LUCENE-2708: when a test Assume fails, display information, improved one

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1023312 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2010-10-16 15:43:11 +00:00
parent d99c26f81f
commit 987f32849b
7 changed files with 76 additions and 29 deletions

View File

@ -17,7 +17,7 @@ import org.apache.lucene.search.Query;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.util.Constants; import org.apache.lucene.util.Constants;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.junit.Assume;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -75,7 +75,7 @@ public class TestQueryTemplateManager extends LuceneTestCase {
// Sun 1.5 suffers from http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6240963 // Sun 1.5 suffers from http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6240963
if (Constants.JAVA_VENDOR.startsWith("Sun") && Constants.JAVA_VERSION.startsWith("1.5")) { if (Constants.JAVA_VENDOR.startsWith("Sun") && Constants.JAVA_VERSION.startsWith("1.5")) {
String defLang = Locale.getDefault().getLanguage(); String defLang = Locale.getDefault().getLanguage();
Assume.assumeTrue(!defLang.equals("tr") && !defLang.equals("az")); assumeFalse("Sun JRE 1.5 suffers from http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6240963 under Turkish locale", defLang.equals("tr") || defLang.equals("az"));
} }
//Cache all the query templates we will be referring to. //Cache all the query templates we will be referring to.
QueryTemplateManager qtm=new QueryTemplateManager(); QueryTemplateManager qtm=new QueryTemplateManager();

View File

@ -34,7 +34,6 @@ import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import static org.junit.Assume.*;
/** /**
* Tests lazy skipping on the proximity file. * Tests lazy skipping on the proximity file.
@ -121,7 +120,7 @@ public class TestLazyProxSkipping extends LuceneTestCase {
} }
public void testLazySkipping() throws IOException { public void testLazySkipping() throws IOException {
assumeTrue(!CodecProvider.getDefaultCodec().equals("SimpleText")); assumeFalse("This test cannot run with SimpleText codec", CodecProvider.getDefaultCodec().equals("SimpleText"));
// test whether only the minimum amount of seeks() // test whether only the minimum amount of seeks()
// are performed // are performed
performTest(5); performTest(5);

View File

@ -42,6 +42,7 @@ import org.apache.lucene.search.FieldCache.CacheEntry;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.util.FieldCacheSanityChecker.Insanity; import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
import org.junit.Assume;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assert; import org.junit.Assert;
@ -351,8 +352,16 @@ public abstract class LuceneTestCase extends Assert {
// org.junit.internal.AssumptionViolatedException in older releases // org.junit.internal.AssumptionViolatedException in older releases
// org.junit.Assume.AssumptionViolatedException in recent ones // org.junit.Assume.AssumptionViolatedException in recent ones
if (e.getClass().getName().endsWith("AssumptionViolatedException")) { if (e.getClass().getName().endsWith("AssumptionViolatedException")) {
System.err.println("NOTE: " + method.getName() + " Assume failed (ignored):"); if (e.getCause() instanceof TestIgnoredException)
e.printStackTrace(); e = e.getCause();
System.err.print("NOTE: Assume failed in '" + method.getName() + "' (ignored):");
if (VERBOSE) {
System.err.println();
e.printStackTrace(System.err);
} else {
System.err.print(" ");
System.err.println(e.getMessage());
}
} else { } else {
testsFailed = true; testsFailed = true;
reportAdditionalFailureInfo(); reportAdditionalFailureInfo();
@ -373,7 +382,7 @@ public abstract class LuceneTestCase extends Assert {
public void setUp() throws Exception { public void setUp() throws Exception {
seed = "random".equals(TEST_SEED) ? seedRand.nextLong() : TwoLongs.fromString(TEST_SEED).l2; seed = "random".equals(TEST_SEED) ? seedRand.nextLong() : TwoLongs.fromString(TEST_SEED).l2;
random.setSeed(seed); random.setSeed(seed);
Assert.assertFalse("ensure your tearDown() calls super.tearDown()!!!", setup); assertFalse("ensure your tearDown() calls super.tearDown()!!!", setup);
setup = true; setup = true;
savedUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler(); savedUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@ -410,7 +419,7 @@ public abstract class LuceneTestCase extends Assert {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
Assert.assertTrue("ensure your setUp() calls super.setUp()!!!", setup); assertTrue("ensure your setUp() calls super.setUp()!!!", setup);
setup = false; setup = false;
BooleanQuery.setMaxClauseCount(savedBoolMaxClauseCount); BooleanQuery.setMaxClauseCount(savedBoolMaxClauseCount);
try { try {
@ -515,6 +524,49 @@ public abstract class LuceneTestCase extends Assert {
static public void assertEquals(String message, float expected, float actual) { static public void assertEquals(String message, float expected, float actual) {
assertEquals(message, Float.valueOf(expected), Float.valueOf(actual)); assertEquals(message, Float.valueOf(expected), Float.valueOf(actual));
} }
// Replacement for Assume jUnit class, so we can add a message with explanation:
private static final class TestIgnoredException extends RuntimeException {
TestIgnoredException(String msg) {
super(msg);
}
TestIgnoredException(String msg, Throwable t) {
super(msg, t);
}
@Override
public String getMessage() {
StringBuilder sb = new StringBuilder(super.getMessage());
if (getCause() != null)
sb.append(" - ").append(getCause());
return sb.toString();
}
// only this one is called by our code, exception is not used outside this class:
@Override
public void printStackTrace(PrintStream s) {
if (getCause() != null) {
s.println(super.toString() + " - Caused by:");
getCause().printStackTrace(s);
} else {
super.printStackTrace(s);
}
}
}
public static void assumeTrue(String msg, boolean b) {
Assume.assumeNoException(b ? null : new TestIgnoredException(msg));
}
public static void assumeFalse(String msg, boolean b) {
assumeTrue(msg, !b);
}
public static void assumeNoException(String msg, Exception e) {
Assume.assumeNoException(e == null ? null : new TestIgnoredException(msg, e));
}
/** /**
* Convinience method for logging an iterator. * Convinience method for logging an iterator.
@ -792,16 +844,14 @@ public abstract class LuceneTestCase extends Assert {
protected List<FrameworkMethod> computeTestMethods() { protected List<FrameworkMethod> computeTestMethods() {
if (testMethods != null) if (testMethods != null)
return testMethods; return testMethods;
// check if the current test's class has methods annotated with @Ignore
final Class<?> clazz = getTestClass().getJavaClass();
for (Method m : clazz.getMethods()) {
Ignore ignored = m.getAnnotation(Ignore.class);
if (ignored != null) {
System.err.println("NOTE: Ignoring test method '" + m.getName() + "' " + ignored.value());
}
}
testMethods = getTestClass().getAnnotatedMethods(Test.class); testMethods = getTestClass().getAnnotatedMethods(Test.class);
for (Method m : getTestClass().getJavaClass().getMethods()) { for (Method m : getTestClass().getJavaClass().getMethods()) {
// check if the current test's class has methods annotated with @Ignore
final Ignore ignored = m.getAnnotation(Ignore.class);
if (ignored != null) {
System.err.println("NOTE: Ignoring test method '" + m.getName() + "': " + ignored.value());
}
// add methods starting with "test"
final int mod = m.getModifiers(); final int mod = m.getModifiers();
if (m.getName().startsWith("test") && if (m.getName().startsWith("test") &&
m.getAnnotation(Test.class) == null && m.getAnnotation(Test.class) == null &&

View File

@ -19,7 +19,6 @@ package org.apache.lucene.analysis.th;
import org.apache.lucene.analysis.BaseTokenStreamTestCase; import org.apache.lucene.analysis.BaseTokenStreamTestCase;
import org.apache.lucene.util.Version; import org.apache.lucene.util.Version;
import org.junit.Assume;
/** /**
* Test case for ThaiAnalyzer, modified from TestFrenchAnalyzer * Test case for ThaiAnalyzer, modified from TestFrenchAnalyzer
@ -33,7 +32,7 @@ public class TestThaiAnalyzer extends BaseTokenStreamTestCase {
* testcase for offsets * testcase for offsets
*/ */
public void testOffsets() throws Exception { public void testOffsets() throws Exception {
Assume.assumeTrue(ThaiWordFilter.DBBI_AVAILABLE); assumeTrue("JRE does not support Thai dictionary-based BreakIterator", ThaiWordFilter.DBBI_AVAILABLE);
assertAnalyzesTo(new ThaiAnalyzer(TEST_VERSION_CURRENT), "การที่ได้ต้องแสดงว่างานดี", assertAnalyzesTo(new ThaiAnalyzer(TEST_VERSION_CURRENT), "การที่ได้ต้องแสดงว่างานดี",
new String[] { "การ", "ที่", "ได้", "ต้อง", "แสดง", "ว่า", "งาน", "ดี" }, new String[] { "การ", "ที่", "ได้", "ต้อง", "แสดง", "ว่า", "งาน", "ดี" },
new int[] { 0, 3, 6, 9, 13, 17, 20, 23 }, new int[] { 0, 3, 6, 9, 13, 17, 20, 23 },
@ -41,6 +40,7 @@ public class TestThaiAnalyzer extends BaseTokenStreamTestCase {
} }
public void testTokenType() throws Exception { public void testTokenType() throws Exception {
assumeTrue("JRE does not support Thai dictionary-based BreakIterator", ThaiWordFilter.DBBI_AVAILABLE);
assertAnalyzesTo(new ThaiAnalyzer(TEST_VERSION_CURRENT), "การที่ได้ต้องแสดงว่างานดี ๑๒๓", assertAnalyzesTo(new ThaiAnalyzer(TEST_VERSION_CURRENT), "การที่ได้ต้องแสดงว่างานดี ๑๒๓",
new String[] { "การ", "ที่", "ได้", "ต้อง", "แสดง", "ว่า", "งาน", "ดี", "๑๒๓" }, new String[] { "การ", "ที่", "ได้", "ต้อง", "แสดง", "ว่า", "งาน", "ดี", "๑๒๓" },
new String[] { "<SOUTHEAST_ASIAN>", "<SOUTHEAST_ASIAN>", new String[] { "<SOUTHEAST_ASIAN>", "<SOUTHEAST_ASIAN>",
@ -56,7 +56,7 @@ public class TestThaiAnalyzer extends BaseTokenStreamTestCase {
*/ */
@Deprecated @Deprecated
public void testBuggyTokenType30() throws Exception { public void testBuggyTokenType30() throws Exception {
Assume.assumeTrue(ThaiWordFilter.DBBI_AVAILABLE); assumeTrue("JRE does not support Thai dictionary-based BreakIterator", ThaiWordFilter.DBBI_AVAILABLE);
assertAnalyzesTo(new ThaiAnalyzer(Version.LUCENE_30), "การที่ได้ต้องแสดงว่างานดี ๑๒๓", assertAnalyzesTo(new ThaiAnalyzer(Version.LUCENE_30), "การที่ได้ต้องแสดงว่างานดี ๑๒๓",
new String[] { "การ", "ที่", "ได้", "ต้อง", "แสดง", "ว่า", "งาน", "ดี", "๑๒๓" }, new String[] { "การ", "ที่", "ได้", "ต้อง", "แสดง", "ว่า", "งาน", "ดี", "๑๒๓" },
new String[] { "<ALPHANUM>", "<ALPHANUM>", "<ALPHANUM>", new String[] { "<ALPHANUM>", "<ALPHANUM>", "<ALPHANUM>",
@ -67,7 +67,7 @@ public class TestThaiAnalyzer extends BaseTokenStreamTestCase {
/** @deprecated testing backwards behavior */ /** @deprecated testing backwards behavior */
@Deprecated @Deprecated
public void testAnalyzer30() throws Exception { public void testAnalyzer30() throws Exception {
Assume.assumeTrue(ThaiWordFilter.DBBI_AVAILABLE); assumeTrue("JRE does not support Thai dictionary-based BreakIterator", ThaiWordFilter.DBBI_AVAILABLE);
ThaiAnalyzer analyzer = new ThaiAnalyzer(Version.LUCENE_30); ThaiAnalyzer analyzer = new ThaiAnalyzer(Version.LUCENE_30);
assertAnalyzesTo(analyzer, "", new String[] {}); assertAnalyzesTo(analyzer, "", new String[] {});
@ -93,7 +93,7 @@ public class TestThaiAnalyzer extends BaseTokenStreamTestCase {
* Test that position increments are adjusted correctly for stopwords. * Test that position increments are adjusted correctly for stopwords.
*/ */
public void testPositionIncrements() throws Exception { public void testPositionIncrements() throws Exception {
Assume.assumeTrue(ThaiWordFilter.DBBI_AVAILABLE); assumeTrue("JRE does not support Thai dictionary-based BreakIterator", ThaiWordFilter.DBBI_AVAILABLE);
ThaiAnalyzer analyzer = new ThaiAnalyzer(TEST_VERSION_CURRENT); ThaiAnalyzer analyzer = new ThaiAnalyzer(TEST_VERSION_CURRENT);
assertAnalyzesTo(new ThaiAnalyzer(TEST_VERSION_CURRENT), "การที่ได้ต้อง the แสดงว่างานดี", assertAnalyzesTo(new ThaiAnalyzer(TEST_VERSION_CURRENT), "การที่ได้ต้อง the แสดงว่างานดี",
@ -111,7 +111,7 @@ public class TestThaiAnalyzer extends BaseTokenStreamTestCase {
} }
public void testReusableTokenStream() throws Exception { public void testReusableTokenStream() throws Exception {
Assume.assumeTrue(ThaiWordFilter.DBBI_AVAILABLE); assumeTrue("JRE does not support Thai dictionary-based BreakIterator", ThaiWordFilter.DBBI_AVAILABLE);
ThaiAnalyzer analyzer = new ThaiAnalyzer(TEST_VERSION_CURRENT); ThaiAnalyzer analyzer = new ThaiAnalyzer(TEST_VERSION_CURRENT);
assertAnalyzesToReuse(analyzer, "", new String[] {}); assertAnalyzesToReuse(analyzer, "", new String[] {});
@ -129,6 +129,7 @@ public class TestThaiAnalyzer extends BaseTokenStreamTestCase {
/** @deprecated, for version back compat */ /** @deprecated, for version back compat */
@Deprecated @Deprecated
public void testReusableTokenStream30() throws Exception { public void testReusableTokenStream30() throws Exception {
assumeTrue("JRE does not support Thai dictionary-based BreakIterator", ThaiWordFilter.DBBI_AVAILABLE);
ThaiAnalyzer analyzer = new ThaiAnalyzer(Version.LUCENE_30); ThaiAnalyzer analyzer = new ThaiAnalyzer(Version.LUCENE_30);
assertAnalyzesToReuse(analyzer, "", new String[] {}); assertAnalyzesToReuse(analyzer, "", new String[] {});

View File

@ -26,7 +26,7 @@ import org.apache.solr.common.SolrException;
import org.apache.solr.handler.extraction.ExtractingParams; import org.apache.solr.handler.extraction.ExtractingParams;
import org.apache.solr.handler.extraction.ExtractingRequestHandler; import org.apache.solr.handler.extraction.ExtractingRequestHandler;
import org.apache.solr.handler.extraction.ExtractingDocumentLoader; import org.apache.solr.handler.extraction.ExtractingDocumentLoader;
import org.junit.Assume;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -60,7 +60,7 @@ public class ExtractingRequestHandlerTest extends SolrTestCaseJ4 {
public void testExtraction() throws Exception { public void testExtraction() throws Exception {
// broken for turkish: https://issues.apache.org/jira/browse/SOLR-2088 // broken for turkish: https://issues.apache.org/jira/browse/SOLR-2088
String defLang = Locale.getDefault().getLanguage(); String defLang = Locale.getDefault().getLanguage();
Assume.assumeTrue(!defLang.equals("tr") && !defLang.equals("az")); assumeFalse("Known bugs under Turkish locale: https://issues.apache.org/jira/browse/SOLR-2088", defLang.equals("tr") || defLang.equals("az"));
ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract"); ExtractingRequestHandler handler = (ExtractingRequestHandler) h.getCore().getRequestHandler("/update/extract");
assertTrue("handler is null and it shouldn't be", handler != null); assertTrue("handler is null and it shouldn't be", handler != null);
loadLocal("solr-word.pdf", "fmap.created", "extractedDate", "fmap.producer", "extractedProducer", loadLocal("solr-word.pdf", "fmap.created", "extractedDate", "fmap.producer", "extractedProducer",

View File

@ -24,7 +24,6 @@ import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.Tokenizer; import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.core.WhitespaceTokenizer; import org.apache.lucene.analysis.core.WhitespaceTokenizer;
import org.apache.lucene.analysis.th.ThaiWordFilter; import org.apache.lucene.analysis.th.ThaiWordFilter;
import org.junit.Assume;
/** /**
* Simple tests to ensure the Thai word filter factory is working. * Simple tests to ensure the Thai word filter factory is working.
@ -34,7 +33,7 @@ public class TestThaiWordFilterFactory extends BaseTokenTestCase {
* Ensure the filter actually decomposes text. * Ensure the filter actually decomposes text.
*/ */
public void testWordBreak() throws Exception { public void testWordBreak() throws Exception {
Assume.assumeTrue(ThaiWordFilter.DBBI_AVAILABLE); assumeTrue("JRE does not support Thai dictionary-based BreakIterator", ThaiWordFilter.DBBI_AVAILABLE);
Reader reader = new StringReader("การที่ได้ต้องแสดงว่างานดี"); Reader reader = new StringReader("การที่ได้ต้องแสดงว่างานดี");
Tokenizer tokenizer = new WhitespaceTokenizer(DEFAULT_VERSION, reader); Tokenizer tokenizer = new WhitespaceTokenizer(DEFAULT_VERSION, reader);
ThaiWordFilterFactory factory = new ThaiWordFilterFactory(); ThaiWordFilterFactory factory = new ThaiWordFilterFactory();

View File

@ -39,7 +39,6 @@ import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.ContentStream; import org.apache.solr.common.util.ContentStream;
import org.apache.solr.core.SolrCore; import org.apache.solr.core.SolrCore;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -120,8 +119,7 @@ public class SolrRequestParserTest extends SolrTestCaseJ4 {
txt = IOUtils.toString( connection.getInputStream()); txt = IOUtils.toString( connection.getInputStream());
} }
catch( Exception ex ) { catch( Exception ex ) {
System.out.println( "this test only works if you have a network connection." ); assumeNoException("Unable to connect to " + url + " to run the test.", ex);
Assume.assumeNoException(ex);
return; return;
} }