Skip to content

Commit fa34134

Browse files
author
Jorge Aparicio
committed
don't build/run doctests when target != host
fixes rust-lang/rust#31907
1 parent 61b4578 commit fa34134

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

src/cargo/ops/cargo_test.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ fn run_doc_tests(options: &TestOptions,
113113
let mut errors = Vec::new();
114114
let config = options.compile_opts.config;
115115

116+
// We don't build/rust doctests if target != host
117+
if let Some(target) = options.compile_opts.target {
118+
if config.rustc_info().host != target {
119+
return Ok(errors);
120+
}
121+
}
122+
116123
let libs = compilation.to_doc_test.iter().map(|package| {
117124
(package, package.targets().iter().filter(|t| t.doctested())
118125
.map(|t| (t.src_path(), t.name(), t.crate_name())))

tests/test_cargo_cross_compile.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,21 @@ fn alternate_arch() -> &'static str {
4646
}
4747
}
4848

49+
fn host() -> String {
50+
let platform = match env::consts::OS {
51+
"linux" => "unknown-linux-gnu",
52+
"macos" => "apple-darwin",
53+
"windows" => "pc-windows-msvc",
54+
_ => unreachable!(),
55+
};
56+
let arch = match env::consts::ARCH {
57+
"x86" => "i686",
58+
"x86_64" => "x86_64",
59+
_ => unreachable!(),
60+
};
61+
format!("{}-{}", arch, platform)
62+
}
63+
4964
test!(simple_cross {
5065
if disabled() { return }
5166

@@ -474,6 +489,63 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
474489
doctest = DOCTEST)));
475490
});
476491

492+
test!(no_cross_doctests {
493+
if disabled() { return }
494+
495+
let p = project("foo")
496+
.file("Cargo.toml", r#"
497+
[project]
498+
name = "foo"
499+
authors = []
500+
version = "0.0.0"
501+
"#)
502+
.file("src/lib.rs", r#"
503+
//! ```
504+
//! extern crate foo;
505+
//! assert!(true);
506+
//! ```
507+
"#);
508+
509+
let host_output = format!("\
510+
{compiling} foo v0.0.0 ({foo})
511+
{running} target[..]foo-[..]
512+
513+
running 0 tests
514+
515+
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
516+
517+
{doctest} foo
518+
519+
running 1 test
520+
test _0 ... ok
521+
522+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
523+
524+
", compiling = COMPILING, running = RUNNING, foo = p.url(), doctest = DOCTEST);
525+
526+
assert_that(p.cargo_process("test"),
527+
execs().with_status(0)
528+
.with_stdout(&host_output));
529+
530+
let target = host();
531+
assert_that(p.cargo_process("test").arg("--target").arg(&target),
532+
execs().with_status(0)
533+
.with_stdout(&host_output));
534+
535+
let target = alternate();
536+
assert_that(p.cargo_process("test").arg("--target").arg(&target),
537+
execs().with_status(0)
538+
.with_stdout(&format!("\
539+
{compiling} foo v0.0.0 ({foo})
540+
{running} target[..]{triple}[..]foo-[..]
541+
542+
running 0 tests
543+
544+
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
545+
546+
", compiling = COMPILING, running = RUNNING, foo = p.url(), triple = target)));
547+
});
548+
477549
test!(simple_cargo_run {
478550
if disabled() { return }
479551

0 commit comments

Comments
 (0)