Skip to content

Commit

Permalink
Detect cross-mode and skip doc-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
teryror committed Jan 28, 2021
1 parent 154fb52 commit 10345ff
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
20 changes: 14 additions & 6 deletions cargo-miri/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,26 +882,34 @@ fn phase_cargo_rustdoc(fst_arg: &str, mut args: env::Args) {

// Because of the way the main function is structured, we have to take the first argument spearately
// from the rest; to simplify the following argument patching loop, we'll just skip that one.
// This is fine for now, because cargo will never pass the relevant arguments in the first position,
// This is fine for now, because cargo will never pass --extern arguments in the first position,
// but we should defensively assert that this will work.
let extern_flag = "--extern";
let runtool_flag = "--runtool";
assert!(fst_arg != extern_flag);
assert!(fst_arg != runtool_flag);
cmd.arg(fst_arg);


let runtool_flag = "--runtool";
let mut crossmode = fst_arg == runtool_flag;
while let Some(arg) = args.next() {
if arg == extern_flag {
// Patch --extern arguments to use *.rmeta files, since phase_cargo_rustc only creates stub *.rlib files.
forward_patched_extern_arg(&mut args, &mut cmd);
} else if arg == runtool_flag {
// Do not forward an existing --runtool argument, since we will set this ourselves
let _ = args.next().expect("`--runtool` should be followed by an executable name");
// An existing --runtool flag indicates cargo is running in cross-target mode, which we don't support.
// Note that this is only passed when cargo is run with the unstable -Zdoctest-xcompile flag;
// otherwise, we won't be called as rustdoc at all.
crossmode = true;
break;
} else {
cmd.arg(arg);
}
}

if crossmode {
eprintln!("Cross-interpreting doc-tests is not currently supported by Miri.");
return;
}

// For each doc-test, rustdoc starts two child processes: first the test is compiled,
// then the produced executable is invoked. We want to reroute both of these to cargo-miri,
// such that the first time we'll enter phase_cargo_rustc, and phase_cargo_runner second.
Expand Down
17 changes: 11 additions & 6 deletions test-cargo-miri/run-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def fail(msg):
sys.exit(1)

def cargo_miri(cmd):
args = ["cargo", "+nightly", "miri", cmd, "-q"]
args = ["cargo", "miri", cmd, "-q"]
if 'MIRI_TEST_TARGET' in os.environ:
args += ["-Zdoctest-xcompile"]
args += ["--target", os.environ['MIRI_TEST_TARGET']]
return args

def normalize_stdout(str):
str = str.replace("src\\", "src/") # normalize paths across platforms
return re.sub("finished in \d+\.\d\ds", "finished in $TIME", str)

def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}):
Expand Down Expand Up @@ -73,24 +73,29 @@ def test_cargo_miri_run():
)

def test_cargo_miri_test():
# rustdoc is not run on foreign targets
is_foreign = 'MIRI_TEST_TARGET' in os.environ
default_ref = "test.cross-target.stdout.ref" if is_foreign else "test.default.stdout.ref"
filter_ref = "test.filter.cross-target.stdout.ref" if is_foreign else "test.filter.stdout.ref"

test("`cargo miri test`",
cargo_miri("test"),
"test.default.stdout.ref", "test.stderr-empty.ref",
default_ref, "test.stderr-empty.ref",
env={'MIRIFLAGS': "-Zmiri-seed=feed"},
)
test("`cargo miri test` (no isolation)",
cargo_miri("test"),
"test.default.stdout.ref", "test.stderr-empty.ref",
default_ref, "test.stderr-empty.ref",
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
)
test("`cargo miri test` (raw-ptr tracking)",
cargo_miri("test"),
"test.default.stdout.ref", "test.stderr-empty.ref",
default_ref, "test.stderr-empty.ref",
env={'MIRIFLAGS': "-Zmiri-track-raw-pointers"},
)
test("`cargo miri test` (with filter)",
cargo_miri("test") + ["--", "--format=pretty", "le1"],
"test.filter.stdout.ref", "test.stderr-empty.ref",
filter_ref, "test.stderr-empty.ref",
)
test("`cargo miri test` (test target)",
cargo_miri("test") + ["--test", "test", "--", "--format=pretty"],
Expand Down
10 changes: 10 additions & 0 deletions test-cargo-miri/test.cross-target.stdout.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

running 1 test
.
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out


running 7 tests
..i....
test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out

11 changes: 11 additions & 0 deletions test-cargo-miri/test.filter.cross-target.stdout.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out


running 1 test
test simple1 ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 6 filtered out

0 comments on commit 10345ff

Please sign in to comment.