Apache Solr open-source search software
LUCENE-3908: include test method even in a failure is caught in a non-test thread.
Dawid Weiss8e8b55d32c75
diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSeedFromUncaught.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSeedFromUncaught.javaindex 9b7700babad..911882f3e1d 100644--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSeedFromUncaught.java+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSeedFromUncaught.java@@ -55,6 +55,7 @@ public class TestSeedFromUncaught extends WithNestedTests {Assert.assertEquals(1, result.getFailureCount());String consoleOut = super.getSysErr() + "\n\n" + super.getSysOut();Assert.assertTrue(consoleOut.contains("-Dtests.seed="));+ Assert.assertTrue(consoleOut.contains("-Dtestmethod=testFoo"));Assert.assertTrue(consoleOut.contains("foobar"));}}diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.javaindex 19cf45b37f8..497a46adfc4 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java@@ -304,7 +304,7 @@ public abstract class LuceneTestCase extends Assert {*/@Rulepublic final TestRule ruleChain = RuleChain- .outerRule(new RememberThreadRule())+ .outerRule(new SaveThreadAndTestNameRule()).around(new UncaughtExceptionsRule(this)).around(new TestResultInterceptorRule()).around(new SystemPropertiesInvariantRule(ignoredInvariantProperties))@@ -561,7 +561,6 @@ public abstract class LuceneTestCase extends Assert {return new Statement() {@Overridepublic void evaluate() throws Throwable {- starting(description);try {base.evaluate();} catch (AssumptionViolatedException e) {@@ -570,8 +569,6 @@ public abstract class LuceneTestCase extends Assert {} catch (Throwable t) {failed(t, description);throw t;- } finally {- ending(description);}}};@@ -593,16 +590,6 @@ public abstract class LuceneTestCase extends Assert {reportAdditionalFailureInfo();assert !(e instanceof AssumptionViolatedException);}-- private void starting(Description description) {- // set current method name for logging- LuceneTestCase.this.name = description.getMethodName();- }-- private void ending(Description description) {- // clear the current method name.- LuceneTestCase.this.name = null;- }};/**@@ -614,21 +601,23 @@ public abstract class LuceneTestCase extends Assert {/*** @see LuceneTestCase#testCaseThread*/- private class RememberThreadRule implements TestRule {+ private class SaveThreadAndTestNameRule implements TestRule {private String previousName;@Override- public Statement apply(final Statement base, Description description) {+ public Statement apply(final Statement base, final Description description) {return new Statement() {public void evaluate() throws Throwable {try {Thread current = Thread.currentThread();previousName = current.getName();LuceneTestCase.this.testCaseThread = current;+ LuceneTestCase.this.name = description.getMethodName();base.evaluate();} finally {LuceneTestCase.this.testCaseThread.setName(previousName);LuceneTestCase.this.testCaseThread = null;+ LuceneTestCase.this.name = null;}}};@@ -1497,9 +1486,16 @@ public abstract class LuceneTestCase extends Assert {// We get here from InterceptTestCaseEvents on the 'failed' event....public void reportAdditionalFailureInfo() {- System.err.println("NOTE: reproduce with: ant test -Dtestcase=" + getClass().getSimpleName()- + " -Dtestmethod=" + getName() + " -Dtests.seed=" + new ThreeLongs(staticSeed, seed, LuceneTestCaseRunner.runnerSeed)- + reproduceWithExtraParams());+ StringBuilder b = new StringBuilder();+ b.append("NOTE: reproduce with: ant test -Dtestcase=")+ .append(getClass().getSimpleName());+ if (getName() != null) {+ b.append(" -Dtestmethod=").append(getName());+ }+ b.append(" -Dtests.seed=")+ .append(new ThreeLongs(staticSeed, seed, LuceneTestCaseRunner.runnerSeed))+ .append(reproduceWithExtraParams());+ System.err.println(b.toString());}// extra params that were overridden needed to reproduce the command