Create new flag to test rustdoc --test
This commit is contained in:
parent
44b59be0f2
commit
6756b72a1d
6 changed files with 55 additions and 53 deletions
2
.gitmodules
vendored
2
.gitmodules
vendored
|
@ -7,7 +7,7 @@
|
||||||
url = https://github.com/rust-lang/compiler-rt.git
|
url = https://github.com/rust-lang/compiler-rt.git
|
||||||
[submodule "src/rt/hoedown"]
|
[submodule "src/rt/hoedown"]
|
||||||
path = src/rt/hoedown
|
path = src/rt/hoedown
|
||||||
url = https://github.com/GuillaumeGomez/hoedown.git
|
url = https://github.com/rust-lang/hoedown.git
|
||||||
[submodule "src/jemalloc"]
|
[submodule "src/jemalloc"]
|
||||||
path = src/jemalloc
|
path = src/jemalloc
|
||||||
url = https://github.com/rust-lang/jemalloc.git
|
url = https://github.com/rust-lang/jemalloc.git
|
||||||
|
|
|
@ -467,7 +467,8 @@ impl Collector {
|
||||||
|
|
||||||
pub fn get_line(&self) -> usize {
|
pub fn get_line(&self) -> usize {
|
||||||
if let Some(ref codemap) = self.codemap{
|
if let Some(ref codemap) = self.codemap{
|
||||||
codemap.lookup_char_pos(BytePos(self.start_line as u32)).line - 1
|
let line = codemap.lookup_char_pos(BytePos(self.start_line as u32)).line;
|
||||||
|
if line > 0 { line - 1 } else { line }
|
||||||
} else {
|
} else {
|
||||||
self.start_line
|
self.start_line
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 78e7b6f69d3fa0cb6ae6e7fb9278c3fd167ec0d1
|
Subproject commit a3736a0a1907cbc8bf619708738815a5fd789c80
|
|
@ -9,14 +9,13 @@
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// compile-flags: --test
|
// compile-flags: --test
|
||||||
// check-stdout
|
// check-test-line-numbers-match
|
||||||
|
|
||||||
/// This is a Foo;
|
/// This is a Foo;
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// println!("baaaaaar");
|
/// println!("baaaaaar");
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable]
|
|
||||||
pub struct Foo;
|
pub struct Foo;
|
||||||
|
|
||||||
/// This is a Bar;
|
/// This is a Bar;
|
||||||
|
|
|
@ -224,6 +224,8 @@ pub struct TestProps {
|
||||||
pub incremental_dir: Option<PathBuf>,
|
pub incremental_dir: Option<PathBuf>,
|
||||||
// Specifies that a cfail test must actually compile without errors.
|
// Specifies that a cfail test must actually compile without errors.
|
||||||
pub must_compile_successfully: bool,
|
pub must_compile_successfully: bool,
|
||||||
|
// rustdoc will test the output of the `--test` option
|
||||||
|
pub check_test_line_numbers_match: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestProps {
|
impl TestProps {
|
||||||
|
@ -248,6 +250,7 @@ impl TestProps {
|
||||||
forbid_output: vec![],
|
forbid_output: vec![],
|
||||||
incremental_dir: None,
|
incremental_dir: None,
|
||||||
must_compile_successfully: false,
|
must_compile_successfully: false,
|
||||||
|
check_test_line_numbers_match: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,6 +350,10 @@ impl TestProps {
|
||||||
if !self.must_compile_successfully {
|
if !self.must_compile_successfully {
|
||||||
self.must_compile_successfully = parse_must_compile_successfully(ln);
|
self.must_compile_successfully = parse_must_compile_successfully(ln);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !self.check_test_line_numbers_match {
|
||||||
|
self.check_test_line_numbers_match = parse_check_test_line_numbers_match(ln);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
|
for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
|
||||||
|
@ -458,6 +465,10 @@ fn parse_must_compile_successfully(line: &str) -> bool {
|
||||||
parse_name_directive(line, "must-compile-successfully")
|
parse_name_directive(line, "must-compile-successfully")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_check_test_line_numbers_match(line: &str) -> bool {
|
||||||
|
parse_name_directive(line, "check-test-line-numbers-match")
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_env(line: &str, name: &str) -> Option<(String, String)> {
|
fn parse_env(line: &str, name: &str) -> Option<(String, String)> {
|
||||||
parse_name_value_directive(line, name).map(|nv| {
|
parse_name_value_directive(line, name).map(|nv| {
|
||||||
// nv is either FOO or FOO=BAR
|
// nv is either FOO or FOO=BAR
|
||||||
|
|
|
@ -1879,10 +1879,6 @@ actual:\n\
|
||||||
fn run_rustdoc_test(&self) {
|
fn run_rustdoc_test(&self) {
|
||||||
assert!(self.revision.is_none(), "revisions not relevant here");
|
assert!(self.revision.is_none(), "revisions not relevant here");
|
||||||
|
|
||||||
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 out_dir = self.output_base_name();
|
||||||
let _ = fs::remove_dir_all(&out_dir);
|
let _ = fs::remove_dir_all(&out_dir);
|
||||||
self.create_dir_racy(&out_dir);
|
self.create_dir_racy(&out_dir);
|
||||||
|
@ -1891,8 +1887,11 @@ actual:\n\
|
||||||
if !proc_res.status.success() {
|
if !proc_res.status.success() {
|
||||||
self.fatal_proc_rec("rustdoc failed!", &proc_res);
|
self.fatal_proc_rec("rustdoc failed!", &proc_res);
|
||||||
}
|
}
|
||||||
let root = self.find_rust_src_root().unwrap();
|
|
||||||
|
|
||||||
|
if self.props.check_test_line_numbers_match == true {
|
||||||
|
self.check_rustdoc_test_option(proc_res);
|
||||||
|
} else {
|
||||||
|
let root = self.find_rust_src_root().unwrap();
|
||||||
let res = self.cmd2procres(Command::new(&self.config.docck_python)
|
let res = self.cmd2procres(Command::new(&self.config.docck_python)
|
||||||
.arg(root.join("src/etc/htmldocck.py"))
|
.arg(root.join("src/etc/htmldocck.py"))
|
||||||
.arg(out_dir)
|
.arg(out_dir)
|
||||||
|
@ -1903,7 +1902,7 @@ actual:\n\
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_rustdoc_test_option(&self) {
|
fn check_rustdoc_test_option(&self, res: ProcRes) {
|
||||||
let mut file = fs::File::open(&self.testpaths.file)
|
let mut file = fs::File::open(&self.testpaths.file)
|
||||||
.expect("markdown_test_output_check_entry File::open failed");
|
.expect("markdown_test_output_check_entry File::open failed");
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
|
@ -1911,13 +1910,12 @@ actual:\n\
|
||||||
.expect("markdown_test_output_check_entry read_to_string failed");
|
.expect("markdown_test_output_check_entry read_to_string failed");
|
||||||
let mut ignore = false;
|
let mut ignore = false;
|
||||||
let mut v: Vec<usize> =
|
let mut v: Vec<usize> =
|
||||||
content.split("\n")
|
content.lines()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter_map(|(line_nb, line)| {
|
.filter_map(|(line_nb, line)| {
|
||||||
let sline = line.split("///").last().unwrap_or("");
|
let sline = line.split("///").last().unwrap_or("");
|
||||||
let line = sline.trim_left();
|
let line = sline.trim_left();
|
||||||
if line.starts_with("```") &&
|
if line.starts_with("```") {
|
||||||
!line.contains("ignore") {
|
|
||||||
if ignore {
|
if ignore {
|
||||||
ignore = false;
|
ignore = false;
|
||||||
None
|
None
|
||||||
|
@ -1931,37 +1929,30 @@ actual:\n\
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let args = ProcArgs {
|
let mut tested = 0;
|
||||||
prog: self.config.rustdoc_path.to_str().unwrap().to_owned(),
|
for _ in res.stdout.split("\n")
|
||||||
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 "))
|
.filter(|s| s.starts_with("test "))
|
||||||
.inspect(|s| {
|
.inspect(|s| {
|
||||||
let tmp: Vec<&str> = s.split(" - line ").collect();
|
let tmp: Vec<&str> = s.split(" - line ").collect();
|
||||||
if tmp.len() == 2 {
|
if tmp.len() == 2 {
|
||||||
let line = usize::from_str_radix(tmp[1].split(" ...")
|
tested += 1;
|
||||||
|
let line = tmp[1].split(" ...")
|
||||||
.next()
|
.next()
|
||||||
.unwrap_or("0"), 10)
|
.unwrap_or("0")
|
||||||
|
.parse()
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
if let Ok(pos) = v.binary_search(&line) {
|
if let Ok(pos) = v.binary_search(&line) {
|
||||||
v.remove(pos);
|
v.remove(pos);
|
||||||
} else {
|
} else {
|
||||||
self.fatal_proc_rec(&format!("Not found doc test: \"{}\" in {:?}",
|
self.fatal_proc_rec(
|
||||||
s, v),
|
&format!("Not found doc test: \"{}\" in {:?}", s, v),
|
||||||
&res);
|
&res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}) {}
|
||||||
.all(|_| true);
|
if tested == 0 {
|
||||||
if v.len() != 0 {
|
self.fatal_proc_rec("No test has been found", &res);
|
||||||
|
} else if v.len() != 0 {
|
||||||
self.fatal_proc_rec(&format!("Not found test at line{} {:?}",
|
self.fatal_proc_rec(&format!("Not found test at line{} {:?}",
|
||||||
if v.len() > 1 { "s" } else { "" }, v),
|
if v.len() > 1 { "s" } else { "" }, v),
|
||||||
&res);
|
&res);
|
||||||
|
|
Loading…
Add table
Reference in a new issue