Skip to main content

Documentation 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.

The test command runs the test suite for a parser. It validates corpus tests, query validity, syntax highlighting tests, and tag tests.
tree-sitter test [OPTIONS]
Aliases: t

Test Types

The command runs several types of tests:

Corpus Tests

Located in test/corpus/, these tests verify that the parser produces the expected syntax trees for various inputs.

Query Tests

Validates that all queries in the queries/ directory are syntactically correct and work with the parser.

Highlight Tests

Located in test/highlight/, these tests verify syntax highlighting produces expected results.

Tag Tests

Located in test/tags/, these tests verify symbol tagging produces expected tags.

Options

Test Selection

-i, --include
regex
Only run tests whose names match this regex.
-e, --exclude
regex
Skip tests whose names match this regex.
--file-name
name
Only run tests from the given filename in the corpus.

Parser Options

-p, --grammar-path
path
The path to the directory containing the grammar. Implies --rebuild.
--lib-path
path
The path to the parser’s dynamic library. Used instead of the cached or automatically generated library.
--lang-name
string
If --lib-path is used, the name of the language used to extract the library’s language function.

Test Management

-u, --update
flag
Update the expected output of tests.
Tests containing ERROR nodes or MISSING nodes will not be updated.

Output Options

--overview-only
flag
Only show the overview of test results, not the diff.
--show-fields
flag
Force showing fields in test diffs.
--stat
level
Show parsing statistics when tests are being run. One of:
  • all - Show statistics for every test
  • outliers-and-total - Show statistics only for outliers and total
  • total-only - Show only total statistics
--json-summary
flag
Output the test summary in a JSON format.

Debug Options

-d, --debug
flag
Output parsing and lexing logs to stderr.
-D, --debug-graph
flag
Output logs of the graphs of the stack and parse trees. Graphs are constructed with graphviz dot, and output is written to log.html.
--open-log
flag
When using --debug-graph, open the log file in the default browser.
-0, --debug-build
flag
Compile the parser with debug flags enabled. Useful when debugging with gdb or lldb.

Build Options

--wasm
flag
Compile and run the parser as a Wasm module (only if the CLI was built with --features=wasm).
-r, --rebuild
flag
Force a rebuild of the parser before running tests.
--config-path
path
The path to an alternative configuration (config.json) file. See init-config.

Examples

Run All Tests

tree-sitter test

Run Tests Matching a Pattern

tree-sitter test --include "function"

Update Test Expectations

tree-sitter test --update

Run Tests with Statistics

tree-sitter test --stat all

Debug a Failing Test

tree-sitter test --include "my_test" --debug-graph --open-log

Run Tests from Specific File

tree-sitter test --file-name statements.txt

Show Only Overview

tree-sitter test --overview-only