Skip to content

Commit 7cdfde6

Browse files
authored
Merge pull request #10 from codespell-project/peternewman-fix-tests
Fix the tests
2 parents f534087 + 268a59e commit 7cdfde6

5 files changed

Lines changed: 93 additions & 23 deletions

File tree

.github/workflows/testing.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ jobs:
88
runs-on: ubuntu-latest
99
continue-on-error: ${{ matrix.experimental }}
1010
strategy:
11+
fail-fast: false
1112
matrix:
1213
codespell_pip_version: ['codespell']
1314
experimental: [false]
1415
include:
1516
- codespell_pip_version: 'git+https://github.com/codespell-project/codespell.git'
16-
experimental: true
17+
# Set this to true if git master is breaking the action's tests
18+
experimental: false
1719

1820
steps:
1921
- name: Checkout
@@ -62,12 +64,25 @@ jobs:
6264
diagnose_bats:
6365
name: Diagnose bats
6466
runs-on: ubuntu-latest
67+
continue-on-error: true
6568
steps:
6669
- uses: actions/checkout@v1
6770
- name: Set up Python
6871
uses: actions/setup-python@v2
6972
- run: pip3 --quiet --quiet install git+https://github.com/codespell-project/codespell.git
7073
- run: |
74+
# Skip the bats diagnostics
75+
exit 0
76+
# Simulate the Dockerfile COPY command
77+
[ -d "${RUNNER_TEMP}/code/" ] || sudo mkdir -p ${RUNNER_TEMP}/code/
78+
[ -f "${RUNNER_TEMP}/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json ${RUNNER_TEMP}/code/
79+
#ls -alR ${RUNNER_TEMP}/code/
80+
[ -d "/code/" ] || sudo mkdir -p /code/
81+
[ -f "/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json /code/
82+
#ls -alR /code/
83+
# Add a random place BATS tries to put it
84+
[ -d "/github/workflow/" ] || sudo mkdir -p /github/workflow/ && sudo chmod 777 /github/workflow/
85+
#ls -alR /github/workflow/
7186
export INPUT_CHECK_FILENAMES=""
7287
export INPUT_CHECK_HIDDEN=""
7388
export INPUT_EXCLUDE_FILE=""
@@ -76,4 +91,4 @@ jobs:
7691
export INPUT_IGNORE_WORDS_LIST=""
7792
export INPUT_PATH="./test/testdata"
7893
export INPUT_ONLY_WARN=""
79-
./entrypoint.sh
94+
./entrypoint.sh || echo $?

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if [ "x${INPUT_IGNORE_WORDS_LIST}" != "x" ]; then
4242
fi
4343
echo "Resulting CLI options ${command_args}"
4444
exec 5>&1
45-
res=`{ { codespell ${command_args} ${INPUT_PATH}; echo $? 1>&4; } 1>&5; } 4>&1`
45+
res=`{ { codespell --count ${command_args} ${INPUT_PATH}; echo $? 1>&4; } 1>&5; } 4>&1`
4646
if [ "$res" = "0" ]; then
4747
echo "Codespell found no problems"
4848
else

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
codespell>=1.17.0
1+
codespell>=2.0.0

test/teardown.bash

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
teardown() {
2+
if ((BATS_ERROR_STATUS));then
3+
echo "Failed with status $BATS_ERROR_STATUS"
4+
if [[ "${output}" != "" ]];then
5+
echo "Output at that time was:"
6+
echo "$output"
7+
else
8+
echo "Output was empty"
9+
fi
10+
return $BATS_ERROR_STATUS
11+
fi
12+
}

test/test.bats

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
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+
610
ROOT_MISSPELLING_COUNT=5
711
FILENAME_MISSPELLING_COUNT=1
812
HIDDEN_MISSPELLING_COUNT=1
913
EXCLUDED_MISSPELLING_COUNT=1
1014
BUILTIN_NAMES_MISSPELLING_COUNT=1
11-
IGNORE_WORDS_MISSPELLING_COUNT=6
15+
IGNORE_WORDS_MISSPELLING_COUNT=5
1216
SUBFOLDER_MISSPELLING_COUNT=1
1317
# From all files called example.txt
1418
EXAMPLE_MISSPELLING_COUNT=5
@@ -17,6 +21,17 @@ export RUNNER_TEMP="/foo/runner_temp"
1721

1822
# This function runs before every test
1923
function 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

Comments
 (0)