Skip to content

Commit f0c1f18

Browse files
authored
Merge pull request #501 from RalfJung/travis
rewrite cargo-miri test in Python
2 parents 9c57f2b + 8fe51ca commit f0c1f18

File tree

2 files changed

+50
-24
lines changed

2 files changed

+50
-24
lines changed

.travis.yml

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ os:
1111
- osx
1212

1313
before_script:
14-
# mac os weirdness (https://github.com/travis-ci/travis-ci/issues/6307)
15-
- rvm get stable
14+
# macOS weirdness (https://github.com/travis-ci/travis-ci/issues/6307)
15+
- if [[ "$TRAVIS_OS_NAME" == osx ]]; then rvm get stable; fi
1616
# Compute the rust version we use. We do not use "language: rust" to have more control here.
1717
- |
1818
if [ "$TRAVIS_EVENT_TYPE" = cron ]; then
@@ -36,35 +36,18 @@ script:
3636
- |
3737
# Test and install plain miri
3838
cargo build --release --all-features &&
39-
#cargo test --release --all-features &&
39+
cargo test --release --all-features &&
4040
cargo install --all-features --force --path .
4141
- |
4242
# get ourselves a MIR-full libstd
4343
xargo/build.sh &&
4444
export MIRI_SYSROOT=~/.xargo/HOST
45-
#- |
46-
# # run all tests with full mir
47-
# cargo test --release --all-features
45+
- |
46+
# run all tests with full mir
47+
cargo test --release --all-features
4848
- |
4949
# Test cargo integration
50-
cd cargo-miri-test &&
51-
# Test `cargo miri`
52-
# We ignore the exit code because we want to see the output even on failure, and
53-
# I found no way to preserve the exit code so that we can test for it later.
54-
# Variables set in this subshell in the parenthesis are not available
55-
# on the outside.
56-
# We assume that if this fails, it'll also print something about the failure on
57-
# stdout/stderr and we'll catch that.
58-
# FIXME: Disabling validation, still investigating whether there is UB here
59-
(cargo miri -q >stdout.real 2>stderr.real -- -Zmiri-disable-validation || true) &&
60-
# Print file names and contents (`cat` would just print contents)
61-
tail -n +0 stdout.real stderr.real &&
62-
# Verify output
63-
diff -u stdout.ref stdout.real &&
64-
diff -u stderr.ref stderr.real &&
65-
# test `cargo miri test`
66-
cargo miri test &&
67-
cd ..
50+
(cd cargo-miri-test && ./run-test.py)
6851
6952
notifications:
7053
email:

cargo-miri-test/run-test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 test_cargo_miri():
11+
print("==> Testing `cargo miri` <==")
12+
## Call `cargo miri`, capture all output
13+
# FIXME: Disabling validation, still investigating whether there is UB here
14+
p = subprocess.Popen(
15+
["cargo", "miri", "-q", "--", "-Zmiri-disable-validation"],
16+
stdout=subprocess.PIPE,
17+
stderr=subprocess.PIPE
18+
)
19+
(stdout, stderr) = p.communicate()
20+
stdout = stdout.decode("UTF-8")
21+
stderr = stderr.decode("UTF-8")
22+
# Show output
23+
print("=> captured stdout <=")
24+
print(stdout, end="")
25+
print("=> captured stderr <=")
26+
print(stderr, end="")
27+
# Test for failures
28+
if p.returncode != 0:
29+
sys.exit(1)
30+
if stdout != open('stdout.ref').read():
31+
print("stdout does not match reference")
32+
sys.exit(1)
33+
if stderr != open('stderr.ref').read():
34+
print("stderr does not match reference")
35+
sys.exit(1)
36+
37+
def test_cargo_miri_test():
38+
print("==> Testing `cargo miri test` <==")
39+
subprocess.check_call(["cargo", "miri", "test"])
40+
41+
test_cargo_miri()
42+
test_cargo_miri_test()
43+
sys.exit(0)

0 commit comments

Comments
 (0)