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
Run all tests
cargo test

# Build and run the full test suite.

Run a subset of tests
cargo test parse_args

# Filter tests by name substring.

Show test output
cargo test -- --nocapture

# Print stdout/stderr from tests.

Run tests serially
cargo test -- --test-threads=1

# Use one test thread to reduce races.

Run one exact test
cargo test parse_args_handles_help -- --exact

# Use the exact test name through the test harness.

Test one workspace package
cargo test -p my-cli

# Limit the run to a selected member.

## Docs and doctests
Build documentation
cargo doc

# Generate local docs for the package and dependencies.

Build and open local docs
cargo doc --open

# Generate documentation and launch it in a browser.

Run doctests only
cargo test --doc

# Focus on failures in documentation examples.

Clean stale docs and artifacts
cargo clean

# Remove target output before a fresh doc build.

Hide setup lines in doctests
/// ```
/// # use std::path::Path;
/// let path = Path::new("Cargo.toml");
/// assert!(path.exists());
/// ```

# Keep examples readable while still compiling.

Recommended next

No recommendations yet.