|
17 | 17 | # Copyright (C) 2023 Perry Naseck, Peter Newman |
18 | 18 |
|
19 | 19 | # This script is based on Travis CI tests by Peter Newman |
| 20 | +current_test="" |
| 21 | +# run_single_only=false |
| 22 | +if [ "$1" = "spellintian" ]; then |
| 23 | + current_test="spellintian" |
| 24 | + # run_single_only=true |
| 25 | +elif [ "$1" = "codespell" ]; then |
| 26 | + current_test="codespell" |
| 27 | +else |
| 28 | + echo "Unknown test specified in first argument. Options are spellintian and codespell." |
| 29 | + exit 1; |
| 30 | +fi; |
| 31 | + |
20 | 32 | if ! [ -x "$(command -v zrun)" ]; then |
21 | 33 | echo "error: Cannot find zrun. Do you need the moreutils package?" |
22 | 34 | exit 1; |
23 | 35 | fi; |
24 | | -if ! [ -x "$(command -v spellintian)" ]; then |
| 36 | +if [ $current_test = "spellintian" ] && ! [ -x "$(command -v spellintian)" ]; then |
25 | 37 | echo "error: Cannot find spellintian. Do you need the lintian package?" |
26 | 38 | exit 1; |
27 | 39 | fi; |
28 | | -if ! [ -x "$(command -v codespell)" ]; then |
| 40 | +if [ $current_test = "codespell" ] && ! [ -x "$(command -v codespell)" ]; then |
29 | 41 | echo "error: Cannot find codespell. Install via pip." |
30 | 42 | exit 1; |
31 | 43 | fi; |
@@ -70,32 +82,21 @@ spellingfiles=$(eval "find ./ -type f -and ! \( \ |
70 | 82 | $SPELLINGBLACKLIST \ |
71 | 83 | \) | xargs") |
72 | 84 |
|
73 | | -# count the number of codespell errors |
74 | | -codespell_errors="$(zrun codespell --interactive 0 --disable-colors --check-filenames --check-hidden --quiet 2 --regex "[a-zA-Z0-9][\\-'a-zA-Z0-9]+[a-zA-Z0-9]" --exclude-file .codespellignorelines --ignore-words .codespellignorewords $spellingfiles 2>&1)" |
75 | | -codespell_errors_count="$([ "$codespell_errors" == "" ] && printf "0" || (printf "%s\n" "$codespell_errors" | wc -l))" |
76 | | -codespell_severity="$([ "$codespell_errors_count" == "0" ] && printf "notice" || printf "error" )" |
77 | | - |
78 | | -# count the number of spellintian errors, including duplicate words |
79 | | -spellintian_errors="$(zrun spellintian $spellingfiles 2>&1)" |
80 | | -spellintian_errors_count=$([ "$spellintian_errors" == "" ] && printf "0" || (printf "%s\n" "$spellintian_errors" | wc -l)) |
81 | | -spellintian_severity="$([ "$spellintian_errors_count" == "0" ] && printf "notice" || printf "error" )" |
| 85 | +if [ $current_test = "spellintian" ]; then |
| 86 | + # count the number of spellintian errors, including duplicate words |
| 87 | + # spellintian does not change the exit code, so the output must be checked |
| 88 | + spellintian_issues="$(zrun spellintian $spellingfiles 2>&1)" |
82 | 89 |
|
83 | | -total_errors_count="$(($spellintian_errors_count + $codespell_errors_count))" |
84 | | -total_severity="$([ "$total_errors_count" == "0" ] && printf "notice" || printf "error" )" |
85 | | - |
86 | | -if [[ $spellintian_errors_count -ne 0 ]]; then |
87 | | - # print the output for info |
88 | | - printf "%s\n" "$spellintian_errors" | sed 's/^\(.*\): \(.*\)$/error:file:\1: spellintian: \2/g' |
89 | | -fi; |
90 | | - |
91 | | -if [[ $codespell_errors_count -ne 0 ]]; then |
92 | | - # print the output for info |
93 | | - printf "%s\n" "$codespell_errors" | sed 's/^\(.*\):\([0-9]\+\): \(.*\)$/error:file:\1:line \2: codespell: \3/g' |
| 90 | + if [[ -n $spellintian_issues ]]; then |
| 91 | + printf "%s\n" "$spellintian_issues" |
| 92 | + # For now we always exit with success, as these errors are manually checked |
| 93 | + # exit 1; |
| 94 | + exit 0; |
| 95 | + fi; |
94 | 96 | fi; |
95 | 97 |
|
96 | | -echo "$spellintian_severity: Found $spellintian_errors_count spelling errors via spellintian" |
97 | | -echo "$codespell_severity: Found $codespell_errors_count spelling errors via codespell" |
98 | | -echo "$total_severity: Found $total_errors_count total spelling errors" |
99 | | -if [[ $total_errors_count -ne 0 ]]; then |
100 | | - exit 1; |
| 98 | +if [ $current_test = "codespell" ]; then |
| 99 | + if ! zrun codespell --interactive 0 --check-filenames --check-hidden --quiet 2 --regex "[a-zA-Z0-9][\\-'a-zA-Z0-9]+[a-zA-Z0-9]" --exclude-file .codespellignorelines --ignore-words .codespellignorewords $spellingfiles 2>&1; then |
| 100 | + exit 1; |
| 101 | + fi; |
101 | 102 | fi; |
0 commit comments