use std::env;
use std::fmt;
use std::fs;
-use std::io::Read;
use std::path::{PathBuf, Path};
use std::process::Command;
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
.arg("markdown")
.arg(&output)
.env("CFG_BUILD", &build.config.build));
+
+ markdown_test(build, compiler, &output);
}
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`
///
}
_ => {
- // 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");
}
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);
}
}