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.
8 import sys, subprocess, os
15 print("\nTEST FAIL: {}".format(msg))
19 args = ["cargo", "miri", cmd, "-q"]
20 if 'MIRI_TEST_TARGET' in os.environ:
21 args += ["--target", os.environ['MIRI_TEST_TARGET']]
24 def test(name, cmd, stdout_ref, stderr_ref):
25 print("==> Testing `{}` <==".format(name))
26 ## Call `cargo miri`, capture all output
29 stdout=subprocess.PIPE,
30 stderr=subprocess.PIPE
32 (stdout, stderr) = p.communicate()
33 stdout = stdout.decode("UTF-8")
34 stderr = stderr.decode("UTF-8")
36 print("=> captured stdout <=")
38 print("=> captured stderr <=")
42 fail("Non-zero exit status")
43 if stdout != open(stdout_ref).read():
44 fail("stdout does not match reference")
45 if stderr != open(stderr_ref).read():
46 fail("stderr does not match reference")
48 def test_cargo_miri_run():
49 test("cargo miri run",
51 "stdout.ref", "stderr.ref"
53 test("cargo miri run (with target)",
54 cargo_miri("run") + ["--bin", "cargo-miri-test"],
55 "stdout.ref", "stderr.ref"
57 test("cargo miri run (with arguments)",
58 cargo_miri("run") + ["--", "--", "hello world", '"hello world"'],
59 "stdout.ref", "stderr.ref2"
62 def test_cargo_miri_test():
63 test("cargo miri test",
64 cargo_miri("test") + ["--", "-Zmiri-seed=feed"],
65 "test.stdout.ref", "test.stderr.ref"
67 test("cargo miri test (with filter)",
68 cargo_miri("test") + ["--", "--", "le1"],
69 "test.stdout.ref2", "test.stderr.ref"
71 test("cargo miri test (without isolation)",
72 cargo_miri("test") + ["--", "-Zmiri-disable-isolation", "--", "num_cpus"],
73 "test.stdout.ref3", "test.stderr.ref"
75 test("cargo miri test (test target)",
76 cargo_miri("test") + ["--test", "test"],
77 "test.stdout.ref4", "test.stderr.ref"
79 test("cargo miri test (bin target)",
80 cargo_miri("test") + ["--bin", "cargo-miri-test"],
81 "test.stdout.ref5", "test.stderr.ref"
84 os.chdir(os.path.dirname(os.path.realpath(__file__)))
86 target_str = " for target {}".format(os.environ['MIRI_TEST_TARGET']) if 'MIRI_TEST_TARGET' in os.environ else ""
87 print(CGREEN + CBOLD + "## Running `cargo miri` tests{}".format(target_str) + CEND)
89 if not 'MIRI_SYSROOT' in os.environ:
90 # Make sure we got a working sysroot.
91 # (If the sysroot gets built later when output is compared, that leads to test failures.)
92 subprocess.run(cargo_miri("setup"), check=True)
94 test_cargo_miri_test()
96 print("\nTEST SUCCESSFUL!")