Skip to content

Commit f85bb0f

Browse files
committed
test for unnecessary rebuilds in 'cargo miri run'
1 parent e29f137 commit f85bb0f

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

test-cargo-miri/run-test.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ def fail(msg):
1515
print("\nTEST FAIL: {}".format(msg))
1616
sys.exit(1)
1717

18-
def cargo_miri(cmd):
19-
args = ["cargo", "miri", cmd, "-q"]
18+
def cargo_miri(cmd, quiet = True):
19+
args = ["cargo", "miri", cmd]
20+
if quiet:
21+
args += ["-q"]
2022
if 'MIRI_TEST_TARGET' in os.environ:
2123
args += ["--target", os.environ['MIRI_TEST_TARGET']]
2224
return args
@@ -48,6 +50,25 @@ def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}):
4850
print("--- END stderr ---")
4951
fail("exit code was {}".format(p.returncode))
5052

53+
def test_rebuild(name, cmd, rebuild_count_expected):
54+
print("Testing {}...".format(name))
55+
p = subprocess.Popen(
56+
cmd,
57+
stdout=subprocess.PIPE,
58+
stderr=subprocess.PIPE,
59+
)
60+
(stdout, stderr) = p.communicate()
61+
stdout = stdout.decode("UTF-8")
62+
stderr = stderr.decode("UTF-8")
63+
if p.returncode != 0:
64+
fail("rebuild failed");
65+
rebuild_count = stderr.count(" Compiling ");
66+
if rebuild_count != rebuild_count_expected:
67+
print("--- BEGIN stderr ---")
68+
print(stderr, end="")
69+
print("--- END stderr ---")
70+
fail("Expected {} rebuild(s), but got {}".format(rebuild_count_expected, rebuild_count));
71+
5172
def test_cargo_miri_run():
5273
test("`cargo miri run` (no isolation)",
5374
cargo_miri("run"),
@@ -67,6 +88,11 @@ def test_cargo_miri_run():
6788
"run.subcrate.stdout.ref", "run.subcrate.stderr.ref",
6889
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
6990
)
91+
# Special test: run it again *without* `-q` to make sure nothing is being rebuilt (Miri issue #1722)
92+
test_rebuild("`cargo miri run` (clean rebuild)",
93+
cargo_miri("run", quiet=False) + ["--", ""],
94+
rebuild_count_expected=1,
95+
)
7096

7197
def test_cargo_miri_test():
7298
# rustdoc is not run on foreign targets

0 commit comments

Comments
 (0)