From b22c2ffd464fc359d19257e512ce8d9232731b1a Mon Sep 17 00:00:00 2001 From: Henry Coles Date: Mon, 23 Oct 2023 11:12:50 +0100 Subject: [PATCH] Expand test api to allow logging of errors during test discovery Logging is active only during coverage phase and mirrors that used for exceptions with junit 4 and other frameworks which do not execute code during discovery. --- .../coverage/execute/CoverageTestExecutionListener.java | 9 ++++++++- .../java/org/pitest/testapi/NullExecutionListener.java | 2 +- .../org/pitest/testapi/TestUnitExecutionListener.java | 7 ++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/pitest/src/main/java/org/pitest/coverage/execute/CoverageTestExecutionListener.java b/pitest/src/main/java/org/pitest/coverage/execute/CoverageTestExecutionListener.java index ad0f70c7c..7cac35bc4 100644 --- a/pitest/src/main/java/org/pitest/coverage/execute/CoverageTestExecutionListener.java +++ b/pitest/src/main/java/org/pitest/coverage/execute/CoverageTestExecutionListener.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; +import java.util.logging.Level; import java.util.logging.Logger; import static java.util.concurrent.TimeUnit.NANOSECONDS; @@ -42,7 +43,12 @@ public void executionStarted(Description description, boolean suppressParallelWa } @Override - public void executionFinished(Description description, boolean passed) { + public void executionFinished(Description description, boolean passed, Throwable maybeError) { + + if (maybeError != null) { + LOG.log(Level.SEVERE, description.toString(), maybeError); + } + Long t0 = startTimes.remove(description); int executionTime; if (t0 == null) { @@ -70,4 +76,5 @@ public void executionFinished(Description description, boolean passed) { invokeQueue.recordTestOutcome(description, passed, executionTime); } + } diff --git a/pitest/src/main/java/org/pitest/testapi/NullExecutionListener.java b/pitest/src/main/java/org/pitest/testapi/NullExecutionListener.java index 0d97f74c0..f9f04d1a0 100644 --- a/pitest/src/main/java/org/pitest/testapi/NullExecutionListener.java +++ b/pitest/src/main/java/org/pitest/testapi/NullExecutionListener.java @@ -7,7 +7,7 @@ public void executionStarted(Description description) { } @Override - public void executionFinished(Description description, boolean passed) { + public void executionFinished(Description description, boolean passed, Throwable error) { //noop } } diff --git a/pitest/src/main/java/org/pitest/testapi/TestUnitExecutionListener.java b/pitest/src/main/java/org/pitest/testapi/TestUnitExecutionListener.java index 3529329f4..97680db1b 100644 --- a/pitest/src/main/java/org/pitest/testapi/TestUnitExecutionListener.java +++ b/pitest/src/main/java/org/pitest/testapi/TestUnitExecutionListener.java @@ -20,5 +20,10 @@ default void executionStarted(Description description) { default void executionStarted(Description description, boolean suppressParallelWarning) { executionStarted(description); } - void executionFinished(Description description, boolean passed); + + default void executionFinished(Description description, boolean passed) { + executionFinished(description, passed, null); + } + + void executionFinished(Description description, boolean passed, Throwable error); }