From 44b59be0f2ad38c39b67a6c8ebfe826c4c30cbd9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 20 Jan 2017 23:24:20 +0100 Subject: [PATCH] Move test from bootstrap to compiletest --- src/bootstrap/check.rs | 74 +--------------- src/test/rustdoc-test/test.rs | 14 ---- src/test/rustdoc/test_option_check/test.rs | 27 ++++++ src/tools/compiletest/src/runtest.rs | 98 ++++++++++++++++++---- 4 files changed, 113 insertions(+), 100 deletions(-) delete mode 100644 src/test/rustdoc-test/test.rs create mode 100644 src/test/rustdoc/test_option_check/test.rs diff --git a/src/bootstrap/check.rs b/src/bootstrap/check.rs index f8c31d733719..19aac0f36bb2 100644 --- a/src/bootstrap/check.rs +++ b/src/bootstrap/check.rs @@ -19,7 +19,6 @@ use std::collections::HashSet; 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 = - 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 index 96a4a35282be..000000000000 --- a/src/test/rustdoc-test/test.rs +++ /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 index 000000000000..772d258bc800 --- /dev/null +++ b/src/test/rustdoc/test_option_check/test.rs @@ -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 or the MIT license +// , 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; diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 86fa5e70c9c2..11c43b7150f9 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(); + } - 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); + 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 = + 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 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); } }