| 
1 | 1 | #!/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  | 
22 | 18 | 
 
  | 
23 | 19 | echo "=================================================================================="  | 
24 |  | -echo "print result.txt"  | 
 | 20 | +echo "Print result.txt"  | 
25 | 21 | cat result.txt  | 
26 | 22 | echo "=================================================================================="  | 
27 | 23 | 
 
  | 
28 |  | -failed_cases=`grep -c "Failed" result.txt`  | 
 | 24 | +failed_cases=$(grep -c "Failed" result.txt)  | 
29 | 25 | 
 
  | 
30 |  | -echo $failed_cases " cases failed."  | 
 | 26 | +echo "$failed_cases cases failed."  | 
31 | 27 | 
 
  | 
32 |  | -if [ $failed_cases -eq 10 ]; then  | 
 | 28 | +if [[ $failed_cases -eq 21 ]]; then  | 
33 | 29 |     echo "=============================="  | 
34 | 30 |     echo "Test cpp-linter-hooks success."  | 
35 | 31 |     echo "=============================="  | 
 | 32 | +    result="success"  | 
36 | 33 |     rm result.txt  | 
37 |  | -    exit 0  | 
 | 34 | +    exit_code=0  | 
38 | 35 | else  | 
39 | 36 |     echo "============================="  | 
40 | 37 |     echo "Test cpp-linter-hooks failed."  | 
41 | 38 |     echo "============================="  | 
42 |  | -    exit 1  | 
 | 39 | +    result="failure"  | 
 | 40 | +    exit_code=1  | 
43 | 41 | 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