Skip to content

Commit 808493a

Browse files
rybakmarcphilipp
authored andcommitted
Run StandaloneTests for Java 8 under Java 8
Problem ------- Tests that claim by their name to run on Java 8 don't actually run on Java 8. This can be clear from the output for tests that add option `--show-version` to the arguments and _don't_ fail -- they all print the version for the current JDK. The tool `java` of JDK 8 does _not_ have the option `--show-version`. The actual option that exists in JDK 8 has fewer hyphens, as per documentation of Java 8 [1]: -showversion Displays version information and continues execution of the application. This option is equivalent to the `-version` option except that the latter instructs the JVM to exit after displaying version information. And when I actually run Java 8 binary with the incorrect option `--show-version` used by the affected tests, I get: $ /usr/lib/jvm/java-8-openjdk-amd64/bin/java --show-version Unrecognized option: --show-version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. The option `--show-version` was only added in Java 9 [2]. Explanation ----------- In actuality, the tests are being run on whatever the current JDK is. These tests create an instance of class `de.sormuras.bartholdy.tool.Java`, which importantly has the following method: @OverRide public Path getHome() { return Bartholdy.currentJdkHome(); } When the `bartholdy` library creates the process, class `AbstractTool` does the following: protected Path createPathToProgram() { return getHome().resolve("bin").resolve(getProgram()); } The string `"java"` returned from method `getProgram` of class `Java` gets resolved against `Bartholdy.currentJdkHome()`. As far as I can tell, the library doesn't promise to look up the `java` binary in the `JAVA_HOME` supplied in the environment. In fact, just before consuming library user's environment, method `run()` of class `de.sormuras.bartholdy.tool.AbstractTool` puts the current JDK as `JAVA_HOME` into the environment to correspond to the behavior of class `de.sormuras.bartholdy.tool.Java` described above: builder.environment().put("JAVA_HOME", Bartholdy.currentJdkHome().toString()); The issue has been present since commit [3] where these tests were introduced. Fix --- Fix affected tests to run them under actual Java 8 by overriding method `de.sormuras.bartholdy.tool.Java#getHome`. Replace erroneous option `--show-version` with `-showversion`. To make tests executeOnJava8() and executeOnJava8SelectPackage() see the class files, update test compile() to use option `--release 8`. Because compiling to release 8 is deprecated, add a linter option to disable the warning to make compile() pass. Because option `-showversion` of Java 8 behaves slightly differently to option `--show-version` of later versions of Java, prepare two new files for expected stdout and stderr: expected-out-java8.txt and expected-err-java8.txt, which are similar to existing files expected-out.txt and expected-err.txt, but have different layout of fastforward lines "JAVA VERSION" and "TREE". Footnotes --------- [1] "Java Platform, Standard Edition Tools Reference", "java" https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html https://docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html [2] https://docs.oracle.com/javase/9/tools/java.htm > `--show-version` or `-showversion` > > Displays version information and continues execution of the application. > This option is equivalent to the `-version` option except that the latter > instructs the JVM to exit after displaying version information. [3] c62cd6a (Fix package path computation in `ClasspathScanner`, 2021-05-12) from #2613 (cherry picked from commit 977c85f)
1 parent 9ec5766 commit 808493a

File tree

3 files changed

+71
-10
lines changed

3 files changed

+71
-10
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
>> JAVA VERSION >>
2+
.+ org.junit.platform.launcher.core.ServiceLoaderRegistry load
3+
.+ Loaded LauncherInterceptor instances: ..
4+
.+ org.junit.platform.launcher.core.ServiceLoaderRegistry load
5+
.+ Loaded LauncherSessionListener instances: ..
6+
.+ org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
7+
.+ Discovered TestEngines:
8+
- junit-jupiter .+
9+
- junit-vintage .+
10+
- junit-platform-suite .+
11+
.+ org.junit.platform.launcher.core.ServiceLoaderRegistry load
12+
.+ Loaded PostDiscoveryFilter instances: ..
13+
.+ org.junit.platform.launcher.core.ServiceLoaderRegistry load
14+
.+ Loaded LauncherDiscoveryListener instances: ..
15+
.+ org.junit.platform.launcher.core.ServiceLoaderRegistry load
16+
.+ Loaded TestExecutionListener instances: .+
17+
.+ org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
18+
.+ Discovered TestEngines:
19+
- junit-jupiter .+
20+
- junit-vintage .+
21+
- junit-platform-suite .+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
>> TREE >>
2+
Failures (2):
3+
>> STACKTRACE >>
4+
5+
Test run finished after \d+ ms
6+
[ 11 containers found ]
7+
[ 0 containers skipped ]
8+
[ 11 containers started ]
9+
[ 0 containers aborted ]
10+
[ 11 containers successful ]
11+
[ 0 containers failed ]
12+
[ 10 tests found ]
13+
[ 2 tests skipped ]
14+
[ 8 tests started ]
15+
[ 1 tests aborted ]
16+
[ 5 tests successful ]
17+
[ 2 tests failed ]
18+

platform-tooling-support-tests/src/test/java/platform/tooling/support/tests/StandaloneTests.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ void compile() throws Exception {
8989
var result = Request.builder() //
9090
.setTool(new Javac()) //
9191
.setProject("standalone") //
92+
.addArguments("-Xlint:-options") //
93+
.addArguments("--release", "8") //
9294
.addArguments("-proc:none") //
9395
.addArguments("-d", workspace.resolve("bin")) //
9496
.addArguments("--class-path", MavenRepo.jar("junit-platform-console-standalone")) //
@@ -368,11 +370,12 @@ void execute() throws IOException {
368370
@Test
369371
@Order(4)
370372
void executeOnJava8() throws IOException {
373+
Java java8 = getJava8();
371374
var result = Request.builder() //
372-
.setTool(new Java()) //
373-
.setJavaHome(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) //
375+
.setTool(java8) //
376+
.setJavaHome(java8.getHome()) //
374377
.setProject("standalone") //
375-
.addArguments("--show-version") //
378+
.addArguments("-showversion") //
376379
.addArguments("-enableassertions") //
377380
.addArguments("-Djava.util.logging.config.file=logging.properties") //
378381
.addArguments("-Djunit.platform.launcher.interceptors.enabled=true") //
@@ -387,8 +390,8 @@ void executeOnJava8() throws IOException {
387390
assertEquals(1, result.getExitCode(), () -> getExitCodeMessage(result));
388391

389392
var workspace = Request.WORKSPACE.resolve("standalone");
390-
var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out.txt"));
391-
var expectedErrLines = Files.readAllLines(workspace.resolve("expected-err.txt"));
393+
var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out-java8.txt"));
394+
var expectedErrLines = Files.readAllLines(workspace.resolve("expected-err-java8.txt"));
392395
assertLinesMatch(expectedOutLines, result.getOutputLines("out"));
393396
assertLinesMatch(expectedErrLines, result.getOutputLines("err"));
394397

@@ -404,11 +407,12 @@ void executeOnJava8() throws IOException {
404407
@Order(5)
405408
// https://github.com/junit-team/junit5/issues/2600
406409
void executeOnJava8SelectPackage() throws IOException {
410+
Java java8 = getJava8();
407411
var result = Request.builder() //
408-
.setTool(new Java()) //
409-
.setJavaHome(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) //
412+
.setTool(java8) //
413+
.setJavaHome(java8.getHome()) //
410414
.setProject("standalone") //
411-
.addArguments("--show-version") //
415+
.addArguments("-showversion") //
412416
.addArguments("-enableassertions") //
413417
.addArguments("-Djava.util.logging.config.file=logging.properties") //
414418
.addArguments("-Djunit.platform.launcher.interceptors.enabled=true") //
@@ -423,8 +427,8 @@ void executeOnJava8SelectPackage() throws IOException {
423427
assertEquals(1, result.getExitCode(), () -> getExitCodeMessage(result));
424428

425429
var workspace = Request.WORKSPACE.resolve("standalone");
426-
var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out.txt"));
427-
var expectedErrLines = Files.readAllLines(workspace.resolve("expected-err.txt"));
430+
var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out-java8.txt"));
431+
var expectedErrLines = Files.readAllLines(workspace.resolve("expected-err-java8.txt"));
428432
assertLinesMatch(expectedOutLines, result.getOutputLines("out"));
429433
assertLinesMatch(expectedErrLines, result.getOutputLines("err"));
430434

@@ -468,4 +472,22 @@ private static String getExitCodeMessage(Result result) {
468472
return "Exit codes don't match. Stdout:\n" + result.getOutput("out") + //
469473
"\n\nStderr:\n" + result.getOutput("err") + "\n";
470474
}
475+
476+
/**
477+
* Special override of class {@link Java} to resolve against a different {@code JAVA_HOME}.
478+
*/
479+
private static Java getJava8() {
480+
Path java8Home = Helper.getJavaHome("8").orElseThrow(TestAbortedException::new);
481+
return new Java() {
482+
@Override
483+
public Path getHome() {
484+
return java8Home;
485+
}
486+
487+
@Override
488+
public String getVersion() {
489+
return "8";
490+
}
491+
};
492+
}
471493
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy