TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tree-sitter/tree-sitter/llms.txt
Use this file to discover all available pages before exploring further.
fuzz command tests a parser by performing random edits and ensuring that undoing these edits results in consistent parse trees.
f
How It Works
The fuzzer:- Parses test files from your corpus
- Applies random edits to the source code
- Re-parses the edited code
- Undoes the edits
- Verifies the parse tree matches the original
- Parse trees are not equal after undoing edits
- Changed ranges are inconsistent
- The parser crashes or hangs
Options
Test Selection
A list of test names to skip fuzzing. Can be specified multiple times.
Only fuzz corpus test cases whose names match this regex.
Skip corpus test cases whose names match this regex.
Parser Options
The path to the directory containing the grammar. Implies
--rebuild.The path to the parser’s dynamic library. Used instead of the cached or automatically generated library.
If
--lib-path is used, the name of the language used to extract the library’s language function.The directory containing the parser. Primarily useful in multi-language repositories.
Fuzzing Parameters
The maximum number of edits to perform per fuzz test.Can also be set via the
TREE_SITTER_EDITS environment variable.The number of iterations to run per test.Can also be set via the
TREE_SITTER_ITERATIONS environment variable.Debug Options
Output parsing and lexing logs to stderr.
Output logs of the graphs of the stack and parse trees during parsing. Graphs are constructed with graphviz dot, and output is written to
log.html.Build Options
Force a rebuild of the parser before running the fuzzer.
Examples
Basic Fuzzing
Fuzz with More Iterations
Fuzz Specific Tests
Skip Problematic Tests
Fuzz with Debug Logging
Fuzz with Environment Variables
Best Practices
Start Small
Begin with few iterations and edits, then increase:Focus on Problem Areas
Use--include to focus on specific language constructs:
Regular Fuzzing
Incorporate fuzzing into your development workflow:CI Integration
Add fuzzing to your CI pipeline:Interpreting Results
Success
If all tests pass, you’ll see:Failure
If a test fails, you’ll see:- The test name that failed
- The edit sequence that caused the failure
- Details about the inconsistency
- Reproduce the issue manually
- Add a regression test
- Fix the grammar or external scanner
Troubleshooting
Fuzzing Takes Too Long
Reduce iterations or edits:Tests Hang
Some inputs may cause infinite loops. Use--skip to bypass:
Inconsistent Failures
Fuzzing is random, so failures may not reproduce. To help:- Note the seed value if displayed
- Run multiple times to confirm
- Add logging to understand the issue