---
url: /reference/cli/test.md
---

# `ast-grep test`

Test ast-grep rules.

Since 0.51.2, exits with a failure if a selected test ID has no matching rule
or if no test cases run. See the [testing guide](/guide/test-rule#test-case-configuration).

## Usage

```shell
ast-grep test [OPTIONS]
```

## Options

### `-c, --config <CONFIG>`

Path to ast-grep root config, default is sgconfig.yml

### `--custom-languages <CUSTOM_LANGUAGES>`

Control loading of native parsers used by custom language rules. See
[global options](/reference/cli#global-options) and the
[custom language guide](/advanced/custom-language#enable-custom-language-loading).

### `-t, --test-dir <TEST_DIR>`

the directories to search test YAML files

### `--snapshot-dir <SNAPSHOT_DIR>`

Specify the directory name storing snapshots. Default to **snapshots**

### `--skip-snapshot-tests`

Only check if the test code is valid, without checking rule output. Turn it on when you want to ignore the output of rules. Conflicts with --update-all

### `-U, --update-all`

Update the content of all snapshots that have changed in test. Conflicts with --skip-snapshot-tests

### `-i, --interactive`

Start an interactive review to update snapshots selectively

### `-f, --filter <FILTER>`

Filter rule test cases to execute using a glob pattern

### `--include-off`

Include `severity:off` rules in test

ast-grep will not run rules with `severity: off` by default. This option will include those rules in the test.

### `--color <WHEN>`

Controls when to use color in the output.

This is useful when piping test output to a file or another command, where ANSI escape codes would be unwanted.
Possible values:

* `auto` (default): Automatically detect if color support is available on the terminal
* `always`: Always display colors
* `ansi`: Always display colors but with ANSI escape codes (alias for `always`)
* `never`: Never display colors

### `-h, --help`

Print help
