Skip to content

Commit 44b59be

Browse files
Move test from bootstrap to compiletest
1 parent aea6f32 commit 44b59be

File tree

4 files changed

+113
-100
lines changed

4 files changed

+113
-100
lines changed

src/bootstrap/check.rs

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use std::collections::HashSet;
1919
use std::env;
2020
use std::fmt;
2121
use std::fs;
22-
use std::io::Read;
2322
use std::path::{PathBuf, Path};
2423
use std::process::Command;
2524

@@ -275,7 +274,6 @@ pub fn docs(build: &Build, compiler: &Compiler) {
275274
println!("doc tests for: {}", p.display());
276275
markdown_test(build, compiler, &p);
277276
}
278-
markdown_test(build, compiler, &output);
279277
}
280278

281279
/// 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) {
297295
.arg("markdown")
298296
.arg(&output)
299297
.env("CFG_BUILD", &build.config.build));
298+
299+
markdown_test(build, compiler, &output);
300300
}
301301

302302
fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) {
@@ -316,76 +316,6 @@ fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) {
316316
build.run(&mut cmd);
317317
}
318318

319-
pub fn markdown_test_output_check(build: &Build, compiler: &Compiler) {
320-
let _time = util::timeit();
321-
for entry in fs::read_dir("src/test/rustdoc-test")
322-
.expect("markdown_test_output_check: read_dir failed") {
323-
if let Ok(entry) = entry {
324-
if entry.path().extension().and_then(|s| s.to_str()) != Some("rs") {
325-
continue
326-
}
327-
markdown_test_output_check_entry(build, compiler, entry.path().as_path());
328-
}
329-
}
330-
}
331-
332-
fn markdown_test_output_check_entry(build: &Build, compiler: &Compiler, path: &Path) {
333-
let mut file = fs::File::open(path)
334-
.expect("markdown_test_output_check_entry File::open failed");
335-
let mut content = String::new();
336-
file.read_to_string(&mut content)
337-
.expect("markdown_test_output_check_entry read_to_string failed");
338-
let mut ignore = false;
339-
let mut v: Vec<usize> =
340-
content.split("\n")
341-
.enumerate()
342-
.filter_map(|(line_nb, line)| {
343-
let sline = line.split("///").last().unwrap_or("");
344-
let line = sline.trim_left();
345-
if line.starts_with("```") &&
346-
!line.contains("ignore") {
347-
if ignore {
348-
ignore = false;
349-
None
350-
} else {
351-
ignore = true;
352-
Some(line_nb + 1)
353-
}
354-
} else {
355-
None
356-
}
357-
})
358-
.collect();
359-
let mut cmd = Command::new(build.rustdoc(compiler));
360-
build.add_rustc_lib_path(compiler, &mut cmd);
361-
build.add_rust_test_threads(&mut cmd);
362-
cmd.arg("--test");
363-
cmd.arg(path);
364-
cmd.env("RUSTC_BOOTSTRAP", "1");
365-
366-
cmd.arg("--test-args").arg(build.flags.cmd.test_args().join(" "));
367-
368-
output(&mut cmd).split("\n")
369-
.filter(|s| s.starts_with("test "))
370-
.inspect(|s| {
371-
let tmp: Vec<&str> = s.split(" - line ").collect();
372-
if tmp.len() == 2 {
373-
let line = usize::from_str_radix(tmp[1].split(" ...")
374-
.next()
375-
.unwrap_or("0"), 10)
376-
.unwrap_or(0);
377-
if let Ok(pos) = v.binary_search(&line) {
378-
v.remove(pos);
379-
} else {
380-
panic!("Not found doc test: \"{}\" in {:?}", s, v);
381-
}
382-
}
383-
}).all(|_| true);
384-
if v.len() != 0 {
385-
panic!("Not found test at line{} {:?}", if v.len() > 1 { "s" } else { "" }, v);
386-
}
387-
}
388-
389319
/// Run all unit tests plus documentation tests for an entire crate DAG defined
390320
/// by a `Cargo.toml`
391321
///

src/test/rustdoc-test/test.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:--test
12+
// check-stdout
13+
14+
/// This is a Foo;
15+
///
16+
/// ```
17+
/// println!("baaaaaar");
18+
/// ```
19+
#[unstable]
20+
pub struct Foo;
21+
22+
/// This is a Bar;
23+
///
24+
/// ```
25+
/// println!("fooooo");
26+
/// ```
27+
pub struct Bar;

src/tools/compiletest/src/runtest.rs

Lines changed: 84 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn run(config: Config, testpaths: &TestPaths) {
4343
}
4444

4545
_ => {
46-
// android has it's own gdb handling
46+
// android has its own gdb handling
4747
if config.mode == DebugInfoGdb && config.gdb.is_none() {
4848
panic!("gdb not available but debuginfo gdb debuginfo test requested");
4949
}
@@ -1879,22 +1879,92 @@ actual:\n\
18791879
fn run_rustdoc_test(&self) {
18801880
assert!(self.revision.is_none(), "revisions not relevant here");
18811881

1882-
let out_dir = self.output_base_name();
1883-
let _ = fs::remove_dir_all(&out_dir);
1884-
self.create_dir_racy(&out_dir);
1882+
if self.props.compile_flags.contains(&"--test".to_owned()) &&
1883+
self.props.check_stdout == true {
1884+
self.check_rustdoc_test_option();
1885+
} else {
1886+
let out_dir = self.output_base_name();
1887+
let _ = fs::remove_dir_all(&out_dir);
1888+
self.create_dir_racy(&out_dir);
18851889

1886-
let proc_res = self.document(&out_dir);
1887-
if !proc_res.status.success() {
1888-
self.fatal_proc_rec("rustdoc failed!", &proc_res);
1890+
let proc_res = self.document(&out_dir);
1891+
if !proc_res.status.success() {
1892+
self.fatal_proc_rec("rustdoc failed!", &proc_res);
1893+
}
1894+
let root = self.find_rust_src_root().unwrap();
1895+
1896+
let res = self.cmd2procres(Command::new(&self.config.docck_python)
1897+
.arg(root.join("src/etc/htmldocck.py"))
1898+
.arg(out_dir)
1899+
.arg(&self.testpaths.file));
1900+
if !res.status.success() {
1901+
self.fatal_proc_rec("htmldocck failed!", &res);
1902+
}
18891903
}
1890-
let root = self.find_rust_src_root().unwrap();
1904+
}
1905+
1906+
fn check_rustdoc_test_option(&self) {
1907+
let mut file = fs::File::open(&self.testpaths.file)
1908+
.expect("markdown_test_output_check_entry File::open failed");
1909+
let mut content = String::new();
1910+
file.read_to_string(&mut content)
1911+
.expect("markdown_test_output_check_entry read_to_string failed");
1912+
let mut ignore = false;
1913+
let mut v: Vec<usize> =
1914+
content.split("\n")
1915+
.enumerate()
1916+
.filter_map(|(line_nb, line)| {
1917+
let sline = line.split("///").last().unwrap_or("");
1918+
let line = sline.trim_left();
1919+
if line.starts_with("```") &&
1920+
!line.contains("ignore") {
1921+
if ignore {
1922+
ignore = false;
1923+
None
1924+
} else {
1925+
ignore = true;
1926+
Some(line_nb + 1)
1927+
}
1928+
} else {
1929+
None
1930+
}
1931+
})
1932+
.collect();
18911933

1892-
let res = self.cmd2procres(Command::new(&self.config.docck_python)
1893-
.arg(root.join("src/etc/htmldocck.py"))
1894-
.arg(out_dir)
1895-
.arg(&self.testpaths.file));
1896-
if !res.status.success() {
1897-
self.fatal_proc_rec("htmldocck failed!", &res);
1934+
let args = ProcArgs {
1935+
prog: self.config.rustdoc_path.to_str().unwrap().to_owned(),
1936+
args: vec!["--test".to_owned(), self.testpaths.file.to_str().unwrap().to_owned()],
1937+
};
1938+
let env = self.props.exec_env.clone();
1939+
let res = self.compose_and_run(args,
1940+
env,
1941+
self.config.run_lib_path.to_str().unwrap(),
1942+
None,
1943+
None);
1944+
1945+
res.stdout.split("\n")
1946+
.filter(|s| s.starts_with("test "))
1947+
.inspect(|s| {
1948+
let tmp: Vec<&str> = s.split(" - line ").collect();
1949+
if tmp.len() == 2 {
1950+
let line = usize::from_str_radix(tmp[1].split(" ...")
1951+
.next()
1952+
.unwrap_or("0"), 10)
1953+
.unwrap_or(0);
1954+
if let Ok(pos) = v.binary_search(&line) {
1955+
v.remove(pos);
1956+
} else {
1957+
self.fatal_proc_rec(&format!("Not found doc test: \"{}\" in {:?}",
1958+
s, v),
1959+
&res);
1960+
}
1961+
}
1962+
})
1963+
.all(|_| true);
1964+
if v.len() != 0 {
1965+
self.fatal_proc_rec(&format!("Not found test at line{} {:?}",
1966+
if v.len() > 1 { "s" } else { "" }, v),
1967+
&res);
18981968
}
18991969
}
19001970

0 commit comments

Comments
 (0)