summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/au/id/zancanaro/javacheck/junit/Properties.java25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java b/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java
index 64bd9ab..6ff0538 100644
--- a/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java
+++ b/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java
@@ -221,7 +221,13 @@ public class Properties extends BlockJUnit4ClassRunner {
}
private ShrinkResult shrink(RoseTree<Object[]> failed, Throwable originalEx) {
- ShrinkResult smallest = new ShrinkResult(failed.getValue(), originalEx);
+ // this array is a mutable container so the shutdown handler can see the new version
+ ShrinkResult[] smallest = new ShrinkResult[]{
+ new ShrinkResult(failed.getValue(), originalEx)};
+
+ Thread shutdownHandler = makeShutdownHandler(smallest, originalEx);
+ Runtime.getRuntime().addShutdownHook(shutdownHandler);
+
Iterator<RoseTree<Object[]>> trees = failed.getChildren();
Set<List<Object>> seenArgs = new HashSet<>();
while (trees.hasNext()) {
@@ -232,7 +238,7 @@ public class Properties extends BlockJUnit4ClassRunner {
} catch (AssumptionViolatedException ex) {
// ignore, because it's not useful
} catch (Throwable ex) {
- smallest = new ShrinkResult(tree.getValue(), ex);
+ smallest[0] = new ShrinkResult(tree.getValue(), ex);
Iterator<RoseTree<Object[]>> children = tree.getChildren();
if (children.hasNext()) {
trees = children;
@@ -242,7 +248,18 @@ public class Properties extends BlockJUnit4ClassRunner {
}
}
}
- return smallest;
+
+ Runtime.getRuntime().removeShutdownHook(shutdownHandler);
+ return smallest[0];
+ }
+
+ private Thread makeShutdownHandler(ShrinkResult[] smallest, Throwable originalException) {
+ return new Thread(() -> {
+ System.err.println("Signal received while shrinking.\n" +
+ "Current best shrink is: " + Arrays.toString(smallest[0].args) + "\n" +
+ "Shrinking exception: " + smallest[0].thrown + "\n" +
+ "Originally was: " + originalException);
+ });
}
public void runTest(final Object[] args) throws Throwable {
@@ -276,4 +293,4 @@ public class Properties extends BlockJUnit4ClassRunner {
}
}
-} \ No newline at end of file
+}