Skip to content

Commit

Permalink
test cargo miri test output when testing cargo miri
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 2, 2018
1 parent 5a17c17 commit 49cf970
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cargo-miri-test/run-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import sys, subprocess

def test_cargo_miri():
print("==> Testing `cargo miri run` <==")
def test(name, cmd, stdout_ref, stderr_ref):
print("==> Testing `{}` <==".format(name))
## Call `cargo miri`, capture all output
p = subprocess.Popen(
["cargo", "miri", "run", "-q"],
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
Expand All @@ -26,17 +26,20 @@ def test_cargo_miri():
# Test for failures
if p.returncode != 0:
sys.exit(1)
if stdout != open('stdout.ref').read():
if stdout != open(stdout_ref).read():
print("stdout does not match reference")
sys.exit(1)
if stderr != open('stderr.ref').read():
if stderr != open(stderr_ref).read():
print("stderr does not match reference")
sys.exit(1)

def test_cargo_miri_run():
test("cargo miri run", ["cargo", "miri", "run", "-q"], "stout.ref", "stderr.ref")

def test_cargo_miri_test():
print("==> Testing `cargo miri test` <==")
subprocess.check_call(["cargo", "miri", "test"])
# validation disabled for now because of https://github.com/rust-lang/rust/issues/54957
test("cargo miri test", ["cargo", "miri", "test", "-q", "--", "-Zmiri-disable-validation"], "stout.ref", "stderr.ref")

test_cargo_miri()
test_cargo_miri_run()
test_cargo_miri_test()
sys.exit(0)
Empty file added cargo-miri-test/test.stderr.ref
Empty file.
7 changes: 7 additions & 0 deletions cargo-miri-test/test.stdout.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

running 2 tests
test bar ... ok
test baz ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

7 changes: 7 additions & 0 deletions cargo-miri-test/tests/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
fn bar() {
assert_eq!(4, 4);
}

// Having more than 1 test does seem to make a difference
// (i.e., this calls ptr::swap which having just one test does not).
#[test]
fn baz() {
assert_eq!(5, 5);
}

0 comments on commit 49cf970

Please sign in to comment.