-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX: Call rustdoc test with the correct cfg flags of a package. #3242
Changes from 1 commit
e100ee9
fd8274a
3f90298
665aa7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There was a situation in which if you you had a lib that depends on a package with features, whenever you ran the tests for the package the `rustdoc test` call was failing because rustdoc was called with the root cfg flags, not the package cfg flags. This fix solves the issue by keeping track of the cfg flags per package, so the rustdoc command will be generated with the correct cfg flags.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2262,3 +2262,73 @@ fn panic_abort_multiple() { | |
.arg("-p").arg("a"), | ||
execs().with_status(0)); | ||
} | ||
|
||
#[test] | ||
fn pass_correct_cfgs_flags_to_rustdoc() { | ||
let p = project("foo") | ||
.file("Cargo.toml", r#" | ||
[package] | ||
name = "foo" | ||
version = "0.1.0" | ||
authors = [] | ||
|
||
[features] | ||
default = ["a/default"] | ||
nightly = ["a/nightly"] | ||
|
||
[dependencies.a] | ||
path = "libs/a" | ||
default-features = false | ||
"#) | ||
.file("src/lib.rs", r#" | ||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn it_works() { | ||
assert!(true); | ||
} | ||
} | ||
"#) | ||
.file("libs/a/Cargo.toml", r#" | ||
[package] | ||
name = "a" | ||
version = "0.1.0" | ||
authors = [] | ||
|
||
[features] | ||
default = ["serde_codegen"] | ||
nightly = ["serde_derive"] | ||
|
||
[dependencies] | ||
serde_derive = { version = "0.8", optional = true } | ||
|
||
[build-dependencies] | ||
serde_codegen = { version = "0.8", optional = true } | ||
"#) | ||
.file("libs/a/src/lib.rs", r#" | ||
#[cfg(feature = "serde_derive")] | ||
const MSG: &'static str = "This is safe"; | ||
|
||
#[cfg(feature = "serde_codegen")] | ||
const MSG: &'static str = "This is risky"; | ||
|
||
pub fn get() -> &'static str { | ||
MSG | ||
} | ||
"#); | ||
|
||
assert_that(p.cargo_process("test") | ||
.arg("--package").arg("a") | ||
.arg("--verbose"), | ||
execs().with_status(0) | ||
.with_stderr_contains("\ | ||
[DOCTEST] a | ||
[RUNNING] `rustdoc --test [..]--cfg feature=\\\"serde_codegen\\\"[..]`")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yeah the escaping here is subtly different on Windows (different shell), so it's fine to just match the word There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @alexcrichton sounds good. I'll change it. |
||
|
||
assert_that(p.cargo_process("test") | ||
.arg("--verbose"), | ||
execs().with_status(0) | ||
.with_stderr_contains("\ | ||
[DOCTEST] foo | ||
[RUNNING] `rustdoc --test [..]--cfg feature=\\\"a\\\"[..]`")); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can call entry just once. Something like that should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TeXitoi that looks better, I'll check it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TeXitoi change done here fd8274a