]> git.lizzy.rs Git - rust.git/commitdiff
Move test from bootstrap to compiletest
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Fri, 20 Jan 2017 22:24:20 +0000 (23:24 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Fri, 3 Feb 2017 10:08:20 +0000 (11:08 +0100)
src/bootstrap/check.rs
src/test/rustdoc-test/test.rs [deleted file]
src/test/rustdoc/test_option_check/test.rs [new file with mode: 0644]
src/tools/compiletest/src/runtest.rs

index f8c31d733719172cd785e6572d4d2e971d9253b3..19aac0f36bb27e59c2a035d7ccca2d9453c48dc9 100644 (file)
@@ -19,7 +19,6 @@
 use std::env;
 use std::fmt;
 use std::fs;
-use std::io::Read;
 use std::path::{PathBuf, Path};
 use std::process::Command;
 
@@ -275,7 +274,6 @@ pub fn docs(build: &Build, compiler: &Compiler) {
         println!("doc tests for: {}", p.display());
         markdown_test(build, compiler, &p);
     }
-    markdown_test(build, compiler, &output);
 }
 
 /// Run the error index generator tool to execute the tests located in the error
@@ -297,6 +295,8 @@ pub fn error_index(build: &Build, compiler: &Compiler) {
                    .arg("markdown")
                    .arg(&output)
                    .env("CFG_BUILD", &build.config.build));
+
+    markdown_test(build, compiler, &output);
 }
 
 fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) {
@@ -316,76 +316,6 @@ fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) {
     build.run(&mut cmd);
 }
 
-pub fn markdown_test_output_check(build: &Build, compiler: &Compiler) {
-    let _time = util::timeit();
-    for entry in fs::read_dir("src/test/rustdoc-test")
-                    .expect("markdown_test_output_check: read_dir failed") {
-        if let Ok(entry) = entry {
-            if entry.path().extension().and_then(|s| s.to_str()) != Some("rs") {
-                continue
-            }
-            markdown_test_output_check_entry(build, compiler, entry.path().as_path());
-        }
-    }
-}
-
-fn markdown_test_output_check_entry(build: &Build, compiler: &Compiler, path: &Path) {
-    let mut file = fs::File::open(path)
-                            .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 mut cmd = Command::new(build.rustdoc(compiler));
-    build.add_rustc_lib_path(compiler, &mut cmd);
-    build.add_rust_test_threads(&mut cmd);
-    cmd.arg("--test");
-    cmd.arg(path);
-    cmd.env("RUSTC_BOOTSTRAP", "1");
-
-    cmd.arg("--test-args").arg(build.flags.cmd.test_args().join(" "));
-
-    output(&mut cmd).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 {
-                                panic!("Not found doc test: \"{}\" in {:?}", s, v);
-                            }
-                        }
-                    }).all(|_| true);
-    if v.len() != 0 {
-        panic!("Not found test at line{} {:?}", if v.len() > 1 { "s" } else { "" }, v);
-    }
-}
-
 /// Run all unit tests plus documentation tests for an entire crate DAG defined
 /// by a `Cargo.toml`
 ///
diff --git a/src/test/rustdoc-test/test.rs b/src/test/rustdoc-test/test.rs
deleted file mode 100644 (file)
index 96a4a35..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-/// This is a Foo;
-///
-/// ```
-/// println!("baaaaaar");
-/// ```
-#[unstable]
-pub struct Foo;
-
-/// This is a Bar;
-///
-/// ```
-/// println!("fooooo");
-/// ```
-pub struct Bar;
diff --git a/src/test/rustdoc/test_option_check/test.rs b/src/test/rustdoc/test_option_check/test.rs
new file mode 100644 (file)
index 0000000..772d258
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags:--test
+// check-stdout
+
+/// This is a Foo;
+///
+/// ```
+/// println!("baaaaaar");
+/// ```
+#[unstable]
+pub struct Foo;
+
+/// This is a Bar;
+///
+/// ```
+/// println!("fooooo");
+/// ```
+pub struct Bar;
index 86fa5e70c9c28322f11d651af32f51408ae82028..11c43b7150f9d4628ecaaee42e42912292cd3650 100644 (file)
@@ -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 @@ fn charset() -> &'static str {
     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);
         }
     }