diff --git a/jetCheck/src/jetCheck/Iteration.java b/jetCheck/src/jetCheck/Iteration.java index dca80cd1440c..d6ecdc6426eb 100644 --- a/jetCheck/src/jetCheck/Iteration.java +++ b/jetCheck/src/jetCheck/Iteration.java @@ -101,13 +101,13 @@ class CheckSession { final int iterationCount; final IntUnaryOperator sizeHintFun; - CheckSession(Generator generator, Predicate property, long globalSeed, int iterationCount, IntUnaryOperator sizeHintFun) { + CheckSession(Generator generator, Predicate property, long globalSeed, int iterationCount, IntUnaryOperator sizeHintFun, boolean silent) { this.generator = generator; this.property = property; this.globalSeed = globalSeed; this.iterationCount = iterationCount; this.sizeHintFun = sizeHintFun; - notifier = new StatusNotifier(iterationCount); + notifier = silent ? StatusNotifier.SILENT : new StatusNotifier(iterationCount); } Iteration firstIteration() { diff --git a/jetCheck/src/jetCheck/PropertyChecker.java b/jetCheck/src/jetCheck/PropertyChecker.java index f0d00546f165..88abc2ba1550 100644 --- a/jetCheck/src/jetCheck/PropertyChecker.java +++ b/jetCheck/src/jetCheck/PropertyChecker.java @@ -15,6 +15,7 @@ public class PropertyChecker { private long globalSeed = new Random().nextLong(); private IntUnaryOperator sizeHintFun = iteration -> (iteration - 1) % DEFAULT_MAX_SIZE_HINT + 1; private int iterationCount = 100; + private boolean silent; private PropertyChecker(Generator generator) { this.generator = generator; @@ -60,6 +61,15 @@ public class PropertyChecker { return this; } + /** + * Suppresses all output during property check and shrinking + * @return this PropertyChecker + */ + public PropertyChecker silently() { + this.silent = true; + return this; + } + /** * Checks the property within a single iteration by using specified seed and size hint. Useful to debug the test after it's failed. */ @@ -72,7 +82,7 @@ public class PropertyChecker { * given number of times (see {@link #withIterationCount(int)}). */ public void shouldHold(@NotNull Predicate property) { - Iteration iteration = new CheckSession<>(generator, property, globalSeed, iterationCount, sizeHintFun).firstIteration(); + Iteration iteration = new CheckSession<>(generator, property, globalSeed, iterationCount, sizeHintFun, silent).firstIteration(); while (iteration != null) { iteration = iteration.performIteration(); } diff --git a/jetCheck/src/jetCheck/StatusNotifier.java b/jetCheck/src/jetCheck/StatusNotifier.java index 420beb6bdb58..a29af52ea17f 100644 --- a/jetCheck/src/jetCheck/StatusNotifier.java +++ b/jetCheck/src/jetCheck/StatusNotifier.java @@ -14,6 +14,17 @@ import java.util.Locale; */ @SuppressWarnings("UseOfSystemOutOrSystemErr") class StatusNotifier { + static final StatusNotifier SILENT = new StatusNotifier(0) { + @Override + boolean shouldPrint() { + return false; + } + + @Override + void counterExampleFound(Iteration iteration) { + } + }; + private final int iterationCount; private int currentIteration; private long lastPrinted = System.currentTimeMillis(); @@ -34,7 +45,7 @@ class StatusNotifier { System.err.println(formatCurrentTime() + ": failed on iteration " + currentIteration + " (" + iteration.printSeeds() + "), shrinking..."); } - private boolean shouldPrint() { + boolean shouldPrint() { if (System.currentTimeMillis() - lastPrinted > 5_000) { lastPrinted = System.currentTimeMillis(); return true; diff --git a/jetCheck/test/jetCheck/PropertyCheckerTestCase.java b/jetCheck/test/jetCheck/PropertyCheckerTestCase.java index 6408457c5959..d62ad3ceef47 100644 --- a/jetCheck/test/jetCheck/PropertyCheckerTestCase.java +++ b/jetCheck/test/jetCheck/PropertyCheckerTestCase.java @@ -11,7 +11,7 @@ abstract class PropertyCheckerTestCase extends TestCase { protected PropertyFalsified checkFails(PropertyChecker checker, Predicate predicate) { try { - checker.shouldHold(predicate); + checker.silently().shouldHold(predicate); throw new AssertionError("Can't falsify " + getName()); } catch (PropertyFalsified e) { @@ -28,9 +28,11 @@ abstract class PropertyCheckerTestCase extends TestCase { //noinspection unchecked PropertyFailure failure = (PropertyFailure)e.getFailure(); + /* System.out.println(" " + getName()); System.out.println("Value: " + e.getBreakingValue()); System.out.println("Data: " + e.getData()); + */ assertEquals(minimizationSteps, failure.getTotalMinimizationExampleCount()); // to track if framework changes don't increase shrinking time significantly on average assertEquals(e.getBreakingValue(), generator.getGeneratorFunction().apply(e.getData())); diff --git a/jetCheck/test/jetCheck/ShrinkTest.java b/jetCheck/test/jetCheck/ShrinkTest.java index b14ca3a2a5cc..f47b131cf426 100644 --- a/jetCheck/test/jetCheck/ShrinkTest.java +++ b/jetCheck/test/jetCheck/ShrinkTest.java @@ -38,7 +38,7 @@ public class ShrinkTest extends PropertyCheckerTestCase { checkFalsified(gen, property, 0); // prove that it sometimes fails for (int i = 0; i < 1000; i++) { try { - PropertyChecker.forAll(gen).shouldHold(property); + PropertyChecker.forAll(gen).silently().shouldHold(property); } catch (PropertyFalsified e) { assertEquals("[]", e.getBreakingValue());