Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-9743: Hunspell: ignore original tests which are out of scope (#2319)

Peter Gromov4f64e39ec632
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/SpellCheckerTest.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/SpellCheckerTest.java
index f216cb0b39f..074534c3a98 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/SpellCheckerTest.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/SpellCheckerTest.java
@@ -186,11 +186,10 @@ public class SpellCheckerTest extends StemmerTestBase {
protected void doTest(String name) throws Exception {
checkSpellCheckerExpectations(
- Path.of(getClass().getResource(name + ".aff").toURI()).getParent().resolve(name), true);
+ Path.of(getClass().getResource(name + ".aff").toURI()).getParent().resolve(name));
}
- static void checkSpellCheckerExpectations(Path basePath, boolean checkSuggestions)
- throws IOException, ParseException {
+ static void checkSpellCheckerExpectations(Path basePath) throws IOException, ParseException {
InputStream affixStream = Files.newInputStream(Path.of(basePath.toString() + ".aff"));
InputStream dictStream = Files.newInputStream(Path.of(basePath.toString() + ".dic"));
@@ -218,7 +217,7 @@ public class SpellCheckerTest extends StemmerTestBase {
for (String word : wrongWords) {
assertFalse("Unexpectedly considered correct: " + word, speller.spell(word.trim()));
}
- if (Files.exists(sug) && checkSuggestions) {
+ if (Files.exists(sug)) {
String suggestions =
wrongWords.stream()
.map(s -> String.join(", ", speller.suggest(s)))
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestHunspellRepositoryTestCases.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestHunspellRepositoryTestCases.java
index 004ef735522..aa1f794757f 100644
--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestHunspellRepositoryTestCases.java
+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspell/TestHunspellRepositoryTestCases.java
@@ -20,13 +20,14 @@ import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.text.ParseException;
import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
+import org.junit.Assert;
import org.junit.AssumptionViolatedException;
import org.junit.Test;
+import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -36,9 +37,18 @@ import org.junit.runners.Parameterized;
*/
@RunWith(Parameterized.class)
public class TestHunspellRepositoryTestCases {
+ private static final Set<String> EXPECTED_FAILURES =
+ Set.of(
+ "hu", // Hungarian is hard: a lot of its rules are hardcoded in Hunspell code, not aff/dic
+ "morph", // we don't do morphological analysis yet
+ "nepali", // not supported yet
+ "phone" // not supported yet, used only for suggestions in en_ZA
+ );
+ private final String testName;
private final Path pathPrefix;
public TestHunspellRepositoryTestCases(String testName, Path pathPrefix) {
+ this.testName = testName;
this.pathPrefix = pathPrefix;
}
@@ -64,7 +74,12 @@ public class TestHunspellRepositoryTestCases {
}
@Test
- public void test() throws IOException, ParseException {
- SpellCheckerTest.checkSpellCheckerExpectations(pathPrefix, false);
+ public void test() throws Throwable {
+ ThrowingRunnable test = () -> SpellCheckerTest.checkSpellCheckerExpectations(pathPrefix);
+ if (EXPECTED_FAILURES.contains(testName)) {
+ Assert.assertThrows(Throwable.class, test);
+ } else {
+ test.run();
+ }
}
}