Skip to content

Commit

Permalink
Split test::Docs into one Step for each book.
Browse files Browse the repository at this point in the history
The *.md at the root directory in src/doc are no longer tested, but this
should be fine since all files there are deprecated.
  • Loading branch information
kennytm committed Feb 22, 2018
1 parent 51238c7 commit 0d300d4
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/bootstrap/builder.rs
Expand Up @@ -231,7 +231,7 @@ pub struct ShouldRun<'a> {
paths: BTreeSet<PathSet>,

// If this is a default rule, this is an additional constraint placed on
// it's run. Generally something like compiler docs being enabled.
// its run. Generally something like compiler docs being enabled.
is_really_default: bool,
}

Expand Down Expand Up @@ -326,7 +326,9 @@ impl<'a> Builder<'a> {
test::RunPassPretty, test::RunFailPretty, test::RunPassValgrindPretty,
test::RunPassFullDepsPretty, test::RunFailFullDepsPretty, test::RunMake,
test::Crate, test::CrateLibrustc, test::Rustdoc, test::Linkcheck, test::Cargotest,
test::Cargo, test::Rls, test::Docs, test::ErrorIndex, test::Distcheck,
test::Cargo, test::Rls, test::ErrorIndex, test::Distcheck,
test::Nomicon, test::Reference, test::RustdocBook, test::RustByExample,
test::TheBook, test::UnstableBook,
test::Rustfmt, test::Miri, test::Clippy, test::RustdocJS, test::RustdocTheme),
Kind::Bench => describe!(test::Crate, test::CrateLibrustc),
Kind::Doc => describe!(doc::UnstableBook, doc::UnstableBookGen, doc::TheBook,
Expand Down
65 changes: 53 additions & 12 deletions src/bootstrap/test.rs
Expand Up @@ -994,23 +994,19 @@ impl Step for Compiletest {
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct Docs {
struct DocTest {
compiler: Compiler,
path: &'static str,
name: &'static str,
is_ext_doc: bool,
}

impl Step for Docs {
impl Step for DocTest {
type Output = ();
const DEFAULT: bool = true;
const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
run.path("src/doc")
}

fn make_run(run: RunConfig) {
run.builder.ensure(Docs {
compiler: run.builder.compiler(run.builder.top_stage, run.host),
});
run.never()
}

/// Run `rustdoc --test` for all documentation in `src/doc`.
Expand All @@ -1026,9 +1022,9 @@ impl Step for Docs {

// Do a breadth-first traversal of the `src/doc` directory and just run
// tests for all files that end in `*.md`
let mut stack = vec![build.src.join("src/doc")];
let mut stack = vec![build.src.join(self.path)];
let _time = util::timeit();
let _folder = build.fold_output(|| "test_docs");
let _folder = build.fold_output(|| format!("test_{}", self.name));

while let Some(p) = stack.pop() {
if p.is_dir() {
Expand All @@ -1051,6 +1047,51 @@ impl Step for Docs {
}
}

macro_rules! test_book {
($($name:ident, $path:expr, $book_name:expr, default=$default:expr;)+) => {
$(
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct $name {
compiler: Compiler,
}

impl Step for $name {
type Output = ();
const DEFAULT: bool = $default;
const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
run.path($path)
}

fn make_run(run: RunConfig) {
run.builder.ensure($name {
compiler: run.builder.compiler(run.builder.top_stage, run.host),
});
}

fn run(self, builder: &Builder) {
builder.ensure(DocTest {
compiler: self.compiler,
path: $path,
name: $book_name,
is_ext_doc: !$default,
});
}
}
)+
}
}

test_book!(
Nomicon, "src/doc/nomicon", "nomicon", default=false;
Reference, "src/doc/reference", "reference", default=false;
RustdocBook, "src/doc/rustdoc", "rustdoc", default=true;
RustByExample, "src/doc/rust-by-example", "rust-by-example", default=false;
TheBook, "src/doc/book", "book", default=false;
UnstableBook, "src/doc/unstable-book", "unstable-book", default=true;
);

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct ErrorIndex {
compiler: Compiler,
Expand Down

0 comments on commit 0d300d4

Please sign in to comment.