Skip to content

Commit d97226c

Browse files
Add new rustdoc ui tests
1 parent 62fb7fc commit d97226c

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

src/bootstrap/check.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::collections::HashSet;
1919
use std::env;
2020
use std::fmt;
2121
use std::fs;
22+
use std::io::Read;
2223
use std::path::{PathBuf, Path};
2324
use std::process::Command;
2425

@@ -316,6 +317,76 @@ fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) {
316317
build.run(&mut cmd);
317318
}
318319

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

src/bootstrap/step.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
474474
.default(true)
475475
.host(true)
476476
.run(move |s| check::docs(build, &s.compiler()));
477+
rules.test("check-rustdoc-output", "src/test/rustdoc-test")
478+
.dep(|s| s.name("libtest"))
479+
.default(true)
480+
.host(true)
481+
.run(move |s| check::markdown_test_output_check(build, &s.compiler()));
477482
rules.test("check-distcheck", "distcheck")
478483
.dep(|s| s.name("dist-src"))
479484
.run(move |_| check::distcheck(build));

src/test/rustdoc-test/test.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// This is a Foo;
2+
///
3+
/// ```
4+
/// println!("baaaaaar");
5+
/// ```
6+
#[unstable]
7+
pub struct Foo;
8+
9+
/// This is a Bar;
10+
///
11+
/// ```
12+
/// println!("fooooo");
13+
/// ```
14+
pub struct Bar;

0 commit comments

Comments
 (0)