33# Tests using the Bats testing framework
44# https://github.com/bats-core/bats-core
55
6+ # Add some test debug from https://github.com/bats-core/bats-core/issues/199
7+ # This currently breaks the tests, so only enabling when troubleshooting
8+ # load teardown
9+
610ROOT_MISSPELLING_COUNT=5
711FILENAME_MISSPELLING_COUNT=1
812HIDDEN_MISSPELLING_COUNT=1
913EXCLUDED_MISSPELLING_COUNT=1
1014BUILTIN_NAMES_MISSPELLING_COUNT=1
11- IGNORE_WORDS_MISSPELLING_COUNT=6
15+ IGNORE_WORDS_MISSPELLING_COUNT=5
1216SUBFOLDER_MISSPELLING_COUNT=1
1317# From all files called example.txt
1418EXAMPLE_MISSPELLING_COUNT=5
@@ -17,6 +21,17 @@ export RUNNER_TEMP="/foo/runner_temp"
1721
1822# This function runs before every test
1923function setup() {
24+ # Simulate the Dockerfile COPY command
25+ [ -d " ${RUNNER_TEMP} /code/" ] || sudo mkdir -p ${RUNNER_TEMP} /code/
26+ [ -f " ${RUNNER_TEMP} /code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json ${RUNNER_TEMP} /code/
27+ # ls -alR ${RUNNER_TEMP}/code/
28+ [ -d " /code/" ] || sudo mkdir -p /code/
29+ [ -f " /code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json /code/
30+ # ls -alR /code/
31+ # Add a random place BATS tries to put it
32+ [ -d " /github/workflow/" ] || sudo mkdir -p /github/workflow/ && sudo chmod 777 /github/workflow/
33+ # ls -alR /github/workflow/
34+
2035 # Set default input values
2136 export INPUT_CHECK_FILENAMES=" "
2237 export INPUT_CHECK_HIDDEN=" "
@@ -30,91 +45,119 @@ function setup() {
3045}
3146
3247@test " Run with defaults" {
33- # codespell's exit status is the number of misspelled words found
34- expectedExitStatus=$(( ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT))
48+ errorCount=$(( ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT))
49+ # codespell's exit status is 0, or 65 if there are errors found
50+ if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
3551 run " ./entrypoint.sh"
3652 [ $status -eq $expectedExitStatus ]
3753
3854 # Check output
39- [ " ${lines[1 ]} " == " ::add-matcher::${RUNNER_TEMP} /_github_workflow/codespell-matcher.json" ]
55+ [ " ${lines[0 ]} " == " ::add-matcher::${RUNNER_TEMP} /_github_workflow/codespell-matcher.json" ]
4056 outputRegex=" ^Running codespell on '${INPUT_PATH} '"
41- [[ " ${lines[2]} " =~ $outputRegex ]]
57+ [[ " ${lines[1]} " =~ $outputRegex ]]
58+ [ " ${lines[-4 - $errorCount]} " == " $errorCount " ]
4259 [ " ${lines[-3]} " == " Codespell found one or more problems" ]
4360 [ " ${lines[-2]} " == " ::remove-matcher owner=codespell-matcher-default::" ]
4461 [ " ${lines[-1]} " == " ::remove-matcher owner=codespell-matcher-specified::" ]
4562}
4663
4764@test " Check file names" {
48- expectedExitStatus=$(( ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + FILENAME_MISSPELLING_COUNT))
65+ errorCount=$(( ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + FILENAME_MISSPELLING_COUNT))
66+ # codespell's exit status is 0, or 65 if there are errors found
67+ if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
4968 INPUT_CHECK_FILENAMES=true
5069 run " ./entrypoint.sh"
5170 [ $status -eq $expectedExitStatus ]
71+ [ " ${lines[-4 - $errorCount]} " == " $errorCount " ]
5272}
5373
5474@test " Check a hidden file" {
55- # codespell --check-hidden has a somewhat unintuitive behavior. When run on
56- # a directory, codespell works on hidden files even if this option is not
57- # enabled. It's only when INPUT_PATH points directly at a hidden file that
58- # codespell ignores it by default.
59- expectedExitStatus=$HIDDEN_MISSPELLING_COUNT
75+ errorCount=$HIDDEN_MISSPELLING_COUNT
76+ # codespell's exit status is 0, or 65 if there are errors found
77+ if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
6078 INPUT_CHECK_HIDDEN=true
6179 INPUT_PATH=" ./test/testdata/.hidden"
6280 run " ./entrypoint.sh"
6381 [ $status -eq $expectedExitStatus ]
82+ [ " ${lines[-4 - $errorCount]} " == " $errorCount " ]
6483}
6584
6685@test " Check a hidden file without INPUT_CHECK_HIDDEN set" {
67- expectedExitStatus=0
86+ errorCount=0
87+ # codespell's exit status is 0, or 65 if there are errors found
88+ if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
6889 INPUT_PATH=" ./test/testdata/.hidden"
6990 run " ./entrypoint.sh"
7091 [ $status -eq $expectedExitStatus ]
92+ [ " ${lines[-4 - $errorCount]} " == " $errorCount " ]
7193}
7294
7395@test " Use an exclude file" {
74- expectedExitStatus=$(( ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXCLUDED_MISSPELLING_COUNT))
96+ errorCount=$(( ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXCLUDED_MISSPELLING_COUNT))
97+ # codespell's exit status is 0, or 65 if there are errors found
98+ if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
7599 INPUT_EXCLUDE_FILE=" ./test/exclude-file.txt"
76100 run " ./entrypoint.sh"
77101 [ $status -eq $expectedExitStatus ]
102+ [ " ${lines[-4 - $errorCount]} " == " $errorCount " ]
78103}
79104
80105@test " Check the skip option" {
81- expectedExitStatus=$(( ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXAMPLE_MISSPELLING_COUNT))
106+ errorCount=$(( ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXAMPLE_MISSPELLING_COUNT))
107+ # codespell's exit status is 0, or 65 if there are errors found
108+ if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
82109 INPUT_SKIP=" example.txt"
83110 run " ./entrypoint.sh"
84111 [ $status -eq $expectedExitStatus ]
112+ [ " ${lines[-4 - $errorCount]} " == " $errorCount " ]
85113}
86114
87115@test " Use an additional builtin dictionary" {
88- expectedExitStatus=$(( ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + BUILTIN_NAMES_MISSPELLING_COUNT))
116+ errorCount=$(( ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + BUILTIN_NAMES_MISSPELLING_COUNT))
117+ # codespell's exit status is 0, or 65 if there are errors found
118+ if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
89119 INPUT_BUILTIN=" clear,rare,names"
90120 run " ./entrypoint.sh"
91121 [ $status -eq $expectedExitStatus ]
122+ [ " ${lines[-4 - $errorCount]} " == " $errorCount " ]
92123}
93124
94125@test " Use an ignore words file" {
95- expectedExitStatus=$(( ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - IGNORE_WORDS_MISSPELLING_COUNT))
126+ errorCount=$(( ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - IGNORE_WORDS_MISSPELLING_COUNT))
127+ # codespell's exit status is 0, or 65 if there are errors found
128+ if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
96129 INPUT_IGNORE_WORDS_FILE=" ./test/ignore-words-file.txt"
97130 run " ./entrypoint.sh"
98131 [ $status -eq $expectedExitStatus ]
132+ [ " ${lines[-4 - $errorCount]} " == " $errorCount " ]
99133}
100134
101135@test " Use an ignore words list" {
102- expectedExitStatus=$(( ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - IGNORE_WORDS_MISSPELLING_COUNT))
136+ errorCount=$(( ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - IGNORE_WORDS_MISSPELLING_COUNT))
137+ # codespell's exit status is 0, or 65 if there are errors found
138+ if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
103139 INPUT_IGNORE_WORDS_LIST=" abandonned"
104140 run " ./entrypoint.sh"
105141 [ $status -eq $expectedExitStatus ]
142+ [ " ${lines[-4 - $errorCount]} " == " $errorCount " ]
106143}
107144
108145@test " Custom path" {
109- expectedExitStatus=$(( SUBFOLDER_MISSPELLING_COUNT))
146+ errorCount=$(( SUBFOLDER_MISSPELLING_COUNT))
147+ # codespell's exit status is 0, or 65 if there are errors found
148+ if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
110149 INPUT_PATH=" ./test/testdata/subfolder"
111150 run " ./entrypoint.sh"
112151 [ $status -eq $expectedExitStatus ]
152+ [ " ${lines[-4 - $errorCount]} " == " $errorCount " ]
113153}
114154
115155@test " Only warn" {
116- expectedExitStatus=0
156+ errorCount=0
157+ # codespell's exit status is 0, or 65 if there are errors found
158+ if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
117159 INPUT_ONLY_WARN=true
118160 run " ./entrypoint.sh"
119161 [ $status -eq $expectedExitStatus ]
162+ # [ "${lines[-4 - $errorCount]}" == "$errorCount" ]
120163}
0 commit comments