rust/test-cargo-miri/run-test.py

47 lines
1.3 KiB
Python
Raw Normal View History

2018-10-30 09:07:40 -05:00
#!/usr/bin/env python3
2018-10-30 05:26:53 -05:00
'''
Test whether cargo-miri works properly.
Assumes the `MIRI_SYSROOT` env var to be set appropriately,
and the working directory to contain the cargo-miri-test project.
'''
import sys, subprocess
def fail(msg):
print("TEST FAIL: {}".format(msg))
sys.exit(1)
def test(name, cmd, stdout_ref, stderr_ref):
print("==> Testing `{}` <==".format(name))
2018-10-30 05:26:53 -05:00
## Call `cargo miri`, capture all output
p = subprocess.Popen(
cmd,
2018-10-30 05:26:53 -05:00
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
(stdout, stderr) = p.communicate()
stdout = stdout.decode("UTF-8")
stderr = stderr.decode("UTF-8")
# Show output
print("=> captured stdout <=")
print(stdout, end="")
print("=> captured stderr <=")
print(stderr, end="")
# Test for failures
if p.returncode != 0:
fail("Non-zero exit status")
if stdout != open(stdout_ref).read():
fail("stdout does not match reference")
if stderr != open(stderr_ref).read():
fail("stderr does not match reference")
2018-10-30 05:26:53 -05:00
def test_cargo_miri_run():
test("cargo miri run", ["cargo", "miri", "run", "-q"], "stdout.ref", "stderr.ref")
2018-10-30 05:26:53 -05:00
def test_cargo_miri_test():
test("cargo miri test", ["cargo", "miri", "test", "-q"], "test.stdout.ref", "test.stderr.ref")
2018-10-30 05:26:53 -05:00
test_cargo_miri_run()
2018-10-30 05:26:53 -05:00
test_cargo_miri_test()
sys.exit(0)