Skip to content

Apache Lucene open-source search software

LUCENE-3743: LuceneTestCase's uncaught exceptions handler should check for AssumptionViolatedExceptions and then not trigger test failure

Steven Rowe25ad7daa5814
diff --git a/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
index 7084194dc92..d21355960ed 100644
--- a/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
+++ b/lucene/src/test-framework/java/org/apache/lucene/util/LuceneTestCase.java
@@ -542,11 +542,33 @@ public abstract class LuceneTestCase extends Assert {
savedUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
- testsFailed = true;
- uncaughtExceptions.add(new UncaughtExceptionEntry(t, e));
- if (savedUncaughtExceptionHandler != null)
- savedUncaughtExceptionHandler.uncaughtException(t, e);
+ // org.junit.internal.AssumptionViolatedException in older releases
+ // org.junit.Assume.AssumptionViolatedException in recent ones
+ if (e.getClass().getName().endsWith("AssumptionViolatedException")) {
+ String where = "<unknown>";
+ for (StackTraceElement elem : e.getStackTrace()) {
+ if ( ! elem.getClassName().startsWith("org.junit")) {
+ where = elem.toString();
+ break;
+ }
+ }
+ if (e.getCause() instanceof _TestIgnoredException)
+ e = e.getCause();
+ System.err.print("NOTE: Assume failed at " + where + " (ignored):");
+ if (VERBOSE) {
+ System.err.println();
+ e.printStackTrace(System.err);
+ } else {
+ System.err.print(" ");
+ System.err.println(e.getMessage());
+ }
+ } else {
+ testsFailed = true;
+ uncaughtExceptions.add(new UncaughtExceptionEntry(t, e));
+ if (savedUncaughtExceptionHandler != null)
+ savedUncaughtExceptionHandler.uncaughtException(t, e);
}
+ }
});
savedBoolMaxClauseCount = BooleanQuery.getMaxClauseCount();