mirror of
https://github.com/openjdk/jdk.git
synced 2026-04-28 15:51:02 +00:00
8372385: tools/jpackage/junit/share/jdk.jpackage/jdk/jpackage/internal/cli/MainTest.java fails
Reviewed-by: almatvee
This commit is contained in:
parent
b054a56571
commit
55362e191d
@ -36,6 +36,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Stream;
|
||||
import jdk.internal.util.OperatingSystem;
|
||||
import jdk.jpackage.test.JUnitAdapter;
|
||||
@ -58,7 +60,9 @@ public class MainTest extends JUnitAdapter.TestSrcInitializer {
|
||||
// Print the tool version
|
||||
build().args("--version").expectVersion(),
|
||||
// Print the tool version
|
||||
build().args("foo", "bar").expectErrors(I18N.format("error.non-option-arguments", 2)),
|
||||
// Additional error messages may be printed if the default bundling operation
|
||||
// can not be identified; don't verify these errors in the output.
|
||||
build().args("foo", "bar").stderrMatchType(OutputMatchType.STARTS_WITH).expectErrors(I18N.format("error.non-option-arguments", 2)),
|
||||
// Valid command line requesting to print the full help.
|
||||
build().args("-h").expectFullHelp(),
|
||||
// Valid command line requesting to build a package and print the full help.
|
||||
@ -68,12 +72,14 @@ public class MainTest extends JUnitAdapter.TestSrcInitializer {
|
||||
// Valid command line requesting to print the full help and the version of the tool.
|
||||
build().args("--help", "--version").expectVersionWithHelp(),
|
||||
// Invalid command line requesting to print the version of the tool.
|
||||
build().args("foo", "--version").expectErrors(I18N.format("error.non-option-arguments", 1))
|
||||
// Additional error messages may be printed if the default bundling operation
|
||||
// can not be identified; don't verify these errors in the output.
|
||||
build().args("foo", "--version").stderrMatchType(OutputMatchType.STARTS_WITH).expectErrors(I18N.format("error.non-option-arguments", 1))
|
||||
).map(TestSpec.Builder::create).toList();
|
||||
}
|
||||
|
||||
|
||||
record TestSpec(List<String> args, int expectedExitCode, List<String> expectedStdout, List<String> expectedStderr) {
|
||||
record TestSpec(List<String> args, int expectedExitCode, ExpectedOutput expectedStdout, ExpectedOutput expectedStderr) {
|
||||
|
||||
TestSpec {
|
||||
Objects.requireNonNull(args);
|
||||
@ -84,15 +90,19 @@ public class MainTest extends JUnitAdapter.TestSrcInitializer {
|
||||
void run() {
|
||||
var result = ExecutionResult.create(args.toArray(String[]::new));
|
||||
assertEquals(expectedExitCode, result.exitCode());
|
||||
assertEquals(expectedStdout, result.stdout());
|
||||
assertEquals(expectedStderr, result.stderr());
|
||||
expectedStdout.test(result.stdout());
|
||||
expectedStderr.test(result.stderr());
|
||||
}
|
||||
|
||||
|
||||
static final class Builder {
|
||||
|
||||
TestSpec create() {
|
||||
return new TestSpec(args, expectedExitCode, expectedStdout, expectedStderr);
|
||||
return new TestSpec(
|
||||
args,
|
||||
expectedExitCode,
|
||||
new ExpectedOutput(expectedStdout, Optional.ofNullable(stdoutMatchType).orElse(OutputMatchType.EQUALS)),
|
||||
new ExpectedOutput(expectedStderr, Optional.ofNullable(stderrMatchType).orElse(OutputMatchType.EQUALS)));
|
||||
}
|
||||
|
||||
Builder args(String... v) {
|
||||
@ -104,6 +114,16 @@ public class MainTest extends JUnitAdapter.TestSrcInitializer {
|
||||
return this;
|
||||
}
|
||||
|
||||
Builder stdoutMatchType(OutputMatchType v) {
|
||||
stdoutMatchType = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
Builder stderrMatchType(OutputMatchType v) {
|
||||
stderrMatchType = v;
|
||||
return this;
|
||||
}
|
||||
|
||||
Builder expectStdout(String... lines) {
|
||||
return expectStdout(List.of(lines));
|
||||
}
|
||||
@ -164,6 +184,8 @@ public class MainTest extends JUnitAdapter.TestSrcInitializer {
|
||||
|
||||
private List<String> args = new ArrayList<>();
|
||||
private int expectedExitCode;
|
||||
private OutputMatchType stdoutMatchType;
|
||||
private OutputMatchType stderrMatchType;
|
||||
private List<String> expectedStdout = new ArrayList<>();
|
||||
private List<String> expectedStderr = new ArrayList<>();
|
||||
}
|
||||
@ -188,6 +210,37 @@ public class MainTest extends JUnitAdapter.TestSrcInitializer {
|
||||
}
|
||||
|
||||
|
||||
private enum OutputMatchType {
|
||||
EQUALS((_, actual) -> actual),
|
||||
STARTS_WITH((expected, actual) -> {
|
||||
if (expected.size() < actual.size()) {
|
||||
return actual.subList(0, expected.size());
|
||||
}
|
||||
return actual;
|
||||
}),
|
||||
;
|
||||
|
||||
OutputMatchType(BiFunction<List<String>, List<String>, List<String>> mapper) {
|
||||
this.mapper = Objects.requireNonNull(mapper);
|
||||
}
|
||||
|
||||
private final BiFunction<List<String>, List<String>, List<String>> mapper;
|
||||
}
|
||||
|
||||
|
||||
private record ExpectedOutput(List<String> content, OutputMatchType type) {
|
||||
ExpectedOutput {
|
||||
Objects.requireNonNull(content);
|
||||
Objects.requireNonNull(type);
|
||||
}
|
||||
|
||||
void test(List<String> lines) {
|
||||
var filteredLines = type.mapper.apply(content, lines);
|
||||
assertEquals(content, filteredLines);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static TestSpec.Builder build() {
|
||||
return new TestSpec.Builder();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user