From 420399742dafe8830a41cf69e7d0c5a4334cdf2c Mon Sep 17 00:00:00 2001 From: "Steven R. Loomis" Date: Wed, 23 Aug 2023 18:43:25 -0500 Subject: [PATCH] CLDR-16393 assume cldr-archive is present for tests - UNLESS -DNO_CLDR_ARCHIVE=true is set --- .../unicode/cldr/unittest/TestTransforms.java | 6 +-- .../unicode/cldr/unittest/TestValidity.java | 7 ++-- .../org/unicode/cldr/util/TestCLDRPaths.java | 38 +++++++++++++++++++ 3 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 tools/cldr-code/src/test/java/org/unicode/cldr/util/TestCLDRPaths.java diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestTransforms.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestTransforms.java index ac24170b197..6cf49f3615c 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestTransforms.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestTransforms.java @@ -46,6 +46,7 @@ import org.unicode.cldr.util.Pair; import org.unicode.cldr.util.PathUtilities; import org.unicode.cldr.util.StandardCodes; +import org.unicode.cldr.util.TestCLDRPaths; import org.unicode.cldr.util.UnicodeRelation; import org.unicode.cldr.util.XMLFileReader; import org.unicode.cldr.util.XPathParts; @@ -398,9 +399,8 @@ public void TestTransformIDs() { checkTransformID(entry.getKey(), entry.getValue()); } - // Only run the rest in exhaustive mode since it requires CLDR_ARCHIVE_DIRECTORY. - if (getInclusion() <= 5) { - return; + if (!TestCLDRPaths.canUseArchiveDirectory()) { + return; // skipped } Set removedTransforms = new HashSet<>(); diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestValidity.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestValidity.java index c83bc34e715..8aec70a944f 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestValidity.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestValidity.java @@ -33,6 +33,7 @@ import org.unicode.cldr.util.StandardCodes; import org.unicode.cldr.util.StandardCodes.LstrField; import org.unicode.cldr.util.StandardCodes.LstrType; +import org.unicode.cldr.util.TestCLDRPaths; import org.unicode.cldr.util.TransliteratorUtilities; import org.unicode.cldr.util.Units; import org.unicode.cldr.util.Validity; @@ -143,10 +144,10 @@ public void TestBasicValidity() { static final Set ALLOWED_REGULAR_TO_SPECIAL = ImmutableSet.of("Zanb", "Zinh", "Zyyy"); public void TestCompatibility() { - // Only run the rest in exhaustive mode, since it requires CLDR_ARCHIVE_DIRECTORY - if (getInclusion() <= 5) { - return; + if (!TestCLDRPaths.canUseArchiveDirectory()) { + return; // skipped } + Set messages = new HashSet<>(); File archive = new File(CLDRPaths.ARCHIVE_DIRECTORY); for (File cldrArchive : archive.listFiles()) { diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/util/TestCLDRPaths.java b/tools/cldr-code/src/test/java/org/unicode/cldr/util/TestCLDRPaths.java new file mode 100644 index 00000000000..09b4ac35bdd --- /dev/null +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/util/TestCLDRPaths.java @@ -0,0 +1,38 @@ +package org.unicode.cldr.util; + +import java.io.File; +import org.junit.jupiter.api.Test; + +public class TestCLDRPaths { + + @Test + void TestCanUseArchiveDirectory() { + if (!canUseArchiveDirectory()) { + // We print this warning as part of the unit tests. + System.err.println( + "WARNING: skipping using cldr-archive. Ideally, -DNO_CLDR_ARCHIVE=false and see "); + } + } + + /** + * @return true if it's OK to read CLDRPaths.ARCHIVE_DIRECTORY, false to skip. + */ + public static final boolean canUseArchiveDirectory() { + if (CLDRConfig.getInstance().getProperty("NO_CLDR_ARCHIVE", false)) { + return false; // skip, NO_CLDR_ARCHIVE is set. + } + + final File archiveDir = new File(CLDRPaths.ARCHIVE_DIRECTORY); + if (!archiveDir.isDirectory()) { + throw new IllegalArgumentException( + String.format( + "Could not read archive directory %s. " + + "Please: " + + "1) setup the archive, , " + + "2) set the -DARCHIVE= property to the correct archive location, or " + + "3) inhibit reading of cldr-archive with -DNO_CLDR_ARCHIVE=true", + archiveDir.getAbsolutePath())); + } + return true; // OK to use + } +}