Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix StandaloneTests specific for Java 8 #3416

Merged
merged 4 commits into from
Sep 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

import de.sormuras.bartholdy.Result;
import de.sormuras.bartholdy.jdk.Jar;
Expand Down Expand Up @@ -69,7 +70,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 +90,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 +101,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 +330,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 +352,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 +371,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 +388,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 expectedErrLines = getExpectedErrLinesOnJava8(workspace);
assertLinesMatch(expectedOutLines, result.getOutputLines("out"));
assertLinesMatch(expectedErrLines, result.getOutputLines("err"));

Expand All @@ -404,11 +408,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 +425,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 expectedErrLines = getExpectedErrLinesOnJava8(workspace);
assertLinesMatch(expectedOutLines, result.getOutputLines("out"));
assertLinesMatch(expectedErrLines, result.getOutputLines("err"));

Expand All @@ -436,6 +441,13 @@ void executeOnJava8SelectPackage() throws IOException {
+ " (group ID: org.junit.vintage, artifact ID: junit-vintage-engine, version: " + vintageVersion));
}

private static List<String> getExpectedErrLinesOnJava8(Path workspace) throws IOException {
var expectedErrLines = new ArrayList<String>();
expectedErrLines.add(">> JAVA VERSION >>");
expectedErrLines.addAll(Files.readAllLines(workspace.resolve("expected-err.txt")));
return expectedErrLines;
}

@Test
@Order(6)
@Disabled("https://github.com/junit-team/junit5/issues/1724")
Expand All @@ -461,6 +473,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";
}

/**
* Special 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";
}
};
}
}