Skip to content

Commit

Permalink
ICU-22917 Use the ICU version API. Add missing @test.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihnita committed Nov 4, 2024
1 parent 1ad7caf commit 7d20d69
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
25 changes: 13 additions & 12 deletions docs/processes/release/tasks/updating-measure-unit.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,23 @@ Make sure `DRAFT_VERSION_SET` at top of
is set correctly. \
These are the ICU versions that have draft methods.

In the same file set `ICU_CURRENT_VERSION` and `ICU_BACK_VERSION`. \

**WARNING / TODO:** clarify what to set them to. I was unable to find documentation for that. \
And I'm questioning if we need two versions. In fact I suspect that for 76 these were set incorrectly.

The code is generated by running `MeasureUnitGeneratorTest.java` unit tests, which writes
generated code to various file.

1. Within **Eclipse**:
- Open `MeasureUnitGeneratorTest.java`, find the `generateUnitTestsUpdate` methods
and run it by clicking on the green play button on menu bar. \
Choose "JUnit Test" if asked.

2. With **maven** (command line):
1. With **maven** (command line):
- Change folder to `{icuRoot}/icu4j`
- run `mvn install -DskipTests -DskipITs`
- run `mvn install -q -Dtest=MeasureUnitGeneratorTest -DgenerateMeasureUnitUpdate -f main/common_tests`

2. Within **Eclipse**:
- Open `MeasureUnitGeneratorTest.java`, find the `generateUnitTestsUpdate` methods
and run it by clicking on the green play button on menu bar. \
Choose "JUnit Test" if asked. \
This will not generate the update, but it will run the test and create a "Run Configuration". \
Open it (Main menu -- "Run" -- "Run Configurations"), select the one named
`MeasureUnitGeneratorTest.generateUnitTestsUpdate`, go to the "Arguments" tab and add
`-DgenerateMeasureUnitUpdate` to the "VM Arguments" text area.

Both methods will generate files with names starting with `genunits_` in `icu4j/main/common_tests/`. \
The file names and the logging to the standard output will guide you.

Expand Down Expand Up @@ -101,7 +100,9 @@ code should be appended at some fixed place (details below).
* **`measunit.cpp`:** replace range.
* **`measfmttest.cpp`:** append the new generated method after the last
`MeasureFormatTest::TestCompatible<version>()` method. \
Don't add it if it already exists.
Don't add it if it already exists. \
WARNING: here you should add the method in two places. The method proper, with code,
as generated, and the declaration in the class definition.
* **`MeasureUnitGeneratorTest.java`:** append the new pairs of measure + version at
the end of the `JAVA_VERSIONS` structure. \
Don't add them if they already exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,8 @@ public void TestCompatible74() {
assertEquals("", 190, units.length);
}

public void TestCompatible76() {
@Test
public void TestCompatible76() {
MeasureUnit[] units = {
MeasureUnit.G_FORCE,
MeasureUnit.METER_PER_SECOND_SQUARED,
Expand Down Expand Up @@ -2755,7 +2756,7 @@ public void TestCompatible76() {
MeasureUnit.TABLESPOON,
MeasureUnit.TEASPOON,
};
assertEquals("", 193, units.length);
assertEquals("", 192, units.length);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.ibm.icu.impl.Pair;
import com.ibm.icu.util.MeasureUnit;
import com.ibm.icu.util.NoUnit;
import com.ibm.icu.util.VersionInfo;

/**
* This is not a real test class. It is only used to
Expand Down Expand Up @@ -67,11 +68,6 @@ public int compareTo(OrderedPair<F, S> other) {
}
}

// TODO: what should these two version be? Should they in fact be the same?
// Can we take the version from `VersionInfo.ICU_VERSION.getMajor()`?
private static final String ICU_CURRENT_VERSION = "76";
private static final String ICU_BACK_VERSION = "74";

private static final HashSet<String> DRAFT_VERSION_SET = new HashSet<>();

private static final HashSet<String> TIME_CODES = new HashSet<>();
Expand Down Expand Up @@ -322,16 +318,17 @@ public void generateUnitTestsUpdate() throws IOException {
// docs/processes/release/tasks/updating-measure-unit.md
// use this test to run each of the following in succession
if (System.getProperty("generateMeasureUnitUpdate") != null) {
final String icuVersion = Integer.toString(VersionInfo.ICU_VERSION.getMajor());
System.out.println();
System.out.println("WARNING: open the pairs of files listed below and copy code fragments, not full files!");
System.out.println("Some kind of diff tool / editor would work best.");

generateConstants(ICU_CURRENT_VERSION); // update generated MeasureUnit constants
generateBackwardCompatibilityTest(ICU_CURRENT_VERSION); // create TestCompatible<icu_ver>
generateCXXHConstants(ICU_CURRENT_VERSION); // update generated createXXX methods
generateConstants(icuVersion); // update generated MeasureUnit constants
generateBackwardCompatibilityTest(icuVersion); // create TestCompatible<icu_ver>
generateCXXHConstants(icuVersion); // update generated createXXX methods
generateCXXConstants(); // update generated code
generateCXXBackwardCompatibilityTest(ICU_BACK_VERSION); // create TestCompatible<icu_ver>
updateJAVAVersions(ICU_BACK_VERSION); // JAVA_VERSIONS
generateCXXBackwardCompatibilityTest(icuVersion); // create TestCompatible<icu_ver>
updateJAVAVersions(icuVersion); // JAVA_VERSIONS
}
}

Expand Down Expand Up @@ -695,6 +692,7 @@ private static void generateBackwardCompatibilityTest(String version) throws IOE
try (PrintStream out = createAndStartOutputFile(fullOutputPath)) {
Map<String, MeasureUnit> seen = new HashMap<>();
out.println();
out.printf(" @Test\n");
out.printf(" public void TestCompatible%s() {\n", version.replace(".", "_"));
out.println(" MeasureUnit[] units = {");
TreeMap<String, List<MeasureUnit>> allUnits = getAllUnits();
Expand Down

0 comments on commit 7d20d69

Please sign in to comment.