Skip to content

Commit e1293ec

Browse files
committed
Auto merge of #42437 - Mark-Simulacrum:skip-no-doc, r=alexcrichton
Skip documentation files without ``` when running markdown tests. This should reduce the 'running 0 tests' noise in builds, and I believe this is a good heuristic for us to use. cc @rust-lang/docs -- do we use the indented format for code blocks anywhere? Will we? If so, we shouldn't do this. r? @alexcrichton
2 parents 9006db1 + dd1d75e commit e1293ec

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/bootstrap/check.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ extern crate build_helper;
1818
use std::collections::HashSet;
1919
use std::env;
2020
use std::fmt;
21-
use std::fs;
21+
use std::fs::{self, File};
2222
use std::path::{PathBuf, Path};
2323
use std::process::Command;
24+
use std::io::Read;
2425

2526
use build_helper::output;
2627

@@ -328,24 +329,15 @@ pub fn docs(build: &Build, compiler: &Compiler) {
328329

329330
while let Some(p) = stack.pop() {
330331
if p.is_dir() {
331-
stack.extend(t!(p.read_dir()).map(|p| t!(p).path()));
332+
stack.extend(t!(p.read_dir()).map(|p| t!(p).path()).filter(|p| {
333+
p.extension().and_then(|s| s.to_str()) == Some("md") &&
334+
// The nostarch directory in the book is for no starch, and so isn't guaranteed to
335+
// build. We don't care if it doesn't build, so skip it.
336+
p.to_str().map_or(true, |p| !p.contains("nostarch"))
337+
}));
332338
continue
333339
}
334340

335-
if p.extension().and_then(|s| s.to_str()) != Some("md") {
336-
continue
337-
}
338-
339-
// The nostarch directory in the book is for no starch, and so isn't guaranteed to build.
340-
// we don't care if it doesn't build, so skip it.
341-
use std::ffi::OsStr;
342-
let path: &OsStr = p.as_ref();
343-
if let Some(path) = path.to_str() {
344-
if path.contains("nostarch") {
345-
continue;
346-
}
347-
}
348-
349341
println!("doc tests for: {}", p.display());
350342
markdown_test(build, compiler, &p);
351343
}
@@ -376,6 +368,13 @@ pub fn error_index(build: &Build, compiler: &Compiler) {
376368
}
377369

378370
fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) {
371+
let mut file = t!(File::open(markdown));
372+
let mut contents = String::new();
373+
t!(file.read_to_string(&mut contents));
374+
if !contents.contains("```") {
375+
return;
376+
}
377+
379378
let mut cmd = Command::new(build.rustdoc(compiler));
380379
build.add_rustc_lib_path(compiler, &mut cmd);
381380
build.add_rust_test_threads(&mut cmd);

0 commit comments

Comments
 (0)