BurntSushi/ripgrep
Testing
ripgrep has two complementary test layers:
- Unit tests inside each crate, exercising library APIs.
- Integration tests under
tests/, exercising the compiledrgbinary as a black box.
The full suite is run via cargo test --all.
Integration tests
Integration tests are wired through tests/tests.rs, which simply pulls in every other test file. The actual test bodies live in:
| File | What it covers |
|---|---|
tests/feature.rs |
The bulk of CLI behaviour: flag combinations, exit codes, output formatting |
tests/regression.rs |
Tests captured from past bug reports; ~54K of code |
tests/json.rs |
The --json output format |
tests/multiline.rs |
The -U/--multiline mode |
tests/binary.rs |
Binary-file detection and --text/--binary |
tests/misc.rs |
Anything that doesn't fit elsewhere |
tests/util.rs |
The harness: builds rg invocations, captures stdout/stderr, asserts |
tests/data/ |
Canned haystacks (e.g., sherlock) used by tests |
tests/macros.rs |
The rgtest!/sherlock! macros |
tests/hay.rs |
Constants for the canned haystacks |
The rgtest! macro
Most tests look like this:
rgtest!(my_test, |dir: Dir, mut cmd: TestCommand| {
dir.create("haystack", "foo\nbar\n");
cmd.arg("foo").assert_eq("haystack:foo\n");
});tests/util.rs defines:
Dir: a temporary directory for each test, auto-cleaned at the end.TestCommand: a wrapper aroundstd::process::Commandthat knows how to find thergbinary and assert against its output.
Helpers like assert_eq, assert_err, lines, stdout, and stderr make the assertions readable.
sherlock! macro
Many tests use the canned SHERLOCK haystack (Sherlock Holmes prose, defined in tests/hay.rs). sherlock! wraps rgtest! and pre-populates the directory with it.
Unit tests
Each crate carries its own unit tests inline. Notable suites:
crates/regex/src/literal.rs— literal extraction, the source of historical correctness bugs.crates/searcher/src/lib.rsandcrates/searcher/src/searcher/mod.rs— line stepping, mmap vs. buffered, encoding.crates/ignore/src/gitignore.rsandcrates/ignore/src/walk.rs— gitignore precedence rules.crates/globset/src/lib.rsandcrates/globset/src/glob.rs— glob compilation and matching.crates/printer/src/standard.rsandcrates/printer/src/json.rs— printer formatting (extensive).
crates/searcher/src/testutil.rs provides a generic harness (SearcherTester) used by both unit tests and the printer's tests. It runs the same query through every relevant configuration (mmap on/off, multi-line on/off, line numbers on/off) and compares against expected output.
Running a subset
# Single test by name substring
cargo test --test integration feature_glob
# Whole crate
cargo test -p grep-searcher
# A specific module
cargo test -p grep-printer standardSnapshot data
There are no snapshot tests in the conventional sense. Expected output is inlined in the test source as raw strings. This is consistent across the project; do not introduce a snapshot crate.
Performance regressions
There is no in-tree CI benchmark gate. The external benchsuite/ directory contains a benchmark harness that the maintainer runs by hand against new releases. If your change might affect performance, run benchsuite/ before and after locally and include the numbers in your PR description.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.