-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
rustdoc: Use --crate-name with --test #16157
Conversation
@@ -87,7 +88,8 @@ pub fn run(input: &str, | |||
|
|||
let mut v = RustdocVisitor::new(&*ctx, None); | |||
v.visit(&ctx.krate); | |||
let krate = v.clean(); | |||
let mut krate = v.clean(); | |||
krate.name = crate_name.unwrap_or(krate.name.clone()); |
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.
This just seems weird. I'd rather see something like
if crate_name.is_some() { krate.name = crate_name.unwrap(); }
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.
Or match crate_name { Some(n) => krate.name = n, None => {} }
or for n in crate_name.move_iter() { krate.name = n }
or crate_name.map(|n| krate.name = n)
.
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.
I considered suggesting the match
, but I figured a multi-line solution like that would not be as desired.
If we had rust-lang/rfcs#160 this would be a good candidate for if let
:
if let Some(crate_name) = crate_name { krate.name = crate_name; }
This ensures that the name of the crate is set from the command line for tests so the auto-injection of `extern crate <name>` in doc tests works correctly.
Updated with a |
This ensures that the name of the crate is set from the command line for tests so the auto-injection of `extern crate <name>` in doc tests works correctly.
Whenever `cargo test` is run and a testable library target is available, the doc tests will be run. This can be opted out of with `test = false` as usual. This is currently not super useful due to rust-lang/rust#16157, but I expect that to be merged soon. In the meantime examples will need to `extern crate foo` explicitly.
Whenever `cargo test` is run and a testable library target is available, the doc tests will be run. This can be opted out of with `test = false` as usual. This is currently not super useful due to rust-lang/rust#16157, but I expect that to be merged soon. In the meantime examples will need to `extern crate foo` explicitly. Closes #334
Whenever `cargo test` is run and a testable library target is available, the doc tests will be run. This can be opted out of with `test = false` as usual. This is currently not super useful due to rust-lang/rust#16157, but I expect that to be merged soon. In the meantime examples will need to `extern crate foo` explicitly.
Whenever `cargo test` is run and a testable library target is available, the doc tests will be run. This can be opted out of with `test = false` as usual. This is currently not super useful due to rust-lang/rust#16157, but I expect that to be merged soon. In the meantime examples will need to `extern crate foo` explicitly. Closes rust-lang#334
This ensures that the name of the crate is set from the command line for tests
so the auto-injection of
extern crate <name>
in doc tests works correctly.