rust-lang/mdBook · error

One or more tests failed

Error message

One or more tests failed

What it means

MDBook::test_chapter() runs each Rust code block (mdbook test) via the rustdoc test runner and tracks failures; if any test failed it bails with this summary error after printing per-test output to stderr.

Source

Thrown at crates/mdbook-driver/src/mdbook.rs:337

                debug!("running {:?}", cmd);
                let output = cmd
                    .output()
                    .with_context(|| "failed to execute `rustdoc`")?;

                if !output.status.success() {
                    failed = true;
                    eprintln!(
                        "ERROR rustdoc returned an error:\n\
                        \n--- stdout\n{}\n--- stderr\n{}",
                        String::from_utf8_lossy(&output.stdout),
                        String::from_utf8_lossy(&output.stderr)
                    );
                }
            }
        }
        if failed {
            bail!("One or more tests failed");
        }
        if let Some(chapter) = chapter {
            if !chapter_found {
                bail!("Chapter not found: {}", chapter);
            }
        }
        Ok(())
    }

    /// The logic for determining where a backend should put its build
    /// artefacts.
    ///
    /// If there is only 1 renderer, put it in the directory pointed to by the
    /// `build.build_dir` key in [`Config`]. If there is more than one then the
    /// renderer gets its own directory within the main build dir.
    ///
    /// i.e. If there were only one renderer (in this case, the HTML renderer):
    ///

View on GitHub (pinned to dc21064fc2)

Solutions

  1. Fix the failing code blocks listed in the test output above this error
  2. Re-run with verbose output to see the exact failing chapter/test
  3. Pin example code to the documented API or mark non-testable blocks with `text`/`ignore` annotations

Example fix

// before (book code block)
```rust
let x = lib::old_api();
```
// after
```rust
let x = lib::new_api();
```
Defensive patterns

Strategy: try-catch

Try / catch

if let Err(e) = book.test(&[], None, chapter) {
    eprintln!("test run failed: {e}; see failing code blocks above");
    std::process::exit(1);
}

Prevention

When it happens

Trigger: Any doctest/code block in the book that fails compilation or assertions during `mdbook test`; interpreter non-zero exit recorded in the test runner.

Common situations: Code examples that drifted from the actual library API after a dependency upgrade; code blocks missing edition attributes; non-deterministic examples.

Related errors


AI-assisted analysis of rust-lang/mdBook@dc21064fc2 (2026-09-01). Data as JSON: /api/errors/c1f5e352a0c37fee. Report an issue: GitHub.