ICU-22462 Rename to PersonNameConsistencyTest

Rename ExhaustivePersonNameFormatterTest to PersonNameConsistencyTest
Always run. Paramaterize the test so each test file are run in their
own test case and report the failure/success separately
This commit is contained in:
Frank Tang 2023-08-22 11:33:11 -07:00 committed by Frank Yung-Fong Tang
parent 706044b0a2
commit ea0dbd4c41

View file

@ -3,10 +3,9 @@
package com.ibm.icu.dev.test.format;
import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
@ -15,104 +14,83 @@ import com.ibm.icu.dev.test.TestUtil;
import com.ibm.icu.text.PersonName;
import com.ibm.icu.text.PersonNameFormatter;
import com.ibm.icu.text.SimplePersonName;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
/**
* This is a test designed to parse the files generated by GeneratePersonNameTestData.java in
* the CLDR project. It takes one command-line parameter-- the path to the directory that
* contains the test files (common/testData/personNameTest in the CLDR source tree).
* This isn't set up as a unit test because of the dependency on the CLDR files (I didn't
* want to copy all of those over into the ICU tree) and because I thought the test would
* take too long to run.
* the CLDR project.
*/
@RunWith(JUnit4.class)
public class ExhaustivePersonNameFormatterTest extends TestFmwk {
@RunWith(JUnitParamsRunner.class)
public class PersonNameConsistencyTest extends TestFmwk {
private static final String DATA_PATH = TestUtil.DATA_PATH + "cldr/personNameTest/";
@Before
public void beforeMethod() {
// Disable this test class except for exhaustive mode.
// To enable exhaustive mode, pass the JVM argument "-DICU.exhaustive=10"
org.junit.Assume.assumeTrue(getExhaustiveness() > 5);
}
static private Collection<String> FILENAMES_TO_SKIP =
Arrays.asList("gaa.txt", "dsb.txt", "syr.txt", "hsb.txt", "lij.txt");
@Test
public void TestPersonNames() throws IOException {
InputStream catalogFileStream = TestUtil.class.getResourceAsStream(DATA_PATH + "catalog.txt");
LineNumberReader catalogFile = new LineNumberReader(new InputStreamReader(catalogFileStream));
int filesWithErrors = 0;
int filesWithoutErrors = 0;
int skippedFiles = 0;
int totalErrors = 0;
String filename = null;
do {
filename = catalogFile.readLine();
if (filename != null) {
if (filename.startsWith("#")) { // comment line, skip without logging
continue;
}
if (!filename.endsWith(".txt")) {
logln("Skipping " + filename + "...");
continue;
}
String[] FILENAMES_TO_SKIP = {"gaa.txt", "dsb.txt", "syr.txt", "hsb.txt", "lij.txt"};
String[] FILENAMES_TO_SKIP_FOR_17028 = {
"az.txt", "be.txt", "bs.txt", "fi.txt", "gu.txt", "hr.txt", "is.txt",
static private Collection<String> FILENAMES_TO_SKIP_FOR_17028 =
Arrays.asList("az.txt", "be.txt", "bs.txt", "fi.txt", "gu.txt", "hr.txt", "is.txt",
"km.txt", "ky.txt", "lo.txt", "mk.txt", "ml.txt", "mn.txt", "mr.txt",
"pa.txt", "pt.txt", "pt_PT.txt", "sw.txt", "tr.txt", "zu.txt",
"yue_Hans.txt", "fa.txt","ka.txt", "zh_Hant_HK.txt", "zh_Hant.txt",
"bn.txt", "zh.txt", "nl.txt", "to.txt", "uk.txt", "my.txt",
"bg.txt", "tk.txt", "ps.txt", "ko.txt", "ms.txt", "ne.txt",
"gd.txt", "lv.txt" };
if (Arrays.asList(FILENAMES_TO_SKIP).contains(filename) ||
Arrays.asList(FILENAMES_TO_SKIP_FOR_17028).contains(filename) && logKnownIssue("CLDR-17028", "Some locales fails Person Name Formatting")) {
// extra check to narrow down the files for debugging
logln("Skipping " + filename + "...");
++skippedFiles;
continue;
}
"gd.txt", "lv.txt" );
try {
int testErrors = testIndividualLocale(filename);
if (testErrors == 0) {
++filesWithoutErrors;
} else {
++filesWithErrors;
totalErrors += testErrors;
}
} catch (Exception e) {
++filesWithErrors;
}
static List<String> readTestCases() throws Exception {
List<String> tests = new ArrayList<>();
InputStream catalogFileStream = TestUtil.class.getResourceAsStream(DATA_PATH + "catalog.txt");
LineNumberReader catalogFile = new LineNumberReader(new InputStreamReader(catalogFileStream));
String filename = null;
while ((filename = catalogFile.readLine()) != null) {
if (filename.startsWith("#")) { // comment line, skip without logging
continue;
}
} while (filename != null);
logln("Files without errors: " + filesWithoutErrors);
logln("Files with errors: " + filesWithErrors);
if (skippedFiles > 0) {
logln("Skipped files: " + skippedFiles);
if (!filename.endsWith(".txt")) {
logln("Skipping " + filename + "...");
continue;
}
tests.add(filename);
}
logln("Total number of errors: " + totalErrors);
assertEquals("Some files had test failures", filesWithErrors, 0);
return tests;
}
private static int testIndividualLocale(String filename) throws IOException {
@Test
@Parameters(method = "readTestCases")
public void TestPersonNames(String filename) throws IOException {
LineNumberReader in = new LineNumberReader(new InputStreamReader(TestUtil.class.getResourceAsStream(DATA_PATH + filename)));
String line = null;
PersonNameTester tester = new PersonNameTester(filename);
do {
line = in.readLine();
tester.processLine(line, in.getLineNumber());
} while (line != null);
System.out.println(filename + " had " + tester.getErrorCount() + " errors");
return tester.getErrorCount();
int errors = 0;
try {
while ((line = in.readLine()) != null) {
tester.processLine(line, in.getLineNumber());
}
errors = tester.getErrorCount();
System.out.println(filename + " had " + errors + " errors");
} catch (Exception e) {
String errorMsg = e.toString() + " " + e.getMessage();
if (FILENAMES_TO_SKIP.contains(filename) ||
(FILENAMES_TO_SKIP_FOR_17028.contains(filename) &&
logKnownIssue("ICU-17028", errorMsg))) {
System.out.println("Test throw exception on " + filename + ": " + errorMsg);
return;
}
}
if (errors != 0) {
String errorMsg = "ERROR: Testing against '" + filename + "' contains " + errors + " errors.";
if (FILENAMES_TO_SKIP.contains(filename) ||
(FILENAMES_TO_SKIP_FOR_17028.contains(filename) && logKnownIssue("ICU-17028", errorMsg))) {
System.out.println("Test failure on " + filename + ": " + errorMsg);
return;
}
errln(errorMsg);
}
}
private static class PersonNameTester {