diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java b/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java index 5ce69998919..6a8917136a8 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java +++ b/lucene/test-framework/src/java/org/apache/lucene/util/RunListenerPrintReproduceInfo.java @@ -154,11 +154,17 @@ public final class RunListenerPrintReproduceInfo extends RunListener { } final StringBuilder b = new StringBuilder(); - b.append("NOTE: reproduce with: ant test "); + b.append("NOTE: reproduce with: gradlew test "); - // Test case, method, seed. - addVmOpt(b, "testcase", RandomizedContext.current().getTargetClass().getSimpleName()); - addVmOpt(b, "tests.method", testName); + // Figure out the test case name and method, if any. + String testClass = RandomizedContext.current().getTargetClass().getSimpleName(); + b.append("--tests "); + b.append(testClass); + if (testName != null) { + b.append(".").append(testName); + } + + // Pass the master seed. addVmOpt(b, "tests.seed", RandomizedContext.current().getRunnerSeedAsString()); // Test groups and multipliers. diff --git a/lucene/test-framework/src/test/org/apache/lucene/util/TestReproduceMessage.java b/lucene/test-framework/src/test/org/apache/lucene/util/TestReproduceMessage.java index 5fbeebae53f..ad1017cbcec 100644 --- a/lucene/test-framework/src/test/org/apache/lucene/util/TestReproduceMessage.java +++ b/lucene/test-framework/src/test/org/apache/lucene/util/TestReproduceMessage.java @@ -16,8 +16,7 @@ */ package org.apache.lucene.util; -import java.util.Arrays; - +import org.hamcrest.Matchers; import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; @@ -26,7 +25,6 @@ import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestRule; -import org.junit.runner.Description; import org.junit.runner.JUnitCore; import org.junit.runners.model.Statement; @@ -46,16 +44,11 @@ public class TestReproduceMessage extends WithNestedTests { } @Rule - public TestRule rule = new TestRule() { + public TestRule rule = (base, description) -> new Statement() { @Override - public Statement apply(final Statement base, Description description) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - triggerOn(SorePoint.RULE); - base.evaluate(); - } - }; + public void evaluate() throws Throwable { + triggerOn(SorePoint.RULE); + base.evaluate(); } }; @@ -178,46 +171,37 @@ public class TestReproduceMessage extends WithNestedTests { Assert.assertTrue(runAndReturnSyserr().contains("NOTE: reproduce with:")); } + static void checkTestName(String syserr, String expectedName) { + Assert.assertTrue(syserr.contains("NOTE: reproduce with:")); + Assert.assertThat(syserr, Matchers.containsString(" --tests " + expectedName)); + } + @Test public void testFailureRule() throws Exception { type = SoreType.FAILURE; where = SorePoint.RULE; - - final String syserr = runAndReturnSyserr(); - - Assert.assertTrue(syserr.contains("NOTE: reproduce with:")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtests.method=test")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtestcase=" + Nested.class.getSimpleName())); + checkTestName(runAndReturnSyserr(), Nested.class.getSimpleName() + ".test"); } @Test public void testFailureBefore() throws Exception { type = SoreType.FAILURE; where = SorePoint.BEFORE; - final String syserr = runAndReturnSyserr(); - Assert.assertTrue(syserr.contains("NOTE: reproduce with:")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtests.method=test")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtestcase=" + Nested.class.getSimpleName())); + checkTestName(runAndReturnSyserr(), Nested.class.getSimpleName() + ".test"); } @Test public void testFailureTest() throws Exception { type = SoreType.FAILURE; where = SorePoint.TEST; - final String syserr = runAndReturnSyserr(); - Assert.assertTrue(syserr.contains("NOTE: reproduce with:")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtests.method=test")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtestcase=" + Nested.class.getSimpleName())); + checkTestName(runAndReturnSyserr(), Nested.class.getSimpleName() + ".test"); } @Test public void testFailureAfter() throws Exception { type = SoreType.FAILURE; where = SorePoint.AFTER; - final String syserr = runAndReturnSyserr(); - Assert.assertTrue(syserr.contains("NOTE: reproduce with:")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtests.method=test")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtestcase=" + Nested.class.getSimpleName())); + checkTestName(runAndReturnSyserr(), Nested.class.getSimpleName() + ".test"); } @Test @@ -249,40 +233,28 @@ public class TestReproduceMessage extends WithNestedTests { public void testErrorRule() throws Exception { type = SoreType.ERROR; where = SorePoint.RULE; - final String syserr = runAndReturnSyserr(); - Assert.assertTrue(syserr.contains("NOTE: reproduce with:")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtests.method=test")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtestcase=" + Nested.class.getSimpleName())); + checkTestName(runAndReturnSyserr(), Nested.class.getSimpleName() + ".test"); } @Test public void testErrorBefore() throws Exception { type = SoreType.ERROR; where = SorePoint.BEFORE; - final String syserr = runAndReturnSyserr(); - Assert.assertTrue(syserr.contains("NOTE: reproduce with:")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtests.method=test")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtestcase=" + Nested.class.getSimpleName())); + checkTestName(runAndReturnSyserr(), Nested.class.getSimpleName() + ".test"); } @Test public void testErrorTest() throws Exception { type = SoreType.ERROR; where = SorePoint.TEST; - final String syserr = runAndReturnSyserr(); - Assert.assertTrue(syserr.contains("NOTE: reproduce with:")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtests.method=test")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtestcase=" + Nested.class.getSimpleName())); + checkTestName(runAndReturnSyserr(), Nested.class.getSimpleName() + ".test"); } @Test public void testErrorAfter() throws Exception { type = SoreType.ERROR; where = SorePoint.AFTER; - final String syserr = runAndReturnSyserr(); - Assert.assertTrue(syserr.contains("NOTE: reproduce with:")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtests.method=test")); - Assert.assertTrue(Arrays.asList(syserr.split("\\s")).contains("-Dtestcase=" + Nested.class.getSimpleName())); + checkTestName(runAndReturnSyserr(), Nested.class.getSimpleName() + ".test"); } @Test @@ -294,10 +266,6 @@ public class TestReproduceMessage extends WithNestedTests { private String runAndReturnSyserr() { JUnitCore.runClasses(Nested.class); - - String err = getSysErr(); - // super.prevSysErr.println("Type: " + type + ", point: " + where + " resulted in:\n" + err); - // super.prevSysErr.println("---"); - return err; + return getSysErr(); } } diff --git a/lucene/test-framework/src/test/org/apache/lucene/util/TestReproduceMessageWithRepeated.java b/lucene/test-framework/src/test/org/apache/lucene/util/TestReproduceMessageWithRepeated.java index 9e03d076e00..00dc38bcdf8 100644 --- a/lucene/test-framework/src/test/org/apache/lucene/util/TestReproduceMessageWithRepeated.java +++ b/lucene/test-framework/src/test/org/apache/lucene/util/TestReproduceMessageWithRepeated.java @@ -16,7 +16,6 @@ */ package org.apache.lucene.util; -import org.junit.Assert; import org.junit.Test; import org.junit.runner.JUnitCore; @@ -39,14 +38,12 @@ public class TestReproduceMessageWithRepeated extends WithNestedTests { } @Test - public void testRepeatedMessage() throws Exception { - String syserr = runAndReturnSyserr(); - Assert.assertTrue(syserr.contains(" -Dtests.method=testMe ")); + public void testRepeatedMessage() throws Exception { + TestReproduceMessage.checkTestName(runAndReturnSyserr(), Nested.class.getSimpleName() + ".testMe"); } private String runAndReturnSyserr() { JUnitCore.runClasses(Nested.class); - String err = getSysErr(); - return err; + return getSysErr(); } }