You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/guide/test-rule.md
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -109,11 +109,11 @@ invalid:
109
109
# .... more invalid test cases
110
110
```
111
111
112
-
After writing the test configuration file, you can run `sg test` in the root folder to test your rule.
112
+
After writing the test configuration file, you can run `ast-grep test` in the root folder to test your rule.
113
113
We will discuss the `skip-snapshot-tests` option later.
114
114
115
115
```bash
116
-
$ sg test --skip-snapshot-tests
116
+
$ ast-grep test --skip-snapshot-tests
117
117
118
118
Running 1 tests
119
119
PASS no-await-in-loop .........................
@@ -147,7 +147,7 @@ In failure details, we can see the detailed code snippet for each case.
147
147
Besides testing code validity, we can further test rule's output like error's message and span. This is what snapshot test will cover.
148
148
149
149
## Snapshot Test
150
-
Let's rerun `sg test` without `--skip-snapshot-tests` option.
150
+
Let's rerun `ast-grep test` without `--skip-snapshot-tests` option.
151
151
This time we will get test failure that invalid code error does not have a matching snapshot.
152
152
Previously we use the `skip-snapshot-tests` option to suppress snapshot test, which is useful when you are still working on your rule. But after the rule is polished, we can create snapshot to capture the desired output of the rule.
153
153
@@ -165,14 +165,14 @@ my-awesome-rules/
165
165
```
166
166
167
167
The generated `__snapshots__` folder will store all the error output and later test run will match against them.
168
-
After the snapshot is generated, we can run `sg test` again, without any option this time, and pass all the test cases!
168
+
After the snapshot is generated, we can run `ast-grep test` again, without any option this time, and pass all the test cases!
169
169
170
170
Furthermore, when we change the rule or update the test case, we can use interactive mode to update the snapshot.
171
171
172
172
Running this command
173
173
174
174
```bash
175
-
sg test --interactive
175
+
ast-grep test --interactive
176
176
```
177
177
178
178
ast-grep will spawn an interactive session to ask you select desired snapshot updates. Example interactive session will look like this. Note the snapshot diff is highlighted in red/green color.
0 commit comments