mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
jetCheck tests: don't spam to console
This commit is contained in:
@@ -101,13 +101,13 @@ class CheckSession<T> {
|
||||
final int iterationCount;
|
||||
final IntUnaryOperator sizeHintFun;
|
||||
|
||||
CheckSession(Generator<T> generator, Predicate<T> property, long globalSeed, int iterationCount, IntUnaryOperator sizeHintFun) {
|
||||
CheckSession(Generator<T> generator, Predicate<T> 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<T> firstIteration() {
|
||||
|
||||
@@ -15,6 +15,7 @@ public class PropertyChecker<T> {
|
||||
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<T> generator) {
|
||||
this.generator = generator;
|
||||
@@ -60,6 +61,15 @@ public class PropertyChecker<T> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Suppresses all output during property check and shrinking
|
||||
* @return this PropertyChecker
|
||||
*/
|
||||
public PropertyChecker<T> 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<T> {
|
||||
* given number of times (see {@link #withIterationCount(int)}).
|
||||
*/
|
||||
public void shouldHold(@NotNull Predicate<T> property) {
|
||||
Iteration<T> iteration = new CheckSession<>(generator, property, globalSeed, iterationCount, sizeHintFun).firstIteration();
|
||||
Iteration<T> iteration = new CheckSession<>(generator, property, globalSeed, iterationCount, sizeHintFun, silent).firstIteration();
|
||||
while (iteration != null) {
|
||||
iteration = iteration.performIteration();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -11,7 +11,7 @@ abstract class PropertyCheckerTestCase extends TestCase {
|
||||
|
||||
protected <T> PropertyFalsified checkFails(PropertyChecker<T> checker, Predicate<T> 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<T> failure = (PropertyFailure<T>)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()));
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user