Skip to content

Commit 28a6d6c

Browse files
committed
Check both stdout and stderr with difflib
1 parent c8d1d9b commit 28a6d6c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

test-cargo-miri/run-test.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ def normalize_stdout(str):
2727
str = str.replace("src\\", "src/") # normalize paths across platforms
2828
return re.sub("finished in \d+\.\d\ds", "finished in $TIME", str)
2929

30+
def check_output(expected, actual, path, name):
31+
if expected == actual:
32+
return True
33+
print(f"{path} did not match reference!")
34+
print(f"--- BEGIN diff {name} ---")
35+
for text in difflib.unified_diff(expected.split("\n"), actual.split("\n")):
36+
print(text)
37+
print(f"--- END diff {name} ---")
38+
return False
39+
3040
def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}):
3141
print("Testing {}...".format(name))
3242
## Call `cargo miri`, capture all output
@@ -44,18 +54,9 @@ def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}):
4454
stderr = stderr.decode("UTF-8")
4555
stdout = normalize_stdout(stdout)
4656
expected_stdout = open(stdout_ref).read()
47-
if p.returncode == 0 and stdout == expected_stdout and stderr == open(stderr_ref).read():
57+
if p.returncode == 0 and check_output(expected_stdout, stdout, stdout_ref, "stdout") and check_output(open(stderr_ref).read(), stderr, stderr_ref, "stderr"):
4858
# All good!
4959
return
50-
# Show output
51-
print(f"{stdout_ref} or {stderr_ref} did not match reference!")
52-
print("--- BEGIN test stdout ---")
53-
for text in difflib.unified_diff(expected_stdout.split("\n"), stdout.split("\n")):
54-
print(text)
55-
print("--- END test stdout ---")
56-
print("--- BEGIN test stderr ---")
57-
print(stderr, end="")
58-
print("--- END test stderr ---")
5960
fail("exit code was {}".format(p.returncode))
6061

6162
def test_no_rebuild(name, cmd, env={}):

0 commit comments

Comments
 (0)