mirror of https://github.com/apache/lucene.git
LUCENE-3506: tests for verifying assertions enabled were no-op.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1188777 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b8d95c3a9f
commit
6b084931fd
|
@ -724,6 +724,10 @@ Test Cases
|
|||
for implementing subclasses in different packages, where assertions are not
|
||||
enabled. (Uwe Schindler)
|
||||
|
||||
* LUCENE-3506: tests relying on assertions being enabled were no-op because
|
||||
they ignored AssertionError. With this fix now entire test framework
|
||||
(all tests) fail if assertions are disabled. (Doron Cohen)
|
||||
|
||||
======================= Lucene 3.4.0 =======================
|
||||
|
||||
Bug fixes
|
||||
|
|
|
@ -400,6 +400,9 @@ public abstract class LuceneTestCase extends Assert {
|
|||
TimeZone.setDefault(timeZone);
|
||||
similarityProvider = new RandomSimilarityProvider(random);
|
||||
testsFailed = false;
|
||||
|
||||
// verify assertions are enabled (do last, for smooth cleanup)
|
||||
assertTrue("assertions are not enabled!", assertionsEnabled());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -1442,4 +1445,15 @@ public abstract class LuceneTestCase extends Assert {
|
|||
|
||||
@Ignore("just a hack")
|
||||
public final void alwaysIgnoredTestMethod() {}
|
||||
|
||||
/** check if assertions are enabled */
|
||||
private static boolean assertionsEnabled() {
|
||||
try {
|
||||
assert Boolean.FALSE.booleanValue();
|
||||
return false; // should never get here
|
||||
} catch (AssertionError e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,55 +17,14 @@ package org.apache.lucene;
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.Reader;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.analysis.Analyzer;
|
||||
import org.apache.lucene.analysis.TokenStream;
|
||||
|
||||
/**
|
||||
* validate that assertions are enabled during tests
|
||||
*/
|
||||
public class TestAssertions extends LuceneTestCase {
|
||||
|
||||
public void testBasics() {
|
||||
try {
|
||||
assert Boolean.FALSE.booleanValue();
|
||||
fail("assertions are not enabled!");
|
||||
} catch (AssertionError e) {
|
||||
assert Boolean.TRUE.booleanValue();
|
||||
}
|
||||
}
|
||||
|
||||
static class TestAnalyzer1 extends Analyzer {
|
||||
|
||||
@Override
|
||||
protected TokenStreamComponents createComponents(String fieldName, Reader aReader) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static final class TestAnalyzer2 extends Analyzer {
|
||||
|
||||
@Override
|
||||
protected TokenStreamComponents createComponents(String fieldName, Reader aReader) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static class TestAnalyzer3 extends Analyzer {
|
||||
|
||||
@Override
|
||||
protected TokenStreamComponents createComponents(String fieldName, Reader aReader) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static class TestAnalyzer4 extends Analyzer {
|
||||
|
||||
@Override
|
||||
protected TokenStreamComponents createComponents(String fieldName, Reader aReader) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static class TestTokenStream1 extends TokenStream {
|
||||
@Override
|
||||
public final boolean incrementToken() { return false; }
|
||||
|
@ -82,31 +41,15 @@ public class TestAssertions extends LuceneTestCase {
|
|||
}
|
||||
|
||||
public void testTokenStreams() {
|
||||
new TestAnalyzer1();
|
||||
|
||||
new TestAnalyzer2();
|
||||
|
||||
try {
|
||||
new TestAnalyzer3();
|
||||
fail("TestAnalyzer3 should fail assertion");
|
||||
} catch (AssertionError e) {
|
||||
}
|
||||
|
||||
try {
|
||||
new TestAnalyzer4();
|
||||
fail("TestAnalyzer4 should fail assertion");
|
||||
} catch (AssertionError e) {
|
||||
}
|
||||
|
||||
new TestTokenStream1();
|
||||
|
||||
new TestTokenStream2();
|
||||
|
||||
boolean doFail = false;
|
||||
try {
|
||||
new TestTokenStream3();
|
||||
fail("TestTokenStream3 should fail assertion");
|
||||
doFail = true;
|
||||
} catch (AssertionError e) {
|
||||
// expected
|
||||
}
|
||||
assertFalse("TestTokenStream3 should fail assertion", doFail);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -146,12 +146,14 @@ public class TestSegmentMerger extends LuceneTestCase {
|
|||
|
||||
// Assert that SM fails if .del exists
|
||||
SegmentMerger sm = new SegmentMerger(dir, 1, "a", null, null, null, newIOContext(random));
|
||||
boolean doFail = false;
|
||||
try {
|
||||
sm.createCompoundFile("b1", w.segmentInfos.info(0), newIOContext(random));
|
||||
fail("should not have been able to create a .cfs with .del and .s* files");
|
||||
doFail = true; // should never get here
|
||||
} catch (AssertionError e) {
|
||||
// expected
|
||||
}
|
||||
assertFalse("should not have been able to create a .cfs with .del and .s* files", doFail);
|
||||
|
||||
// Create an index w/ .s*
|
||||
w = new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random)).setOpenMode(OpenMode.CREATE));
|
||||
|
@ -164,12 +166,15 @@ public class TestSegmentMerger extends LuceneTestCase {
|
|||
r.close();
|
||||
|
||||
// Assert that SM fails if .s* exists
|
||||
SegmentInfos sis = new SegmentInfos();
|
||||
sis.read(dir);
|
||||
try {
|
||||
sm.createCompoundFile("b2", w.segmentInfos.info(0), newIOContext(random));
|
||||
fail("should not have been able to create a .cfs with .del and .s* files");
|
||||
sm.createCompoundFile("b2", sis.info(0), newIOContext(random));
|
||||
doFail = true; // should never get here
|
||||
} catch (AssertionError e) {
|
||||
// expected
|
||||
}
|
||||
assertFalse("should not have been able to create a .cfs with .del and .s* files", doFail);
|
||||
|
||||
dir.close();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue