Rust CLI Troubleshooting: Tests, Doctests, and Documentation

Commands for debugging failing tests, capturing output, isolating flaky cases, and fixing documentation-generation issues in Rust CLI projects.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Test debugging workflows

Isolate failing tests and inspect runtime output.

Run all tests

Build and run the full test suite.

bashANYcargotest
bash
cargo test

The baseline command for reproducing a failing test run.

Run a subset of tests

Filter tests by name substring.

bashANYcargotestfilter
bash
cargo test parse_args

Useful when tightening the debug loop around one failing CLI behavior.

Show test output

Print stdout/stderr from tests.

bashANYcargotestnocapture
bash
cargo test -- --nocapture

Great for CLI tools whose tests assert output or side effects.

Run tests serially

Use one test thread to reduce races.

bashANYcargotestthreads
bash
cargo test -- --test-threads=1

Helpful for flaky tests involving ports, temp files, or global process state.

Run one exact test

Use the exact test name through the test harness.

bashANYcargotestexact
bash
cargo test parse_args_handles_help -- --exact

Useful when multiple test names share the same substring.

Test one workspace package

Limit the run to a selected member.

bashANYcargotestworkspace
bash
cargo test -p my-cli

Avoids noise from unrelated packages in a workspace.

Docs and doctests

Generate docs, open local docs, and clean up stale output.

Build documentation

Generate local docs for the package and dependencies.

bashANYcargodocrustdoc
bash
cargo doc

Useful when troubleshooting rustdoc failures or missing public API docs.

Build and open local docs

Generate documentation and launch it in a browser.

bashANYcargodocopen
bash
cargo doc --open

Good for quickly verifying which public items and examples are appearing.

Run doctests only

Focus on failures in documentation examples.

bashANYcargotestdoctest
bash
cargo test --doc

Useful when only code examples inside docs are failing.

Clean stale docs and artifacts

Remove target output before a fresh doc build.

bashANYcargocleandoc
bash
cargo clean

Useful because documentation output can accumulate in `target/doc` across runs.

Hide setup lines in doctests

Keep examples readable while still compiling.

rustANYrustdoctestdocs
rust
/// ```
/// # use std::path::Path;
/// let path = Path::new("Cargo.toml");
/// assert!(path.exists());
/// ```

Hidden `#` lines are a common technique for making doctests compile without cluttering the displayed example.

Recommended next

No recommendations yet.