Skip to content

Commit

Permalink
tests: extend tests with failing check
Browse files Browse the repository at this point in the history
  • Loading branch information
boidolr committed Feb 28, 2024
1 parent 8fad677 commit fdb1e09
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Test pre-commit hook"
name: "Tests"

on:
push:
Expand All @@ -19,7 +19,17 @@ jobs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- uses: boidolr/actions/run-precommit@main
- uses: boidolr/actions/setup-precommit@main
with:
working-directory: tests

- name: Check hook pass
run: pre-commit run --config "tests/.pre-commit-config.yaml" --all-files ast-grep-pass

- name: Check hook failure
shell: bash
run: |
set +e
pre-commit run --config "tests/.pre-commit-config.yaml" --all-files ast-grep-fail
if [[ "$?" == "0" ]]; then exit 1; fi
11 changes: 10 additions & 1 deletion tests/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,14 @@ repos:
- repo: https://github.com/boidolr/precommit-ast-grep
rev: main
hooks:
- id: ast-grep
- alias: ast-grep-pass
id: ast-grep
args: ["--config=tests/sgconfig.yaml", "--filter=ast-grep-pass", "--update-all"]

- alias: ast-grep-fail
id: ast-grep
args: ["--config=tests/sgconfig.yaml", "--filter=ast-grep-fail"]

- alias: ast-grep-fix
id: ast-grep
args: ["--config=tests/sgconfig.yaml", "--filter=ast-grep-fail", "--update-all"]
9 changes: 9 additions & 0 deletions tests/rules/test-rule-fail.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
id: ast-grep-fail
message: Test fail rule
severity: error
language: json
rule:
kind: pair
has:
field: key
regex: ^"extends"$

0 comments on commit fdb1e09

Please sign in to comment.