Skip to content

Commit 892f17d

Browse files
committed
Auto merge of #2485 - japaric:no-cross-doctests, r=alexcrichton
don't build/run doctests when target != host fixes rust-lang/rust#31907 r? @alexcrichton
2 parents 61b4578 + d37d38c commit 892f17d

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
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: 68 additions & 2 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

@@ -464,14 +479,65 @@ test test_foo ... ok
464479
465480
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
466481
482+
", compiling = COMPILING, running = RUNNING, foo = p.url(), triple = target,
483+
doctest = DOCTEST)));
484+
});
485+
486+
test!(no_cross_doctests {
487+
if disabled() { return }
488+
489+
let p = project("foo")
490+
.file("Cargo.toml", r#"
491+
[project]
492+
name = "foo"
493+
authors = []
494+
version = "0.0.0"
495+
"#)
496+
.file("src/lib.rs", r#"
497+
//! ```
498+
//! extern crate foo;
499+
//! assert!(true);
500+
//! ```
501+
"#);
502+
503+
let host_output = format!("\
504+
{compiling} foo v0.0.0 ({foo})
505+
{running} target[..]foo-[..]
506+
507+
running 0 tests
508+
509+
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
510+
467511
{doctest} foo
468512
513+
running 1 test
514+
test _0 ... ok
515+
516+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
517+
518+
", compiling = COMPILING, running = RUNNING, foo = p.url(), doctest = DOCTEST);
519+
520+
assert_that(p.cargo_process("test"),
521+
execs().with_status(0)
522+
.with_stdout(&host_output));
523+
524+
let target = host();
525+
assert_that(p.cargo_process("test").arg("--target").arg(&target),
526+
execs().with_status(0)
527+
.with_stdout(&host_output));
528+
529+
let target = alternate();
530+
assert_that(p.cargo_process("test").arg("--target").arg(&target),
531+
execs().with_status(0)
532+
.with_stdout(&format!("\
533+
{compiling} foo v0.0.0 ({foo})
534+
{running} target[..]{triple}[..]foo-[..]
535+
469536
running 0 tests
470537
471538
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
472539
473-
", compiling = COMPILING, running = RUNNING, foo = p.url(), triple = target,
474-
doctest = DOCTEST)));
540+
", compiling = COMPILING, running = RUNNING, foo = p.url(), triple = target)));
475541
});
476542

477543
test!(simple_cargo_run {

0 commit comments

Comments
 (0)