Skip to content

Skip documentation files without ``` when running markdown tests. #42437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ extern crate build_helper;
use std::collections::HashSet;
use std::env;
use std::fmt;
use std::fs;
use std::fs::{self, File};
use std::path::{PathBuf, Path};
use std::process::Command;
use std::io::Read;

use build_helper::output;

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

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

if p.extension().and_then(|s| s.to_str()) != Some("md") {
continue
}

// The nostarch directory in the book is for no starch, and so isn't guaranteed to build.
// we don't care if it doesn't build, so skip it.
use std::ffi::OsStr;
let path: &OsStr = p.as_ref();
if let Some(path) = path.to_str() {
if path.contains("nostarch") {
continue;
}
}

println!("doc tests for: {}", p.display());
markdown_test(build, compiler, &p);
}
Expand Down Expand Up @@ -376,6 +368,13 @@ pub fn error_index(build: &Build, compiler: &Compiler) {
}

fn markdown_test(build: &Build, compiler: &Compiler, markdown: &Path) {
let mut file = t!(File::open(markdown));
let mut contents = String::new();
t!(file.read_to_string(&mut contents));
if !contents.contains("```") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't the only way there are code blocks though; for example, four spaces is also considered a code block

return;
}

let mut cmd = Command::new(build.rustdoc(compiler));
build.add_rustc_lib_path(compiler, &mut cmd);
build.add_rust_test_threads(&mut cmd);
Expand Down