From 09ea29de9193c3d186cc98ebaeb921c34aa39f66 Mon Sep 17 00:00:00 2001 From: Raphael Boidol Date: Wed, 28 Feb 2024 22:48:59 +0100 Subject: [PATCH] tests: extend tests with failing check --- .github/workflows/test.yaml | 15 +++++++++++++-- tests/.pre-commit-config.yaml | 11 ++++++++++- tests/rules/test-rule-fail.yaml | 9 +++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 tests/rules/test-rule-fail.yaml diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1f4ae5b..73f9f2c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -1,4 +1,4 @@ -name: "Test pre-commit hook" +name: "Tests" on: push: @@ -19,7 +19,18 @@ 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 + echo "::notice::Hook failed as expected" \ No newline at end of file diff --git a/tests/.pre-commit-config.yaml b/tests/.pre-commit-config.yaml index 5bb6576..e62cfc7 100644 --- a/tests/.pre-commit-config.yaml +++ b/tests/.pre-commit-config.yaml @@ -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-fix", "--update-all"] diff --git a/tests/rules/test-rule-fail.yaml b/tests/rules/test-rule-fail.yaml new file mode 100644 index 0000000..979328b --- /dev/null +++ b/tests/rules/test-rule-fail.yaml @@ -0,0 +1,9 @@ +id: ast-grep-fail +message: Test fail rule +severity: error +language: json +rule: + kind: pair + has: + field: key + regex: ^"extends"$ \ No newline at end of file