Skip to content

Commit

Permalink
Change WASI test runner behavior to match Python runner
Browse files Browse the repository at this point in the history
The reference implementation does not support or validate stderr. For
stdout, it treats a default specification for a missing JSON file as
if the field is not present, rather than an empty string (thus
ignoring anything that the test outputs to stdout).
  • Loading branch information
electrum committed Dec 24, 2024
1 parent e6620e3 commit 11295b6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class Specification {
private final List<String> dirs;
private final Map<String, String> env;
private final int exitCode;
private final Optional<String> stderr;
private final Optional<String> stdout;

@JsonCreator
Expand All @@ -24,13 +23,11 @@ public Specification(
@JsonProperty("dirs") List<String> dirs,
@JsonProperty("env") Map<String, String> env,
@JsonProperty("exit_code") int exitCode,
@JsonProperty("stderr") String stderr,
@JsonProperty("stdout") String stdout) {
this.args = requireNonNullElse(args, emptyList());
this.dirs = requireNonNullElse(dirs, emptyList());
this.env = requireNonNullElse(env, emptyMap());
this.exitCode = exitCode;
this.stderr = Optional.ofNullable(stderr);
this.stdout = Optional.ofNullable(stdout);
}

Expand All @@ -50,15 +47,11 @@ public int exitCode() {
return exitCode;
}

public Optional<String> stderr() {
return stderr;
}

public Optional<String> stdout() {
return stdout;
}

public static Specification createDefault() {
return new Specification(emptyList(), emptyList(), emptyMap(), 0, "", "");
return new Specification(emptyList(), emptyList(), emptyMap(), 0, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,15 @@ public void execute() throws MojoExecutionException {
new NameExpr("var exitCode"),
new NameExpr(String.valueOf(specification.exitCode())),
AssignExpr.Operator.ASSIGN))
.addStatement(
new AssignExpr(
new NameExpr("Optional<String> stderr"),
new NameExpr(optionalOf(specification.stderr())),
AssignExpr.Operator.ASSIGN))
.addStatement(
new AssignExpr(
new NameExpr("Optional<String> stdout"),
new NameExpr(optionalOf(specification.stdout())),
AssignExpr.Operator.ASSIGN))
.addStatement(
new NameExpr(
"WasiTestRunner.execute(test, args, dirs, env, exitCode,"
+ " stderr, stdout)"));
"WasiTestRunner.execute("
+ "test, args, dirs, env, exitCode, stdout)"));
}

dest.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public static void execute(
List<String> dirs,
Map<String, String> env,
int exitCode,
Optional<String> stderr,
Optional<String> stdout) {

try (FileSystem fs =
Expand Down Expand Up @@ -76,7 +75,6 @@ public static void execute(

assertEquals(exitCode, actualExitCode, "exit code");
stdout.ifPresent(expected -> assertEquals(expected, stdoutStream.output(), "stdout"));
stderr.ifPresent(expected -> assertEquals(expected, stderrStream.output(), "stderr"));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down

0 comments on commit 11295b6

Please sign in to comment.