]> git.lizzy.rs Git - rust.git/blob - test-cargo-miri/run-test.py
Merge remote-tracking branch 'origin/master' into cargo-miri-test
[rust.git] / test-cargo-miri / run-test.py
1 #!/usr/bin/env python3
2 '''
3 Test whether cargo-miri works properly.
4 Assumes the `MIRI_SYSROOT` env var to be set appropriately,
5 and the working directory to contain the cargo-miri-test project.
6 '''
7
8 import sys, subprocess
9
10 def test(name, cmd, stdout_ref, stderr_ref):
11     print("==> Testing `{}` <==".format(name))
12     ## Call `cargo miri`, capture all output
13     p = subprocess.Popen(
14         cmd,
15         stdout=subprocess.PIPE,
16         stderr=subprocess.PIPE
17     )
18     (stdout, stderr) = p.communicate()
19     stdout = stdout.decode("UTF-8")
20     stderr = stderr.decode("UTF-8")
21     # Show output
22     print("=> captured stdout <=")
23     print(stdout, end="")
24     print("=> captured stderr <=")
25     print(stderr, end="")
26     # Test for failures
27     if p.returncode != 0:
28         sys.exit(1)
29     if stdout != open(stdout_ref).read():
30         print("stdout does not match reference")
31         sys.exit(1)
32     if stderr != open(stderr_ref).read():
33         print("stderr does not match reference")
34         sys.exit(1)
35
36 def test_cargo_miri_run():
37     test("cargo miri run", ["cargo", "miri", "run", "-q"], "stout.ref", "stderr.ref")
38
39 def test_cargo_miri_test():
40     # FIXME: validation disabled for now because of https://github.com/rust-lang/rust/issues/54957
41     test("cargo miri test", ["cargo", "miri", "test", "-q", "--", "-Zmiri-disable-validation"], "stout.ref", "stderr.ref")
42
43 test_cargo_miri_run()
44 test_cargo_miri_test()
45 sys.exit(0)