Skip to content

Commit

Permalink
moved cross-compiling doctests behind the doctest-xcompile feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Goirad committed Sep 18, 2019
1 parent 8c93de6 commit a5235b7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ pub struct CliUnstable {
pub binary_dep_depinfo: bool,
pub build_std: Option<Vec<String>>,
pub timings: Option<Vec<String>>,
pub doctest_xcompile: bool,
}

impl CliUnstable {
Expand Down Expand Up @@ -393,6 +394,7 @@ impl CliUnstable {
self.build_std = Some(crate::core::compiler::standard_lib::parse_unstable_flag(v))
}
"timings" => self.timings = Some(parse_timings(v)),
"doctest-xcompile" => self.doctest_xcompile = true,
_ => failure::bail!("unknown `-Z` flag specified: {}", k),
}

Expand Down
18 changes: 14 additions & 4 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,16 @@ fn run_doc_tests(
let mut errors = Vec::new();
let config = options.compile_opts.config;

let runtool = compilation.target_runner();
// The unstable doctest-xcompile feature enables both per-target-ignores and
// cross-compiling doctests. As a side effect, this feature also gates running
// doctests with runtools when target == host.
let doctest_xcompile = config.cli_unstable().doctest_xcompile;
let mut runtool: &Option<(std::path::PathBuf, Vec<String>)> = &None;
if doctest_xcompile {
runtool = compilation.target_runner();
} else if compilation.host != compilation.target {
return Ok((Test::Doc, errors));
}

for doctest_info in &compilation.to_doc_test {
let Doctest {
Expand All @@ -155,9 +164,10 @@ fn run_doc_tests(
.arg("--crate-name")
.arg(&target.crate_name());

p.arg("-Z");
p.arg("unstable-options");
p.arg("--enable-per-target-ignores");
if doctest_xcompile {
p.arg("-Zunstable-options");
p.arg("--enable-per-target-ignores");
}

runtool.as_ref().map(|(runtool, runtool_args)| {
p.arg("--target").arg(&compilation.target);
Expand Down
7 changes: 2 additions & 5 deletions tests/testsuite/cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ fn cross_tests() {
[COMPILING] foo v0.0.0 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/{triple}/debug/deps/foo-[..][EXE]
[RUNNING] target/{triple}/debug/deps/bar-[..][EXE]
[DOCTEST] Skipping doctests, no runner defined for target",
[RUNNING] target/{triple}/debug/deps/bar-[..][EXE]",
triple = target
))
.with_stdout_contains("test test_foo ... ok")
Expand Down Expand Up @@ -596,7 +595,6 @@ fn no_cross_doctests() {
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/{triple}/debug/deps/foo-[..][EXE]
[DOCTEST] Skipping doctests, no runner defined for target
",
triple = target
))
Expand Down Expand Up @@ -1225,8 +1223,7 @@ fn cross_test_dylib() {
[COMPILING] foo v0.0.1 ([CWD])
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
[RUNNING] target/{arch}/debug/deps/foo-[..][EXE]
[RUNNING] target/{arch}/debug/deps/test-[..][EXE]
[DOCTEST] Skipping doctests, no runner defined for target",
[RUNNING] target/{arch}/debug/deps/test-[..][EXE]",
arch = cross_compile::alternate()
))
.with_stdout_contains_n("test foo ... ok", 2)
Expand Down

0 comments on commit a5235b7

Please sign in to comment.