Skip to content

Commit 7332611

Browse files
authored
feat: add more tests (#135)
* Add more tests * Update shebang * chmod +x testing/run.sh * update run.sh * update run.sh * update run.sh * update run.sh * add result to github summary
1 parent c1d5f09 commit 7332611

File tree

4 files changed

+82
-28
lines changed

4 files changed

+82
-28
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ jobs:
4040
fail_ci_if_error: true # optional (default = false)
4141
verbose: true # optional (default = false)
4242
- name: Test cpp-linter-hooks
43-
run: sh testing/run.sh
43+
run: bash testing/run.sh

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repos:
1010
- id: check-toml
1111
- id: requirements-txt-fixer
1212
- repo: https://github.com/astral-sh/ruff-pre-commit
13-
rev: v0.13.1
13+
rev: v0.14.2
1414
hooks:
1515
# Run the linter.
1616
- id: ruff-check
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
repos:
2+
- repo: .
3+
rev: HEAD
4+
hooks:
5+
- id: clang-format
6+
args: [--style=LLVM, --version=16] # to load .clang-format
7+
- id: clang-tidy
8+
args: [--checks=.clang-tidy, --version=16] # path/to/.clang-tidy
9+
- repo: .
10+
rev: HEAD
11+
hooks:
12+
- id: clang-format
13+
args: [--style=Google, --version=17]
14+
- id: clang-tidy
15+
args: [--checks=.clang-tidy, --version=17]
16+
- repo: .
17+
rev: HEAD
18+
hooks:
19+
- id: clang-format
20+
args: [--style=Microsoft, --version=18]
21+
- id: clang-tidy
22+
args: [--checks=.clang-tidy, --version=18]
23+
- repo: .
24+
rev: HEAD
25+
hooks:
26+
- id: clang-format
27+
args: [--style=WebKit, --version=19]
28+
- id: clang-tidy
29+
args: [--checks=.clang-tidy, --version=19]
30+
- repo: .
31+
rev: HEAD
32+
hooks:
33+
- id: clang-format
34+
args: [--style=Mozilla, --version=20]
35+
- id: clang-tidy
36+
args: [--checks=.clang-tidy, --version=20]
37+
- repo: .
38+
rev: HEAD
39+
hooks:
40+
- id: clang-format
41+
args: [--style=Chromium, --version=21]
42+
- id: clang-tidy
43+
args: [--checks=.clang-tidy, --version=21]

testing/run.sh

100644100755
Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,54 @@
11
#!/bin/bash
2-
echo "==========================="
3-
echo "Test pre-commit-config.yaml"
4-
echo "==========================="
5-
pre-commit clean
6-
pre-commit run -c testing/pre-commit-config.yaml --files testing/main.c | tee -a result.txt || true
7-
git restore testing/main.c
8-
9-
echo "===================================="
10-
echo "Test pre-commit-config-version.yaml"
11-
echo "===================================="
12-
pre-commit clean
13-
pre-commit run -c testing/pre-commit-config-version.yaml --files testing/main.c | tee -a result.txt || true
14-
git restore testing/main.c
15-
16-
echo "===================================="
17-
echo "Test pre-commit-config-verbose.yaml"
18-
echo "===================================="
19-
pre-commit clean
20-
pre-commit run -c testing/pre-commit-config-verbose.yaml --files testing/main.c | tee -a result.txt || true
21-
git restore testing/main.c
2+
3+
configs=(
4+
"pre-commit-config.yaml"
5+
"pre-commit-config-version.yaml"
6+
"pre-commit-config-verbose.yaml"
7+
"pre-commit-config-style.yaml"
8+
)
9+
10+
for config in "${configs[@]}"; do
11+
echo "===================================="
12+
echo "Test $config"
13+
echo "===================================="
14+
pre-commit clean
15+
pre-commit run -c testing/$config --files testing/main.c | tee -a result.txt || true
16+
git restore testing/main.c
17+
done
2218

2319
echo "=================================================================================="
24-
echo "print result.txt"
20+
echo "Print result.txt"
2521
cat result.txt
2622
echo "=================================================================================="
2723

28-
failed_cases=`grep -c "Failed" result.txt`
24+
failed_cases=$(grep -c "Failed" result.txt)
2925

30-
echo $failed_cases " cases failed."
26+
echo "$failed_cases cases failed."
3127

32-
if [ $failed_cases -eq 10 ]; then
28+
if [[ $failed_cases -eq 21 ]]; then
3329
echo "=============================="
3430
echo "Test cpp-linter-hooks success."
3531
echo "=============================="
32+
result="success"
3633
rm result.txt
37-
exit 0
34+
exit_code=0
3835
else
3936
echo "============================="
4037
echo "Test cpp-linter-hooks failed."
4138
echo "============================="
42-
exit 1
39+
result="failure"
40+
exit_code=1
4341
fi
42+
43+
# Add result to GitHub summary if running in GitHub Actions
44+
if [[ -n "$GITHUB_STEP_SUMMARY" ]]; then
45+
{
46+
echo "### cpp-linter-hooks Test Result"
47+
echo ""
48+
echo "**Result:** $result"
49+
echo ""
50+
echo "**Failed cases:** $failed_cases"
51+
} >> "$GITHUB_STEP_SUMMARY"
52+
fi
53+
54+
exit $exit_code

0 commit comments

Comments
 (0)