Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ fn run_doc_tests(options: &TestOptions,
-> CargoResult<(Test, Vec<ProcessError>)> {
let mut errors = Vec::new();
let config = options.compile_opts.config;
let host_deps = find_host_deps(options, compilation);

// We don't build/rust doctests if target != host
if config.rustc()?.host != compilation.target {
Expand All @@ -144,6 +145,8 @@ fn run_doc_tests(options: &TestOptions,
p.arg("--test").arg(lib)
.arg("--crate-name").arg(&crate_name);

p.arg("-L").arg(&host_deps);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It occurred to me that this line may need to be further down to put the host directory after the others? Does the ordering of the -L options mean this is buggy despite passing tests?


for &rust_dep in &[&compilation.deps_output] {
let mut arg = OsString::from("dependency=");
arg.push(rust_dep);
Expand Down Expand Up @@ -198,3 +201,24 @@ fn run_doc_tests(options: &TestOptions,
}
Ok((Test::Doc, errors))
}

fn find_host_deps(options: &TestOptions, compilation: &Compilation) -> OsString {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of being calculated here, could this perhaps be a field of the Compilation returned?

let build_type = if options.compile_opts.release { "release" } else { "debug" };
let mut dir = compilation.root_output.clone();

// first pop off the build_type
dir.pop();
// if we see the target next, pop it off
let target: &OsStr = compilation.target.as_ref();
if dir.file_name().unwrap() == target {
dir.pop();
}
// push the build_type back on
dir.push(build_type);
// and we are looking for the deps directory
dir.push("deps");

let mut host_deps = OsString::from("dependency=");
host_deps.push(dir);
host_deps
}
52 changes: 51 additions & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fs::File;
use std::io::prelude::*;
use std::str;

use cargotest::{sleep_ms, is_nightly};
use cargotest::{sleep_ms, is_nightly, rustc_host};
use cargotest::support::{project, execs, basic_bin_manifest, basic_lib_manifest, cargo_exe};
use cargotest::support::paths::CargoPathExt;
use cargotest::support::registry::Package;
Expand Down Expand Up @@ -2782,3 +2782,53 @@ fn publish_a_crate_without_tests() {
assert_that(p.cargo("test").arg("--package").arg("testless"),
execs().with_status(0));
}

#[test]
fn find_dependency_of_proc_macro_dependency_with_target() {
let workspace = project("workspace")
.file("Cargo.toml", r#"
[workspace]
members = ["root", "proc_macro_dep"]
"#)
.file("root/Cargo.toml", r#"
[project]
name = "root"
version = "0.1.0"
authors = []

[dependencies]
proc_macro_dep = { path = "../proc_macro_dep" }
"#)
.file("root/src/lib.rs", r#"
#[macro_use]
extern crate proc_macro_dep;

#[derive(Noop)]
pub struct X;
"#)
.file("proc_macro_dep/Cargo.toml", r#"
[project]
name = "proc_macro_dep"
version = "0.1.0"
authors = []

[lib]
proc-macro = true

[dependencies]
base64 = "^0.6"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throughout a number of other tests you'll see calls to Package::new(..).publish() which allow having a "fake registry" during testing without actually pulling in a dependency from crates.io, perhaps that can be used here instead?

"#)
.file("proc_macro_dep/src/lib.rs", r#"
extern crate base64;
extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_derive(Noop)]
pub fn noop(_input: TokenStream) -> TokenStream {
"".parse().unwrap()
}
"#);
workspace.build();
assert_that(workspace.cargo("test").arg("--all").arg("--target").arg(rustc_host()),
execs().with_status(0));
}