]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: Use --crate-name with --test
authorAlex Crichton <alex@alexcrichton.com>
Fri, 1 Aug 2014 03:14:59 +0000 (20:14 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 1 Aug 2014 06:01:24 +0000 (23:01 -0700)
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.

src/librustdoc/lib.rs
src/librustdoc/test.rs

index a89b76572875efba87edec77401683653a17b175..ddd06e427d7dfbff71c00997bb75a7d376a45f9e 100644 (file)
@@ -214,13 +214,14 @@ pub fn main_args(args: &[String]) -> int {
         Some(eh) => eh,
         None => return 3
     };
+    let crate_name = matches.opt_str("crate-name");
 
     match (should_test, markdown_input) {
         (true, true) => {
             return markdown::test(input, libs, externs, test_args)
         }
         (true, false) => {
-            return test::run(input, cfgs, libs, externs, test_args)
+            return test::run(input, cfgs, libs, externs, test_args, crate_name)
         }
         (false, true) => return markdown::render(input, output.unwrap_or(Path::new("doc")),
                                                  &matches, &external_html,
index aef6af1677ab0d67b2f32c1eb0cb9ea96b370e37..9df748e74e8baf9d1920f0e99db7b4625cb3f3fd 100644 (file)
@@ -41,7 +41,8 @@ pub fn run(input: &str,
            cfgs: Vec<String>,
            libs: HashSet<Path>,
            externs: core::Externs,
-           mut test_args: Vec<String>)
+           mut test_args: Vec<String>,
+           crate_name: Option<String>)
            -> int {
     let input_path = Path::new(input);
     let input = driver::FileInput(input_path.clone());
@@ -87,7 +88,11 @@ 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();
+    match crate_name {
+        Some(name) => krate.name = name,
+        None => {}
+    }
     let (krate, _) = passes::collapse_docs(krate);
     let (krate, _) = passes::unindent_comments(krate);