Skip to content

Commit 6248858

Browse files
committed
auto merge of rust-lang#16157 : alexcrichton/rust/rustdoc-tests, r=huonw
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.
2 parents 51ff6c0 + 4dbe3eb commit 6248858

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/librustdoc/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,14 @@ pub fn main_args(args: &[String]) -> int {
214214
Some(eh) => eh,
215215
None => return 3
216216
};
217+
let crate_name = matches.opt_str("crate-name");
217218

218219
match (should_test, markdown_input) {
219220
(true, true) => {
220221
return markdown::test(input, libs, externs, test_args)
221222
}
222223
(true, false) => {
223-
return test::run(input, cfgs, libs, externs, test_args)
224+
return test::run(input, cfgs, libs, externs, test_args, crate_name)
224225
}
225226
(false, true) => return markdown::render(input, output.unwrap_or(Path::new("doc")),
226227
&matches, &external_html,

src/librustdoc/test.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ pub fn run(input: &str,
4141
cfgs: Vec<String>,
4242
libs: HashSet<Path>,
4343
externs: core::Externs,
44-
mut test_args: Vec<String>)
44+
mut test_args: Vec<String>,
45+
crate_name: Option<String>)
4546
-> int {
4647
let input_path = Path::new(input);
4748
let input = driver::FileInput(input_path.clone());
@@ -87,7 +88,11 @@ pub fn run(input: &str,
8788

8889
let mut v = RustdocVisitor::new(&*ctx, None);
8990
v.visit(&ctx.krate);
90-
let krate = v.clean();
91+
let mut krate = v.clean();
92+
match crate_name {
93+
Some(name) => krate.name = name,
94+
None => {}
95+
}
9196
let (krate, _) = passes::collapse_docs(krate);
9297
let (krate, _) = passes::unindent_comments(krate);
9398

0 commit comments

Comments
 (0)