From fa341342538240b98ef53193770a1b30aec47ee0 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 14 Mar 2016 19:00:39 -0500 Subject: [PATCH 1/3] don't build/run doctests when target != host fixes rust-lang/rust#31907 --- src/cargo/ops/cargo_test.rs | 7 +++ tests/test_cargo_cross_compile.rs | 72 +++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index 55a9ec5f08f..d4d20fea7d7 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -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()))) diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index a2dc833e0e1..9cad506cbd6 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -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 } @@ -474,6 +489,63 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured doctest = DOCTEST))); }); +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))); +}); + test!(simple_cargo_run { if disabled() { return } From d37d38c8744037c2fc37e894ea4f2246daeeb5eb Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 15 Mar 2016 07:55:01 -0500 Subject: [PATCH 2/3] update output of cross_tests --- tests/test_cargo_cross_compile.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index 9cad506cbd6..1a81d0dc631 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -479,12 +479,6 @@ test test_foo ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured -{doctest} 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))); }); From ac46a1be90f0320c8fe98097456194942613acfb Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 15 Mar 2016 10:35:52 -0500 Subject: [PATCH 3/3] remove unused format argument --- tests/test_cargo_cross_compile.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_cargo_cross_compile.rs b/tests/test_cargo_cross_compile.rs index 1a81d0dc631..475ec0abf42 100644 --- a/tests/test_cargo_cross_compile.rs +++ b/tests/test_cargo_cross_compile.rs @@ -479,8 +479,7 @@ test test_foo ... ok test result: ok. 1 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!(no_cross_doctests {