Skip to content

Commit 5e99868

Browse files
committed
Check that the tests run on the JDK the jdk job asked for
FormatterVersionTest, from palantir#1707, compares the test JVM with the expectedJavaVersion system property, which upstream's testJdkNN tasks set. Here the build passes the -PjavaRuntime value, so a CI leg that runs on another JDK fails instead of skipping the tests that need a newer parser and still passing.
1 parent 60f39af commit 5e99868

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

‎build.gradle‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,11 @@ subprojects {
127127
}
128128
}
129129

130+
// The JDK the tests run on, and with it the javac whose internals the formatter parses with. The code is
131+
// compiled for 21 whatever this says. CI's `jdk` jobs pass -PjavaRuntime=25 and so on.
132+
ext.javaRuntime = providers.gradleProperty('javaRuntime').getOrElse('21')
133+
130134
javaVersions {
131135
libraryTarget = 21
132-
// The JDK the tests run on, and with it the javac whose internals the formatter parses with. The code is
133-
// compiled for 21 whatever this says. CI's `jdk` jobs pass -PjavaRuntime=25 and so on.
134-
runtime = providers.gradleProperty('javaRuntime').getOrElse('21')
136+
runtime = javaRuntime
135137
}

‎open-java-format/build.gradle‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ tasks.named("test") {
7676
// Run all classes and tests in parallel
7777
// https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution
7878
systemProperty 'junit.jupiter.execution.parallel.mode.default', 'concurrent'
79+
// FormatterVersionTest fails when the tests run on another JDK than the one asked for, so a CI leg
80+
// cannot pass on the wrong JDK and skip the tests that need a newer parser.
81+
systemProperty 'expectedJavaVersion', rootProject.ext.javaRuntime
7982
}
8083

8184
javaVersion {

‎open-java-format/src/test/java/com/palantir/javaformat/java/FormatterVersionTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
import org.junit.jupiter.api.Test;
2323

2424
/**
25-
* Guards the {@code testJdkNN} legs: without this, a leg that resolves to a JDK older than the one it asked for skips
26-
* the {@code ModuleImport} golden and the module import tests, and still passes.
25+
* Guards CI's {@code jdk} legs: without this, a leg that runs on an older JDK than the one it asked for with
26+
* {@code -PjavaRuntime} skips the {@code ModuleImport} golden and the module import tests, and still passes.
2727
*/
2828
public class FormatterVersionTest {
2929

3030
@Test
3131
public void runsOnTheJdkTheTestTaskAskedFor() {
3232
String expected = System.getProperty("expectedJavaVersion");
33-
Assumptions.assumeTrue(expected != null, "expectedJavaVersion is set only by the testJdkNN tasks");
33+
Assumptions.assumeTrue(expected != null, "expectedJavaVersion is set by the Gradle build");
3434
assertThat(Formatter.getRuntimeVersion()).isEqualTo(Integer.parseInt(expected));
3535
}
3636
}

0 commit comments

Comments
 (0)