]> git.proxmox.com Git - cargo.git/commitdiff
Disable doctests separately from tests
authorAlex Crichton <alex@alexcrichton.com>
Mon, 11 Aug 2014 04:27:17 +0000 (21:27 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 11 Aug 2014 04:28:19 +0000 (21:28 -0700)
This adds a `doctest = false` option to the `Cargo.toml` config for a target to
disable doc tests for the target. Notably `test = false` does not disable this
as it is separately toggleable.

Closes #353

src/cargo/core/manifest.rs
src/cargo/ops/cargo_test.rs
src/cargo/util/toml.rs
tests/test_cargo_test.rs

index f31d322c9ae1f38dfb919aa7b15b56b783baed2f..c733f8962cfabda15c936e1e3b98039363b5ad01 100644 (file)
@@ -109,6 +109,7 @@ pub struct Profile {
     opt_level: uint,
     debug: bool,
     test: bool,
+    doctest: bool,
     doc: bool,
     dest: Option<String>,
     plugin: bool,
@@ -124,6 +125,7 @@ impl Profile {
             doc: false,
             dest: None,
             plugin: false,
+            doctest: false,
         }
     }
 
@@ -132,10 +134,7 @@ impl Profile {
             env: "compile".to_string(), // run in the default environment only
             opt_level: 0,
             debug: true,
-            test: false, // whether or not to pass --test
-            dest: None,
-            plugin: false,
-            doc: false,
+            .. Profile::default()
         }
     }
 
@@ -189,6 +188,10 @@ impl Profile {
         self.test
     }
 
+    pub fn is_doctest(&self) -> bool {
+        self.doctest
+    }
+
     pub fn is_plugin(&self) -> bool {
         self.plugin
     }
@@ -224,6 +227,11 @@ impl Profile {
         self
     }
 
+    pub fn doctest(mut self, doctest: bool) -> Profile {
+        self.doctest = doctest;
+        self
+    }
+
     pub fn doc(mut self, doc: bool) -> Profile {
         self.doc = doc;
         self
index 695bd09c65b9b08f578473e55c2540aa87665c73..e4c9bb7d3833aa7263d93f3f914aa82c8fa1fc7d 100644 (file)
@@ -35,7 +35,7 @@ pub fn run_tests(manifest_path: &Path,
     }
 
     let mut libs = package.get_targets().iter().filter_map(|target| {
-        if !target.get_profile().is_test() || !target.is_lib() {
+        if !target.get_profile().is_doctest() || !target.is_lib() {
             return None
         }
         Some((target.get_src_path(), target.get_name()))
index d160fef2ada6a62bb4938ad9c709678d305da822..20aba7688c047fd0f58cb32e17b24742306a5018 100644 (file)
@@ -229,11 +229,8 @@ fn inferred_lib_target(name: &str, layout: &Layout) -> Vec<TomlTarget> {
     layout.lib.as_ref().map(|lib| {
         vec![TomlTarget {
             name: name.to_string(),
-            crate_type: None,
             path: Some(TomlPath(lib.clone())),
-            test: None,
-            plugin: None,
-            doc: None,
+            .. TomlTarget::new()
         }]
     }).unwrap_or(Vec::new())
 }
@@ -250,11 +247,8 @@ fn inferred_bin_targets(name: &str, layout: &Layout) -> Vec<TomlTarget> {
         name.map(|name| {
             TomlTarget {
                 name: name,
-                crate_type: None,
                 path: Some(TomlPath(bin.clone())),
-                test: None,
-                plugin: None,
-                doc: None,
+                .. TomlTarget::new()
             }
         })
     }).collect()
@@ -265,11 +259,8 @@ fn inferred_example_targets(layout: &Layout) -> Vec<TomlTarget> {
         ex.filestem_str().map(|name| {
             TomlTarget {
                 name: name.to_string(),
-                crate_type: None,
                 path: Some(TomlPath(ex.clone())),
-                test: None,
-                plugin: None,
-                doc: None,
+                .. TomlTarget::new()
             }
         })
     }).collect()
@@ -280,11 +271,8 @@ fn inferred_test_targets(layout: &Layout) -> Vec<TomlTarget> {
         ex.filestem_str().map(|name| {
             TomlTarget {
                 name: name.to_string(),
-                crate_type: None,
                 path: Some(TomlPath(ex.clone())),
-                test: None,
-                plugin: None,
-                doc: None,
+                .. TomlTarget::new()
             }
         })
     }).collect()
@@ -314,12 +302,8 @@ impl TomlManifest {
             self.lib.get_ref().iter().map(|t| {
                 if layout.lib.is_some() && t.path.is_none() {
                     TomlTarget {
-                        name: t.name.clone(),
-                        crate_type: t.crate_type.clone(),
                         path: layout.lib.as_ref().map(|p| TomlPath(p.clone())),
-                        test: t.test,
-                        plugin: t.plugin,
-                        doc: t.doc,
+                        .. t.clone()
                     }
                 } else {
                     t.clone()
@@ -335,12 +319,8 @@ impl TomlManifest {
             self.bin.get_ref().iter().map(|t| {
                 if bin.is_some() && t.path.is_none() {
                     TomlTarget {
-                        name: t.name.clone(),
-                        crate_type: t.crate_type.clone(),
                         path: bin.as_ref().map(|&p| TomlPath(p.clone())),
-                        test: t.test,
-                        plugin: None,
-                        doc: t.doc,
+                        .. t.clone()
                     }
                 } else {
                     t.clone()
@@ -462,6 +442,7 @@ struct TomlTarget {
     crate_type: Option<Vec<String>>,
     path: Option<TomlPath>,
     test: Option<bool>,
+    doctest: Option<bool>,
     doc: Option<bool>,
     plugin: Option<bool>,
 }
@@ -472,6 +453,20 @@ enum TomlPath {
     TomlPath(Path),
 }
 
+impl TomlTarget {
+    fn new() -> TomlTarget {
+        TomlTarget {
+            name: String::new(),
+            crate_type: None,
+            path: None,
+            test: None,
+            doctest: None,
+            doc: None,
+            plugin: None,
+        }
+    }
+}
+
 impl TomlPath {
     fn to_path(&self) -> Path {
         match *self {
@@ -508,8 +503,11 @@ fn normalize(libs: &[TomlLibTarget],
             Some(false) => {}
         }
 
+        let doctest = target.doctest.unwrap_or(true);
         match target.doc {
-            Some(true) | None => ret.push(Profile::default_doc()),
+            Some(true) | None => {
+                ret.push(Profile::default_doc().doctest(doctest));
+            }
             Some(false) => {}
         }
 
index 56e80719425608255a8393029244d44aa2bbd71e..2fb1b97724888131fc31d5f4ee6fc1b4dfd20cb5 100644 (file)
@@ -223,6 +223,10 @@ test!(test_with_deep_lib_dep {
 
             [dependencies.foo]
             path = "../foo"
+
+            [[lib]]
+            name = "bar"
+            doctest = false
         "#)
         .file("src/lib.rs", "
             extern crate foo;
@@ -256,16 +260,9 @@ test!(test_with_deep_lib_dep {
 running 1 test
 test bar_test ... ok
 
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measure
-
-{doctest} bar
-
-running 0 tests
-
-test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured\n\n\
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n\
                        ",
                        compiling = COMPILING, running = RUNNING,
-                       doctest = DOCTEST,
                        dir = p.url()).as_slice()));
 })
 
@@ -576,6 +573,7 @@ test!(lib_with_standard_name2 {
             [[lib]]
             name = "syntax"
             test = false
+            doctest = false
         "#)
         .file("src/lib.rs", "
             pub fn foo() {}