Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the tests #10

Merged
merged 38 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
7bd4d5a
Fix the tests
peternewman Jun 3, 2020
367d4ba
Require git master to work too and don't fail fast
peternewman Jun 3, 2020
9326e1a
Remove the diagnostic run
peternewman Jun 3, 2020
928d4b8
Bump the required version of codespell
peternewman Jun 3, 2020
5f74246
Merge branch 'master' into peternewman-fix-tests
peternewman Dec 2, 2020
f27665d
Simulate the Dockerfile COPY command
peternewman Dec 2, 2020
f49504c
Try and sudo to fix the permissions issue
peternewman Dec 2, 2020
c5dbe6f
Only mkdir/copy if it hasn't been done
peternewman Dec 2, 2020
08ae01d
Try copying the file to ${RUNNER_TEMP}
peternewman Dec 2, 2020
bf2bec9
Make parent folders if required
peternewman Dec 2, 2020
a90243a
Copy to both locations, add some debug
peternewman Dec 2, 2020
0bbff5e
Get ls to show the full path
peternewman Dec 2, 2020
216895f
More simulation of BATS failures
peternewman Dec 2, 2020
52f299e
Create teardown.bash
peternewman Dec 2, 2020
15e3eeb
Install the test debug
peternewman Dec 2, 2020
2292753
Always show the error count
peternewman Dec 2, 2020
fb62f44
Switch the first test to handle the new error count system
peternewman Dec 2, 2020
6046798
Skip a fiddly BATS test for now
peternewman Dec 2, 2020
58acb1c
Fix permissions on the test folder
peternewman Dec 2, 2020
ead6899
Convert another test
peternewman Dec 2, 2020
e61fbbf
Try changing how we set the exit status
peternewman Dec 2, 2020
1d8b046
Try going back to basics
peternewman Dec 2, 2020
e894697
Take out the teardown stuff temporarily
peternewman Dec 2, 2020
cbbc991
Try and improve the error count calculation again
peternewman Dec 2, 2020
751442d
Switch the other error counts to the new logic
peternewman Dec 2, 2020
c035912
Best guess for new line numbers
peternewman Dec 2, 2020
0ce0c51
Add some more debug
peternewman Dec 2, 2020
6ccde7b
Line numbers now zero based?
peternewman Dec 2, 2020
552dbbe
Always check the actual error count
peternewman Dec 2, 2020
5e86f0e
Fix a test and try adding teardown back in
peternewman Dec 2, 2020
37d1191
Fix the line offset on some BATS tests
peternewman Dec 2, 2020
452ccc8
Fix the hidden counts in the tests
peternewman Dec 2, 2020
34e6fc7
Read the error count backwards from the bottom (after all the errors)
peternewman Dec 2, 2020
e30e8fe
Require 2.0.0 due to the exit code/count behaviour change
peternewman Dec 2, 2020
17ee064
BATS diagnostics is optional
peternewman Dec 2, 2020
9f7dd73
Just return the exit code when debugging bats
peternewman Dec 4, 2020
8fd870a
Add the rest of the bats coderun
peternewman Dec 4, 2020
268a59e
Skip the bats diagnostics
peternewman Dec 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ jobs:
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
codespell_pip_version: ['codespell']
experimental: [false]
include:
- codespell_pip_version: 'git+https://github.com/codespell-project/codespell.git'
experimental: true
# Set this to true if git master is breaking the action's tests
experimental: false

steps:
- name: Checkout
Expand Down Expand Up @@ -62,12 +64,25 @@ jobs:
diagnose_bats:
name: Diagnose bats
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v2
- run: pip3 --quiet --quiet install git+https://github.com/codespell-project/codespell.git
- run: |
# Skip the bats diagnostics
exit 0
# Simulate the Dockerfile COPY command
[ -d "${RUNNER_TEMP}/code/" ] || sudo mkdir -p ${RUNNER_TEMP}/code/
[ -f "${RUNNER_TEMP}/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json ${RUNNER_TEMP}/code/
#ls -alR ${RUNNER_TEMP}/code/
[ -d "/code/" ] || sudo mkdir -p /code/
[ -f "/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json /code/
#ls -alR /code/
# Add a random place BATS tries to put it
[ -d "/github/workflow/" ] || sudo mkdir -p /github/workflow/ && sudo chmod 777 /github/workflow/
#ls -alR /github/workflow/
export INPUT_CHECK_FILENAMES=""
export INPUT_CHECK_HIDDEN=""
export INPUT_EXCLUDE_FILE=""
Expand All @@ -76,4 +91,4 @@ jobs:
export INPUT_IGNORE_WORDS_LIST=""
export INPUT_PATH="./test/testdata"
export INPUT_ONLY_WARN=""
./entrypoint.sh
./entrypoint.sh || echo $?
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if [ "x${INPUT_IGNORE_WORDS_LIST}" != "x" ]; then
fi
echo "Resulting CLI options ${command_args}"
exec 5>&1
res=`{ { codespell ${command_args} ${INPUT_PATH}; echo $? 1>&4; } 1>&5; } 4>&1`
res=`{ { codespell --count ${command_args} ${INPUT_PATH}; echo $? 1>&4; } 1>&5; } 4>&1`
if [ "$res" = "0" ]; then
echo "Codespell found no problems"
else
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
codespell>=1.17.0
codespell>=2.0.0
12 changes: 12 additions & 0 deletions test/teardown.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
teardown() {
if ((BATS_ERROR_STATUS));then
echo "Failed with status $BATS_ERROR_STATUS"
if [[ "${output}" != "" ]];then
echo "Output at that time was:"
echo "$output"
else
echo "Output was empty"
fi
return $BATS_ERROR_STATUS
fi
}
81 changes: 62 additions & 19 deletions test/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
# Tests using the Bats testing framework
# https://github.com/bats-core/bats-core

# Add some test debug from https://github.com/bats-core/bats-core/issues/199
# This currently breaks the tests, so only enabling when troubleshooting
#load teardown

ROOT_MISSPELLING_COUNT=5
FILENAME_MISSPELLING_COUNT=1
HIDDEN_MISSPELLING_COUNT=1
EXCLUDED_MISSPELLING_COUNT=1
BUILTIN_NAMES_MISSPELLING_COUNT=1
IGNORE_WORDS_MISSPELLING_COUNT=6
IGNORE_WORDS_MISSPELLING_COUNT=5
peternewman marked this conversation as resolved.
Show resolved Hide resolved
SUBFOLDER_MISSPELLING_COUNT=1
# From all files called example.txt
EXAMPLE_MISSPELLING_COUNT=5
Expand All @@ -17,6 +21,17 @@ export RUNNER_TEMP="/foo/runner_temp"

# This function runs before every test
function setup() {
# Simulate the Dockerfile COPY command
[ -d "${RUNNER_TEMP}/code/" ] || sudo mkdir -p ${RUNNER_TEMP}/code/
[ -f "${RUNNER_TEMP}/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json ${RUNNER_TEMP}/code/
#ls -alR ${RUNNER_TEMP}/code/
[ -d "/code/" ] || sudo mkdir -p /code/
[ -f "/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json /code/
#ls -alR /code/
# Add a random place BATS tries to put it
[ -d "/github/workflow/" ] || sudo mkdir -p /github/workflow/ && sudo chmod 777 /github/workflow/
#ls -alR /github/workflow/

# Set default input values
export INPUT_CHECK_FILENAMES=""
export INPUT_CHECK_HIDDEN=""
Expand All @@ -30,91 +45,119 @@ function setup() {
}

@test "Run with defaults" {
# codespell's exit status is the number of misspelled words found
expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT))
errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT))
# codespell's exit status is 0, or 65 if there are errors found
if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]

# Check output
[ "${lines[1]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ]
[ "${lines[0]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ]
outputRegex="^Running codespell on '${INPUT_PATH}'"
[[ "${lines[2]}" =~ $outputRegex ]]
[[ "${lines[1]}" =~ $outputRegex ]]
[ "${lines[-4 - $errorCount]}" == "$errorCount" ]
[ "${lines[-3]}" == "Codespell found one or more problems" ]
[ "${lines[-2]}" == "::remove-matcher owner=codespell-matcher-default::" ]
[ "${lines[-1]}" == "::remove-matcher owner=codespell-matcher-specified::" ]
}

@test "Check file names" {
expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + FILENAME_MISSPELLING_COUNT))
errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + FILENAME_MISSPELLING_COUNT))
# codespell's exit status is 0, or 65 if there are errors found
if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
INPUT_CHECK_FILENAMES=true
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
[ "${lines[-4 - $errorCount]}" == "$errorCount" ]
}

@test "Check a hidden file" {
# codespell --check-hidden has a somewhat unintuitive behavior. When run on
# a directory, codespell works on hidden files even if this option is not
# enabled. It's only when INPUT_PATH points directly at a hidden file that
# codespell ignores it by default.
expectedExitStatus=$HIDDEN_MISSPELLING_COUNT
errorCount=$HIDDEN_MISSPELLING_COUNT
# codespell's exit status is 0, or 65 if there are errors found
if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
INPUT_CHECK_HIDDEN=true
INPUT_PATH="./test/testdata/.hidden"
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
[ "${lines[-4 - $errorCount]}" == "$errorCount" ]
}

@test "Check a hidden file without INPUT_CHECK_HIDDEN set" {
expectedExitStatus=0
errorCount=0
# codespell's exit status is 0, or 65 if there are errors found
if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
INPUT_PATH="./test/testdata/.hidden"
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
[ "${lines[-4 - $errorCount]}" == "$errorCount" ]
}

@test "Use an exclude file" {
expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXCLUDED_MISSPELLING_COUNT))
errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXCLUDED_MISSPELLING_COUNT))
# codespell's exit status is 0, or 65 if there are errors found
if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
INPUT_EXCLUDE_FILE="./test/exclude-file.txt"
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
[ "${lines[-4 - $errorCount]}" == "$errorCount" ]
}

@test "Check the skip option" {
expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXAMPLE_MISSPELLING_COUNT))
errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXAMPLE_MISSPELLING_COUNT))
# codespell's exit status is 0, or 65 if there are errors found
if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
INPUT_SKIP="example.txt"
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
[ "${lines[-4 - $errorCount]}" == "$errorCount" ]
}

@test "Use an additional builtin dictionary" {
expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + BUILTIN_NAMES_MISSPELLING_COUNT))
errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + BUILTIN_NAMES_MISSPELLING_COUNT))
# codespell's exit status is 0, or 65 if there are errors found
if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
INPUT_BUILTIN="clear,rare,names"
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
[ "${lines[-4 - $errorCount]}" == "$errorCount" ]
}

@test "Use an ignore words file" {
expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - IGNORE_WORDS_MISSPELLING_COUNT))
errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - IGNORE_WORDS_MISSPELLING_COUNT))
# codespell's exit status is 0, or 65 if there are errors found
if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
INPUT_IGNORE_WORDS_FILE="./test/ignore-words-file.txt"
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
[ "${lines[-4 - $errorCount]}" == "$errorCount" ]
}

@test "Use an ignore words list" {
expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - IGNORE_WORDS_MISSPELLING_COUNT))
errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - IGNORE_WORDS_MISSPELLING_COUNT))
# codespell's exit status is 0, or 65 if there are errors found
if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
INPUT_IGNORE_WORDS_LIST="abandonned"
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
[ "${lines[-4 - $errorCount]}" == "$errorCount" ]
}

@test "Custom path" {
expectedExitStatus=$((SUBFOLDER_MISSPELLING_COUNT))
errorCount=$((SUBFOLDER_MISSPELLING_COUNT))
# codespell's exit status is 0, or 65 if there are errors found
if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
INPUT_PATH="./test/testdata/subfolder"
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
[ "${lines[-4 - $errorCount]}" == "$errorCount" ]
}

@test "Only warn" {
expectedExitStatus=0
errorCount=0
# codespell's exit status is 0, or 65 if there are errors found
if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi
INPUT_ONLY_WARN=true
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
#[ "${lines[-4 - $errorCount]}" == "$errorCount" ]
}