Skip to content

Commit

Permalink
Auto merge of #2485 - japaric:no-cross-doctests, r=alexcrichton
Browse files Browse the repository at this point in the history
don't build/run doctests when target != host

fixes rust-lang/rust#31907

r? @alexcrichton
  • Loading branch information
bors committed Mar 15, 2016
2 parents 61b4578 + ac46a1b commit c3b571f
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ fn run_doc_tests(options: &TestOptions,
let mut errors = Vec::new();
let config = options.compile_opts.config;

// We don't build/rust doctests if target != host
if let Some(target) = options.compile_opts.target {
if config.rustc_info().host != target {
return Ok(errors);
}
}

let libs = compilation.to_doc_test.iter().map(|package| {
(package, package.targets().iter().filter(|t| t.doctested())
.map(|t| (t.src_path(), t.name(), t.crate_name())))
Expand Down
69 changes: 67 additions & 2 deletions tests/test_cargo_cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ fn alternate_arch() -> &'static str {
}
}

fn host() -> String {
let platform = match env::consts::OS {
"linux" => "unknown-linux-gnu",
"macos" => "apple-darwin",
"windows" => "pc-windows-msvc",
_ => unreachable!(),
};
let arch = match env::consts::ARCH {
"x86" => "i686",
"x86_64" => "x86_64",
_ => unreachable!(),
};
format!("{}-{}", arch, platform)
}

test!(simple_cross {
if disabled() { return }

Expand Down Expand Up @@ -464,14 +479,64 @@ test test_foo ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
", compiling = COMPILING, running = RUNNING, foo = p.url(), triple = target)));
});

test!(no_cross_doctests {
if disabled() { return }

let p = project("foo")
.file("Cargo.toml", r#"
[project]
name = "foo"
authors = []
version = "0.0.0"
"#)
.file("src/lib.rs", r#"
//! ```
//! extern crate foo;
//! assert!(true);
//! ```
"#);

let host_output = format!("\
{compiling} foo v0.0.0 ({foo})
{running} target[..]foo-[..]
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
{doctest} foo
running 1 test
test _0 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
", compiling = COMPILING, running = RUNNING, foo = p.url(), doctest = DOCTEST);

assert_that(p.cargo_process("test"),
execs().with_status(0)
.with_stdout(&host_output));

let target = host();
assert_that(p.cargo_process("test").arg("--target").arg(&target),
execs().with_status(0)
.with_stdout(&host_output));

let target = alternate();
assert_that(p.cargo_process("test").arg("--target").arg(&target),
execs().with_status(0)
.with_stdout(&format!("\
{compiling} foo v0.0.0 ({foo})
{running} target[..]{triple}[..]foo-[..]
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
", compiling = COMPILING, running = RUNNING, foo = p.url(), triple = target,
doctest = DOCTEST)));
", compiling = COMPILING, running = RUNNING, foo = p.url(), triple = target)));
});

test!(simple_cargo_run {
Expand Down

0 comments on commit c3b571f

Please sign in to comment.