Skip to content

Commit

Permalink
Merge branch 'fix-standalone-test-java8' into fix-java-22-console-tes…
Browse files Browse the repository at this point in the history
…t-failures

Temporary merge to see if new tip of pull request junit-team#3416 fixes issue in
the Java 22 pull request.
  • Loading branch information
rybak committed Aug 6, 2023
2 parents a086903 + 140dfa3 commit 6c20951
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 21 deletions.
2 changes: 1 addition & 1 deletion documentation/src/docs/asciidoc/user-guide/appendix.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ artifacts are deployed to Sonatype's {snapshot-repo}[snapshots repository] under
The _Bill of Materials_ POM provided under the following Maven coordinates can be used to
ease dependency management when referencing multiple of the above artifacts using
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies[Maven]
or https://docs.gradle.org/current/userguide/managing_transitive_dependencies.html#sec:bom_import[Gradle].
or https://docs.gradle.org/current/userguide/platforms.html#sub:bom_import[Gradle].

* *Group ID*: `org.junit`
* *Artifact ID*: `junit-bom`
Expand Down
2 changes: 1 addition & 1 deletion junit-bom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ This module provides a Bill of Materials POM to ease dependency management using
or [Gradle]. Please refer to the [User Guide] for details.

[Maven]: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Importing_Dependencies
[Gradle]: https://docs.gradle.org/current/userguide/managing_transitive_dependencies.html#sec:bom_import
[Gradle]: https://docs.gradle.org/current/userguide/platforms.html#sub:bom_import
[User Guide]: https://junit.org/junit5/docs/current/user-guide/#dependency-metadata-junit-bom
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
>> JAVA VERSION >>
.+ org.junit.platform.launcher.core.ServiceLoaderRegistry load
.+ Loaded LauncherInterceptor instances: ..
.+ org.junit.platform.launcher.core.ServiceLoaderRegistry load
.+ Loaded LauncherSessionListener instances: ..
.+ org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
.+ Discovered TestEngines:
- junit-jupiter .+
- junit-vintage .+
- junit-platform-suite .+
.+ org.junit.platform.launcher.core.ServiceLoaderRegistry load
.+ Loaded PostDiscoveryFilter instances: ..
.+ org.junit.platform.launcher.core.ServiceLoaderRegistry load
.+ Loaded LauncherDiscoveryListener instances: ..
.+ org.junit.platform.launcher.core.ServiceLoaderRegistry load
.+ Loaded TestExecutionListener instances: .+
.+ org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
.+ Discovered TestEngines:
- junit-jupiter .+
- junit-vintage .+
- junit-platform-suite .+
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
>> TREE >>
Failures (2):
>> STACKTRACE >>

Test run finished after \d+ ms
[ 11 containers found ]
[ 0 containers skipped ]
[ 11 containers started ]
[ 0 containers aborted ]
[ 11 containers successful ]
[ 0 containers failed ]
[ 10 tests found ]
[ 2 tests skipped ]
[ 8 tests started ]
[ 1 tests aborted ]
[ 5 tests successful ]
[ 2 tests failed ]

Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void listAllObservableEngines() {
.addArguments("engines", "--disable-banner").build() //
.run(false);

assertEquals(0, result.getExitCode(), String.join("\n", result.getOutputLines("out")));
assertEquals(0, result.getExitCode(), () -> getExitCodeMessage(result));

var jupiterVersion = Helper.version("junit-jupiter-engine");
var suiteVersion = Helper.version("junit-platform-suite-engine");
Expand All @@ -89,6 +89,8 @@ void compile() throws Exception {
var result = Request.builder() //
.setTool(new Javac()) //
.setProject("standalone") //
.addArguments("-Xlint:-options")
.addArguments("--release", "8")
.addArguments("-proc:none") //
.addArguments("-d", workspace.resolve("bin")) //
.addArguments("--class-path", MavenRepo.jar("junit-platform-console-standalone")) //
Expand All @@ -98,7 +100,7 @@ void compile() throws Exception {
.addArguments(workspace.resolve("src/standalone/VintageIntegration.java")).build() //
.run();

assertEquals(0, result.getExitCode(), result.getOutput("out") + result.getOutput("err"));
assertEquals(0, result.getExitCode(), () -> getExitCodeMessage(result));
assertTrue(result.getOutput("out").isEmpty());
assertTrue(result.getOutput("err").isEmpty());

Expand Down Expand Up @@ -327,7 +329,7 @@ private static Result discover(String... args) {
.build() //
.run(false);

assertEquals(0, result.getExitCode(), String.join("\n", result.getOutputLines("out")));
assertEquals(0, result.getExitCode(), () -> getExitCodeMessage(result));
return result;
}

Expand All @@ -349,13 +351,13 @@ void execute() throws IOException {
.addArguments("--classpath", "bin").build() //
.run(false);

assertEquals(1, result.getExitCode(), String.join("\n", result.getOutputLines("out")));
assertEquals(1, result.getExitCode(), () -> getExitCodeMessage(result));

var workspace = Request.WORKSPACE.resolve("standalone");
var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out.txt"));
var expectedErrLines = Files.readAllLines(workspace.resolve("expected-err.txt"));
assertLinesMatch(expectedOutLines, result.getOutputLines("out"), result.getOutput("out"));
assertLinesMatch(expectedErrLines, result.getOutputLines("err"), result.getOutput("err"));
assertLinesMatch(expectedOutLines, result.getOutputLines("out"));
assertLinesMatch(expectedErrLines, result.getOutputLines("err"));

var jupiterVersion = Helper.version("junit-jupiter-engine");
var vintageVersion = Helper.version("junit-vintage-engine");
Expand All @@ -368,11 +370,12 @@ void execute() throws IOException {
@Test
@Order(4)
void executeOnJava8() throws IOException {
Java java8 = getJava8();
var result = Request.builder() //
.setTool(new Java()) //
.setJavaHome(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) //
.setTool(java8) //
.setJavaHome(java8.getHome()) //
.setProject("standalone") //
.addArguments("--show-version") //
.addArguments("-showversion") //
.addArguments("-enableassertions") //
.addArguments("-Djava.util.logging.config.file=logging.properties") //
.addArguments("-Djunit.platform.launcher.interceptors.enabled=true") //
Expand All @@ -384,11 +387,11 @@ void executeOnJava8() throws IOException {
.addArguments("--classpath", "bin").build() //
.run(false);

assertEquals(1, result.getExitCode(), String.join("\n", result.getOutputLines("out")));
assertEquals(1, result.getExitCode(), () -> getExitCodeMessage(result));

var workspace = Request.WORKSPACE.resolve("standalone");
var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out.txt"));
var expectedErrLines = Files.readAllLines(workspace.resolve("expected-err.txt"));
var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out-java8.txt"));
var expectedErrLines = Files.readAllLines(workspace.resolve("expected-err-java8.txt"));
assertLinesMatch(expectedOutLines, result.getOutputLines("out"));
assertLinesMatch(expectedErrLines, result.getOutputLines("err"));

Expand All @@ -404,11 +407,12 @@ void executeOnJava8() throws IOException {
@Order(5)
// https://github.com/junit-team/junit5/issues/2600
void executeOnJava8SelectPackage() throws IOException {
Java java8 = getJava8();
var result = Request.builder() //
.setTool(new Java()) //
.setJavaHome(Helper.getJavaHome("8").orElseThrow(TestAbortedException::new)) //
.setTool(java8) //
.setJavaHome(java8.getHome()) //
.setProject("standalone") //
.addArguments("--show-version") //
.addArguments("-showversion") //
.addArguments("-enableassertions") //
.addArguments("-Djava.util.logging.config.file=logging.properties") //
.addArguments("-Djunit.platform.launcher.interceptors.enabled=true") //
Expand All @@ -420,11 +424,11 @@ void executeOnJava8SelectPackage() throws IOException {
.addArguments("--classpath", "bin").build() //
.run(false);

assertEquals(1, result.getExitCode(), String.join("\n", result.getOutputLines("out")));
assertEquals(1, result.getExitCode(), () -> getExitCodeMessage(result));

var workspace = Request.WORKSPACE.resolve("standalone");
var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out.txt"));
var expectedErrLines = Files.readAllLines(workspace.resolve("expected-err.txt"));
var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out-java8.txt"));
var expectedErrLines = Files.readAllLines(workspace.resolve("expected-err-java8.txt"));
assertLinesMatch(expectedOutLines, result.getOutputLines("out"));
assertLinesMatch(expectedErrLines, result.getOutputLines("err"));

Expand Down Expand Up @@ -461,6 +465,29 @@ void executeWithJarredTestClasses() {
.build() //
.run(false);

assertEquals(1, result.getExitCode(), String.join("\n", result.getOutputLines("out")));
assertEquals(1, result.getExitCode(), () -> getExitCodeMessage(result));
}

private static String getExitCodeMessage(Result result) {
return "Exit codes don't match. Stdout:\n" +
result.getOutput("out") + "\n\nStderr:\n" + result.getOutput("err") + "\n";
}

/**
* Speicial override of class {@link Java} to resolve against a different {@code JAVA_HOME}.
*/
private static Java getJava8() {
Path java8Home = Helper.getJavaHome("8").orElseThrow(TestAbortedException::new);
return new Java() {
@Override
public Path getHome() {
return java8Home;
}

@Override
public String getVersion() {
return "8";
}
};
}
}

0 comments on commit 6c20951

Please sign in to comment.