From d97db113ec3613e080c74b3cf271097211d0b0e8 Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Thu, 24 Sep 2020 11:48:12 -0500 Subject: [PATCH] CLDR-11585 fix pom.xml, add tests (#734) - fix pom.xml repository settings so that settings can be more minimal - basic test runner shim for web / java - build tests where they are - currently test code is included in cldr-apps.war (TODO) - currently, cldr-apps are tested against Derby (regression of CLDR-8383) (cherry picked from commit 6adc82b6b6116bb67e046ec129adb66f4aa6aac4) --- .github/workflows/maven.yml | 5 ++++ .github/workflows/mvn-settings.xml | 5 ---- tools/cldr-apps/pom.xml | 9 ++++++ .../unicode/cldr/unittest/web/TestAll.java | 14 +++++++++- .../unicode/cldr/unittest/web/TestShim.java | 18 ++++++++++++ tools/cldr-unittest/build.xml | 1 + .../org/unicode/cldr/unittest/TestAll.java | 14 ++++++++-- .../org/unicode/cldr/unittest/TestShim.java | 20 +++++++++++++ tools/java/pom.xml | 28 ++++++++++++------- tools/pom.xml | 11 ++++++++ 10 files changed, 106 insertions(+), 19 deletions(-) create mode 100644 tools/cldr-apps/src/test/java/org/unicode/cldr/unittest/web/TestShim.java create mode 100644 tools/cldr-unittest/src/org/unicode/cldr/unittest/TestShim.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 2eab79761d5..94fbae3ce2e 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -24,3 +24,8 @@ jobs: run: mvn -s .github/workflows/mvn-settings.xml -B package --file tools/pom.xml env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Test with maven + run: mvn -s .github/workflows/mvn-settings.xml -B test --file tools/pom.xml + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/.github/workflows/mvn-settings.xml b/.github/workflows/mvn-settings.xml index 32fa7c80838..e11189b3a01 100644 --- a/.github/workflows/mvn-settings.xml +++ b/.github/workflows/mvn-settings.xml @@ -24,11 +24,6 @@ TODO: Remove this when ICU-21251 is completed. true true - - githubicu - GitHub unicode-org/icu Apache Maven Packages - https://maven.pkg.github.com/unicode-org/icu - github GitHub unicode-org/cldr Apache Maven Packages diff --git a/tools/cldr-apps/pom.xml b/tools/cldr-apps/pom.xml index e0d84e4dbea..02fe55ea841 100644 --- a/tools/cldr-apps/pom.xml +++ b/tools/cldr-apps/pom.xml @@ -148,6 +148,15 @@ cldr-apps src + + + src + + org/unicode/cldr/unittest/web/data/**/* + + + + diff --git a/tools/cldr-apps/src/org/unicode/cldr/unittest/web/TestAll.java b/tools/cldr-apps/src/org/unicode/cldr/unittest/web/TestAll.java index 6f97af4d1fe..0a128181083 100644 --- a/tools/cldr-apps/src/org/unicode/cldr/unittest/web/TestAll.java +++ b/tools/cldr-apps/src/org/unicode/cldr/unittest/web/TestAll.java @@ -7,6 +7,7 @@ import java.io.BufferedReader; import java.io.File; +import java.io.PrintWriter; import java.sql.SQLException; import javax.sql.DataSource; @@ -86,9 +87,20 @@ private static void pleaseSet(String var, String err, String sugg) { public static final String DERBY_PREFIX = "jdbc:derby:"; public static void main(String[] args) { + main(args, null); + /* NOTREACHED */ + } + + public static void main(String[] args, PrintWriter logs) { CheckCLDR.setDisplayInformation(CLDRConfig.getInstance().getEnglish()); args = TestAll.doResetDb(args); - new TestAll().run(args); + TestAll test = new TestAll(); + if(logs != null) { + test.run(args, logs); + } else { + test.run(args); + /* NOTREACHED */ + } } public static String[] doResetDb(String[] args) { diff --git a/tools/cldr-apps/src/test/java/org/unicode/cldr/unittest/web/TestShim.java b/tools/cldr-apps/src/test/java/org/unicode/cldr/unittest/web/TestShim.java new file mode 100644 index 00000000000..68a0bda6d8d --- /dev/null +++ b/tools/cldr-apps/src/test/java/org/unicode/cldr/unittest/web/TestShim.java @@ -0,0 +1,18 @@ +package org.unicode.cldr.unittest.web; + +import java.io.PrintWriter; + +import org.junit.jupiter.api.Test; + +/** + * a JUnit test that calls TestAll. + */ +class TestShim { + @Test + public void TestAll() { + String args[] = { "-q" }; + // regular main() will System.exit() which is not too friendly. + // call this instead. + TestAll.main(args, new PrintWriter(System.out)); // TODO: parameterize + } +} \ No newline at end of file diff --git a/tools/cldr-unittest/build.xml b/tools/cldr-unittest/build.xml index f5cd635e842..a2d9700c25c 100644 --- a/tools/cldr-unittest/build.xml +++ b/tools/cldr-unittest/build.xml @@ -95,6 +95,7 @@ diff --git a/tools/cldr-unittest/src/org/unicode/cldr/unittest/TestAll.java b/tools/cldr-unittest/src/org/unicode/cldr/unittest/TestAll.java index 69385a1e416..3f0cace9fa9 100644 --- a/tools/cldr-unittest/src/org/unicode/cldr/unittest/TestAll.java +++ b/tools/cldr-unittest/src/org/unicode/cldr/unittest/TestAll.java @@ -158,6 +158,16 @@ public String toString() { } public static void main(String[] args) { + int errCount = runTests(args); + if (errCount != 0) { + System.exit(1); + } + } + + /** + * Run all tests, but do not System.exit at the end. + */ + public static int runTests(String[] args) { final boolean doTimeStamps = false; TimeStampingPrintWriter tspw = new TimeStampingPrintWriter(System.out); if (!doTimeStamps) { @@ -172,9 +182,7 @@ public static void main(String[] args) { sb.append("Tests took "); sb.append(dispBean.toString()); System.out.println(sb.toString()); - if (errCount != 0) { - System.exit(1); - } + return errCount; } public TestAll() { diff --git a/tools/cldr-unittest/src/org/unicode/cldr/unittest/TestShim.java b/tools/cldr-unittest/src/org/unicode/cldr/unittest/TestShim.java new file mode 100644 index 00000000000..0705d16b812 --- /dev/null +++ b/tools/cldr-unittest/src/org/unicode/cldr/unittest/TestShim.java @@ -0,0 +1,20 @@ +package org.unicode.cldr.unittest; + +import java.io.PrintWriter; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * a JUnit test that calls TestAll. + */ +class TestShim { + @Test + public void TestAll() { + String args[] = { "-n", "-q" }; // TODO: parameterize + // regular main() will System.exit() which is not too friendly. + // call this instead. + int errCount = TestAll.runTests(args); + assertEquals(errCount, 0, "Test had errors"); + } +} \ No newline at end of file diff --git a/tools/java/pom.xml b/tools/java/pom.xml index ec097ab94d2..08e05a433b8 100644 --- a/tools/java/pom.xml +++ b/tools/java/pom.xml @@ -33,9 +33,15 @@ utilities-for-cldr + - junit - junit + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine test @@ -71,6 +77,7 @@ + ${project.basedir}/../cldr-unittest/src . @@ -87,6 +94,15 @@ + + + ${project.basedir}/../cldr-unittest/src + + org/unicode/cldr/unittest/*.txt + org/unicode/cldr/unittest/data/**/* + + + @@ -135,12 +151,4 @@ - - - - githubicu - GitHub unicode-org/icu Apache Maven Packages - https://maven.pkg.github.com/unicode-org/icu - - diff --git a/tools/pom.xml b/tools/pom.xml index 8d4ff96b31b..afc94613f9c 100644 --- a/tools/pom.xml +++ b/tools/pom.xml @@ -196,6 +196,14 @@ + + + githubicu + GitHub unicode-org/icu Apache Maven Packages + https://maven.pkg.github.com/unicode-org/icu + + + @@ -216,6 +224,9 @@ maven-surefire-plugin ${maven-surefire-plugin-version} + + -DCLDR_ENVIRONMENT=UNITTEST -Djava.awt.headless=true -DCLDR_DIR=../../ -Xmx6g -enableassertions + maven-jar-plugin