about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2017-01-20 23:24:20 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2017-02-03 11:08:20 +0100
commit44b59be0f2ad38c39b67a6c8ebfe826c4c30cbd9 (patch)
tree76e8ef2503c5668fd861952d42ed58baafc4a762 /src/tools
parentaea6f3234af12f0a7c098c2a80803061aba76608 (diff)
downloadrust-44b59be0f2ad38c39b67a6c8ebfe826c4c30cbd9.tar.gz
rust-44b59be0f2ad38c39b67a6c8ebfe826c4c30cbd9.zip
Move test from bootstrap to compiletest
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/compiletest/src/runtest.rs98
1 files changed, 84 insertions, 14 deletions
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index 86fa5e70c9c..11c43b7150f 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -43,7 +43,7 @@ pub fn run(config: Config, testpaths: &TestPaths) {
         }
 
         _ => {
-            // android has it's own gdb handling
+            // android has its own gdb handling
             if config.mode == DebugInfoGdb && config.gdb.is_none() {
                 panic!("gdb not available but debuginfo gdb debuginfo test requested");
             }
@@ -1879,22 +1879,92 @@ actual:\n\
     fn run_rustdoc_test(&self) {
         assert!(self.revision.is_none(), "revisions not relevant here");
 
-        let out_dir = self.output_base_name();
-        let _ = fs::remove_dir_all(&out_dir);
-        self.create_dir_racy(&out_dir);
+        if self.props.compile_flags.contains(&"--test".to_owned()) &&
+           self.props.check_stdout == true {
+            self.check_rustdoc_test_option();
+        } else {
+            let out_dir = self.output_base_name();
+            let _ = fs::remove_dir_all(&out_dir);
+            self.create_dir_racy(&out_dir);
 
-        let proc_res = self.document(&out_dir);
-        if !proc_res.status.success() {
-            self.fatal_proc_rec("rustdoc failed!", &proc_res);
+            let proc_res = self.document(&out_dir);
+            if !proc_res.status.success() {
+                self.fatal_proc_rec("rustdoc failed!", &proc_res);
+            }
+            let root = self.find_rust_src_root().unwrap();
+
+            let res = self.cmd2procres(Command::new(&self.config.docck_python)
+                                       .arg(root.join("src/etc/htmldocck.py"))
+                                       .arg(out_dir)
+                                       .arg(&self.testpaths.file));
+            if !res.status.success() {
+                self.fatal_proc_rec("htmldocck failed!", &res);
+            }
         }
-        let root = self.find_rust_src_root().unwrap();
+    }
+
+    fn check_rustdoc_test_option(&self) {
+        let mut file = fs::File::open(&self.testpaths.file)
+                                .expect("markdown_test_output_check_entry File::open failed");
+        let mut content = String::new();
+        file.read_to_string(&mut content)
+            .expect("markdown_test_output_check_entry read_to_string failed");
+        let mut ignore = false;
+        let mut v: Vec<usize> =
+            content.split("\n")
+                   .enumerate()
+                   .filter_map(|(line_nb, line)| {
+                       let sline = line.split("///").last().unwrap_or("");
+                       let line = sline.trim_left();
+                       if line.starts_with("```") &&
+                          !line.contains("ignore") {
+                           if ignore {
+                               ignore = false;
+                               None
+                           } else {
+                               ignore = true;
+                               Some(line_nb + 1)
+                           }
+                       } else {
+                           None
+                       }
+                   })
+                   .collect();
 
-        let res = self.cmd2procres(Command::new(&self.config.docck_python)
-                                   .arg(root.join("src/etc/htmldocck.py"))
-                                   .arg(out_dir)
-                                   .arg(&self.testpaths.file));
-        if !res.status.success() {
-            self.fatal_proc_rec("htmldocck failed!", &res);
+        let args = ProcArgs {
+            prog: self.config.rustdoc_path.to_str().unwrap().to_owned(),
+            args: vec!["--test".to_owned(), self.testpaths.file.to_str().unwrap().to_owned()],
+        };
+        let env = self.props.exec_env.clone();
+        let res = self.compose_and_run(args,
+                                       env,
+                                       self.config.run_lib_path.to_str().unwrap(),
+                                       None,
+                                       None);
+
+        res.stdout.split("\n")
+                  .filter(|s| s.starts_with("test "))
+                  .inspect(|s| {
+                      let tmp: Vec<&str> = s.split(" - line ").collect();
+                      if tmp.len() == 2 {
+                          let line = usize::from_str_radix(tmp[1].split(" ...")
+                                                                 .next()
+                                                                 .unwrap_or("0"), 10)
+                                         .unwrap_or(0);
+                          if let Ok(pos) = v.binary_search(&line) {
+                              v.remove(pos);
+                          } else {
+                              self.fatal_proc_rec(&format!("Not found doc test: \"{}\" in {:?}",
+                                                           s, v),
+                                                  &res);
+                          }
+                      }
+                  })
+                  .all(|_| true);
+        if v.len() != 0 {
+            self.fatal_proc_rec(&format!("Not found test at line{} {:?}",
+                                         if v.len() > 1 { "s" } else { "" }, v),
+                                &res);
         }
     }