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
11 print("\nTEST FAIL: {}".format(msg))
15 args = ["cargo", "miri", cmd, "-q"]
16 if 'MIRI_TEST_TARGET' in os.environ:
17 args += ["--target", os.environ['MIRI_TEST_TARGET']]
20 def test(name, cmd, stdout_ref, stderr_ref):
21 print("==> Testing `{}` <==".format(name))
22 ## Call `cargo miri`, capture all output
25 stdout=subprocess.PIPE,
26 stderr=subprocess.PIPE
28 (stdout, stderr) = p.communicate()
29 stdout = stdout.decode("UTF-8")
30 stderr = stderr.decode("UTF-8")
32 print("=> captured stdout <=")
34 print("=> captured stderr <=")
38 fail("Non-zero exit status")
39 if stdout != open(stdout_ref).read():
40 fail("stdout does not match reference")
41 if stderr != open(stderr_ref).read():
42 fail("stderr does not match reference")
44 def test_cargo_miri_run():
45 test("cargo miri run",
47 "stdout.ref", "stderr.ref"
49 test("cargo miri run (with arguments)",
50 cargo_miri("run") + ["--", "--", "hello world", '"hello world"'],
51 "stdout.ref", "stderr.ref2"
54 def test_cargo_miri_test():
55 test("cargo miri test",
56 cargo_miri("test") + ["--", "-Zmiri-seed=feed"],
57 "test.stdout.ref", "test.stderr.ref"
59 test("cargo miri test (with filter)",
60 cargo_miri("test") + ["--", "--", "le1"],
61 "test.stdout.ref2", "test.stderr.ref"
64 os.chdir(os.path.dirname(os.path.realpath(__file__)))
67 test_cargo_miri_test()
69 print("\nTEST SUCCESSFUL!")