]> git.lizzy.rs Git - rust.git/blob - test-cargo-miri/run-test.py
update cargo miri test to test rng crate a bit; this currently fails
[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 fail(msg):
11     print("TEST FAIL: {}".format(msg))
12     sys.exit(1)
13
14 def test(name, cmd, stdout_ref, stderr_ref):
15     print("==> Testing `{}` <==".format(name))
16     ## Call `cargo miri`, capture all output
17     p = subprocess.Popen(
18         cmd,
19         stdout=subprocess.PIPE,
20         stderr=subprocess.PIPE
21     )
22     (stdout, stderr) = p.communicate()
23     stdout = stdout.decode("UTF-8")
24     stderr = stderr.decode("UTF-8")
25     # Show output
26     print("=> captured stdout <=")
27     print(stdout, end="")
28     print("=> captured stderr <=")
29     print(stderr, end="")
30     # Test for failures
31     if p.returncode != 0:
32         fail("Non-zero exit status")
33     if stdout != open(stdout_ref).read():
34         fail("stdout does not match reference")
35     if stderr != open(stderr_ref).read():
36         fail("stderr does not match reference")
37
38 def test_cargo_miri_run():
39     test("cargo miri run", ["cargo", "miri", "run", "-q"], "stdout.ref", "stderr.ref")
40     test("cargo miri run (with arguments)",
41         ["cargo", "miri", "run", "-q", "--", "--", "hello world", '"hello world"'],
42         "stdout.ref", "stderr.ref2"
43     )
44
45 def test_cargo_miri_test():
46     test("cargo miri test", ["cargo", "miri", "test", "-q", "--", "-Zmiri-seed=feed"], "test.stdout.ref", "test.stderr.ref")
47     test("cargo miri test (with filter)",
48         ["cargo", "miri", "test", "-q", "--", "--", "impl"],
49         "test.stdout.ref2", "test.stderr.ref"
50     )
51
52 test_cargo_miri_run()
53 test_cargo_miri_test()
54 print("TEST SUCCESSFUL!")
55 sys.exit(0)