From 7bd4d5a5d7433ea27544c8a5c9d9e5e6028c364f Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 3 Jun 2020 22:45:11 +0100 Subject: [PATCH 01/37] Fix the tests For the new normalised hidden file behaviour --- test/test.bats | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test/test.bats b/test/test.bats index a842cde..4abad9c 100644 --- a/test/test.bats +++ b/test/test.bats @@ -26,7 +26,7 @@ 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)) + expectedExitStatus=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT)) run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] @@ -40,17 +40,13 @@ function setup() { } @test "Check file names" { - expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + FILENAME_MISSPELLING_COUNT)) + expectedExitStatus=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + FILENAME_MISSPELLING_COUNT)) INPUT_CHECK_FILENAMES=true run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] } @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 INPUT_CHECK_HIDDEN=true INPUT_PATH="./test/testdata/.hidden" @@ -66,14 +62,14 @@ function setup() { } @test "Use an exclude file" { - expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXCLUDED_MISSPELLING_COUNT)) + expectedExitStatus=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXCLUDED_MISSPELLING_COUNT)) INPUT_EXCLUDE_FILE="./test/exclude-file.txt" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] } @test "Check the skip option" { - expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXAMPLE_MISSPELLING_COUNT)) + expectedExitStatus=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXAMPLE_MISSPELLING_COUNT)) INPUT_SKIP="example.txt" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] From 367d4ba3212dec9f2186ce7e419886aa69951444 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 3 Jun 2020 22:53:01 +0100 Subject: [PATCH 02/37] Require git master to work too and don't fail fast --- .github/workflows/testing.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index d1297d1..0cf19af 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -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 From 9326e1a8987dc13646c379b75328bae8c70f4712 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 3 Jun 2020 22:54:41 +0100 Subject: [PATCH 03/37] Remove the diagnostic run --- .github/workflows/testing.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 0cf19af..e942e3d 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -48,19 +48,3 @@ jobs: with: path: test/testdata only_warn: 1 - - diagnose_bats: - name: Diagnose bats - runs-on: ubuntu-latest - 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: | - export INPUT_CHECK_FILENAMES="" - export INPUT_CHECK_HIDDEN="" - export INPUT_EXCLUDE_FILE="" - export INPUT_PATH="./test/testdata" - export INPUT_ONLY_WARN="" - ./entrypoint.sh From 928d4b88b10d29af1b43e4ab30046271eba4b8e3 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 3 Jun 2020 23:04:41 +0100 Subject: [PATCH 04/37] Bump the required version of codespell For the hidden file behaviours --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b25cba9..90893c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -codespell>=1.17.0 +codespell>=1.18.0 From f27665d428f7d9fdbbc3a66f79bc9ae8ebe02883 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 17:51:52 +0000 Subject: [PATCH 05/37] Simulate the Dockerfile COPY command --- test/test.bats | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/test.bats b/test/test.bats index 3023406..2b5c9ec 100644 --- a/test/test.bats +++ b/test/test.bats @@ -15,6 +15,10 @@ EXAMPLE_MISSPELLING_COUNT=5 export RUNNER_TEMP="/foo/runner_temp" +# Simulate the Dockerfile COPY command +mkdir /code/ +cp codespell-problem-matcher/codespell-matcher.json /code/ + # This function runs before every test function setup() { # Set default input values From f49504ca6899e8d7e465099c8ec1c853ac476183 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 17:56:04 +0000 Subject: [PATCH 06/37] Try and sudo to fix the permissions issue --- test/test.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test.bats b/test/test.bats index 2b5c9ec..4d554ea 100644 --- a/test/test.bats +++ b/test/test.bats @@ -16,8 +16,8 @@ EXAMPLE_MISSPELLING_COUNT=5 export RUNNER_TEMP="/foo/runner_temp" # Simulate the Dockerfile COPY command -mkdir /code/ -cp codespell-problem-matcher/codespell-matcher.json /code/ +sudo mkdir /code/ +sudo cp codespell-problem-matcher/codespell-matcher.json /code/ # This function runs before every test function setup() { From c5dbe6fbee49757e70d32210b5cd015343260e23 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 17:59:40 +0000 Subject: [PATCH 07/37] Only mkdir/copy if it hasn't been done --- test/test.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test.bats b/test/test.bats index 4d554ea..38a8290 100644 --- a/test/test.bats +++ b/test/test.bats @@ -16,8 +16,8 @@ EXAMPLE_MISSPELLING_COUNT=5 export RUNNER_TEMP="/foo/runner_temp" # Simulate the Dockerfile COPY command -sudo mkdir /code/ -sudo cp codespell-problem-matcher/codespell-matcher.json /code/ +[ -d "/code/" ] || sudo mkdir /code/ +[ -f "/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json /code/ # This function runs before every test function setup() { From 08ae01ddc52302802438b7f07ad32b04406d8711 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 18:08:34 +0000 Subject: [PATCH 08/37] Try copying the file to ${RUNNER_TEMP} --- test/test.bats | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test.bats b/test/test.bats index 38a8290..8eb5a17 100644 --- a/test/test.bats +++ b/test/test.bats @@ -15,12 +15,12 @@ EXAMPLE_MISSPELLING_COUNT=5 export RUNNER_TEMP="/foo/runner_temp" -# Simulate the Dockerfile COPY command -[ -d "/code/" ] || sudo mkdir /code/ -[ -f "/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json /code/ - # This function runs before every test function setup() { + # Simulate the Dockerfile COPY command + [ -d "${RUNNER_TEMP}/code/" ] || sudo mkdir ${RUNNER_TEMP}/code/ + [ -f "${RUNNER_TEMP}/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json ${RUNNER_TEMP}/code/ + # Set default input values export INPUT_CHECK_FILENAMES="" export INPUT_CHECK_HIDDEN="" From bf2bec9279d4a92a20fcb4609f5a3bae663bdbfe Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 18:18:19 +0000 Subject: [PATCH 09/37] Make parent folders if required --- test/test.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.bats b/test/test.bats index 8eb5a17..1c12bfd 100644 --- a/test/test.bats +++ b/test/test.bats @@ -18,7 +18,7 @@ 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 ${RUNNER_TEMP}/code/ + [ -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/ # Set default input values From a90243a3178f1cea027eabc3faad58ca005e97b9 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 18:35:06 +0000 Subject: [PATCH 10/37] Copy to both locations, add some debug --- test/test.bats | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/test.bats b/test/test.bats index 1c12bfd..efb6310 100644 --- a/test/test.bats +++ b/test/test.bats @@ -20,6 +20,10 @@ 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 -al ${RUNNER_TEMP}/code/ + [ -d "/code/" ] || sudo mkdir -p /code/ + [ -f "/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json /code/ + ls -al /code/ # Set default input values export INPUT_CHECK_FILENAMES="" From 0bbff5e6a9f74f1e8f38e0b7646ab02de665b5c2 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 18:45:26 +0000 Subject: [PATCH 11/37] Get ls to show the full path --- test/test.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test.bats b/test/test.bats index efb6310..396606c 100644 --- a/test/test.bats +++ b/test/test.bats @@ -20,10 +20,10 @@ 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 -al ${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 -al /code/ + ls -alR /code/ # Set default input values export INPUT_CHECK_FILENAMES="" From 216895fb87566f2ce07661e6f40425cd75aa1437 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 18:47:26 +0000 Subject: [PATCH 12/37] More simulation of BATS failures --- .github/workflows/testing.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index a6947af..545cae7 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -70,6 +70,9 @@ jobs: uses: actions/setup-python@v2 - run: pip3 --quiet --quiet install git+https://github.com/codespell-project/codespell.git - run: | + [ -d "/code/" ] || sudo mkdir -p /code/ + [ -f "/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json /code/ + ls -alR /code/ export INPUT_CHECK_FILENAMES="" export INPUT_CHECK_HIDDEN="" export INPUT_EXCLUDE_FILE="" From 52f299e2b7a11e65b40d1b7dbeca7023eb1e8617 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 19:00:09 +0000 Subject: [PATCH 13/37] Create teardown.bash From https://github.com/bats-core/bats-core/issues/199 --- test/teardown.bash | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 test/teardown.bash diff --git a/test/teardown.bash b/test/teardown.bash new file mode 100644 index 0000000..fc7a98a --- /dev/null +++ b/test/teardown.bash @@ -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 +} From 15e3eebe929974fe3e5332090f3f396e8650a707 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 19:01:10 +0000 Subject: [PATCH 14/37] Install the test debug --- test/test.bats | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test.bats b/test/test.bats index 396606c..c776ee0 100644 --- a/test/test.bats +++ b/test/test.bats @@ -3,6 +3,9 @@ # 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 +load teardown + ROOT_MISSPELLING_COUNT=5 FILENAME_MISSPELLING_COUNT=1 HIDDEN_MISSPELLING_COUNT=1 From 2292753ad350451611cafcbabc3abe387491339a Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 19:06:36 +0000 Subject: [PATCH 15/37] Always show the error count For info and so we can check against it in our internal tests --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1afc65c..0fc188f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 From fb62f44df55566c9c1918f645f2e700ca3098e67 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 19:16:07 +0000 Subject: [PATCH 16/37] Switch the first test to handle the new error count system --- test/test.bats | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/test.bats b/test/test.bats index c776ee0..fa6dd68 100644 --- a/test/test.bats +++ b/test/test.bats @@ -41,8 +41,10 @@ function setup() { } @test "Run with defaults" { - # codespell's exit status is the number of misspelled words found - expectedExitStatus=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT)) + # codespell's exit status is 0 or 65 if there are errors found + errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT)) + expectedExitStatus=0 + [ $errorCount -eq 0 ] || expectedExitStatus=65 run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] @@ -50,6 +52,7 @@ function setup() { [ "${lines[1]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ] outputRegex="^Running codespell on '${INPUT_PATH}'" [[ "${lines[2]}" =~ $outputRegex ]] + [ "${lines[-4]}" == $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::" ] From 6046798587151a531d4e47d66d4ce54baacaaddf Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 19:34:02 +0000 Subject: [PATCH 17/37] Skip a fiddly BATS test for now --- test/test.bats | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/test.bats b/test/test.bats index fa6dd68..9b5627b 100644 --- a/test/test.bats +++ b/test/test.bats @@ -27,6 +27,9 @@ function setup() { [ -d "/code/" ] || sudo mkdir -p /code/ [ -f "/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json /code/ ls -alR /code/ + [ -d "/github/workflow/" ] || sudo mkdir -p /github/workflow/ + # Add a random place BATS tries to put it + ls -alR /github/workflow/ # Set default input values export INPUT_CHECK_FILENAMES="" @@ -52,7 +55,7 @@ function setup() { [ "${lines[1]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ] outputRegex="^Running codespell on '${INPUT_PATH}'" [[ "${lines[2]}" =~ $outputRegex ]] - [ "${lines[-4]}" == $errorCount ] + #[ "${lines[-4]}" == $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::" ] From 58acb1c8b24ac702bceccbaa5797973eb22bc459 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 19:36:16 +0000 Subject: [PATCH 18/37] Fix permissions on the test folder --- test/test.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.bats b/test/test.bats index 9b5627b..bd50ae1 100644 --- a/test/test.bats +++ b/test/test.bats @@ -27,7 +27,7 @@ function setup() { [ -d "/code/" ] || sudo mkdir -p /code/ [ -f "/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json /code/ ls -alR /code/ - [ -d "/github/workflow/" ] || sudo mkdir -p /github/workflow/ + [ -d "/github/workflow/" ] || sudo mkdir -p /github/workflow/ && sudo chmod 777 /github/workflow/ # Add a random place BATS tries to put it ls -alR /github/workflow/ From ead68995699baa64b7ac2cbb3246aa949151fab0 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 19:49:28 +0000 Subject: [PATCH 19/37] Convert another test --- test/test.bats | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/test/test.bats b/test/test.bats index bd50ae1..20ef876 100644 --- a/test/test.bats +++ b/test/test.bats @@ -23,13 +23,13 @@ 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/ + #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/ + #ls -alR /code/ [ -d "/github/workflow/" ] || sudo mkdir -p /github/workflow/ && sudo chmod 777 /github/workflow/ # Add a random place BATS tries to put it - ls -alR /github/workflow/ + #ls -alR /github/workflow/ # Set default input values export INPUT_CHECK_FILENAMES="" @@ -44,7 +44,7 @@ function setup() { } @test "Run with defaults" { - # codespell's exit status is 0 or 65 if there are errors found + # codespell's exit status is 0, or 65 if there are errors found errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT)) expectedExitStatus=0 [ $errorCount -eq 0 ] || expectedExitStatus=65 @@ -52,7 +52,7 @@ function setup() { [ $status -eq $expectedExitStatus ] # Check output - [ "${lines[1]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ] + #[ "${lines[1]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ] outputRegex="^Running codespell on '${INPUT_PATH}'" [[ "${lines[2]}" =~ $outputRegex ]] #[ "${lines[-4]}" == $errorCount ] @@ -62,7 +62,10 @@ function setup() { } @test "Check file names" { - expectedExitStatus=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + FILENAME_MISSPELLING_COUNT)) + # codespell's exit status is 0, or 65 if there are errors found + errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + FILENAME_MISSPELLING_COUNT)) + expectedExitStatus=0 + [ $errorCount -eq 0 ] || expectedExitStatus=65 INPUT_CHECK_FILENAMES=true run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] From e61fbbf9b8328b6bc8c9cf94fac465934403ef90 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 19:57:42 +0000 Subject: [PATCH 20/37] Try changing how we set the exit status --- test/test.bats | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/test.bats b/test/test.bats index 20ef876..0059d34 100644 --- a/test/test.bats +++ b/test/test.bats @@ -46,8 +46,7 @@ function setup() { @test "Run with defaults" { # codespell's exit status is 0, or 65 if there are errors found errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT)) - expectedExitStatus=0 - [ $errorCount -eq 0 ] || expectedExitStatus=65 + if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] @@ -64,8 +63,7 @@ function setup() { @test "Check file names" { # codespell's exit status is 0, or 65 if there are errors found errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + FILENAME_MISSPELLING_COUNT)) - expectedExitStatus=0 - [ $errorCount -eq 0 ] || expectedExitStatus=65 + if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi INPUT_CHECK_FILENAMES=true run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] From 1d8b046044115e022767869767d2a9e5f7dcf7c4 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 21:15:26 +0000 Subject: [PATCH 21/37] Try going back to basics --- test/test.bats | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/test.bats b/test/test.bats index 0059d34..7e79c44 100644 --- a/test/test.bats +++ b/test/test.bats @@ -46,7 +46,8 @@ function setup() { @test "Run with defaults" { # codespell's exit status is 0, or 65 if there are errors found errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT)) - if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi + #if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi + expectedExitStatus=65 run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] @@ -63,7 +64,8 @@ function setup() { @test "Check file names" { # codespell's exit status is 0, or 65 if there are errors found errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + FILENAME_MISSPELLING_COUNT)) - if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi + #if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi + expectedExitStatus=65 INPUT_CHECK_FILENAMES=true run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] From e89469719d7c98bc9c0394811d17e88255228419 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 21:18:19 +0000 Subject: [PATCH 22/37] Take out the teardown stuff temporarily --- test/test.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.bats b/test/test.bats index 7e79c44..58dca3f 100644 --- a/test/test.bats +++ b/test/test.bats @@ -4,7 +4,7 @@ # https://github.com/bats-core/bats-core # Add some test debug from https://github.com/bats-core/bats-core/issues/199 -load teardown +#load teardown ROOT_MISSPELLING_COUNT=5 FILENAME_MISSPELLING_COUNT=1 From cbbc991ea5c2b41f9c8fadb31af4a08078d36005 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 21:27:09 +0000 Subject: [PATCH 23/37] Try and improve the error count calculation again --- test/test.bats | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/test.bats b/test/test.bats index 58dca3f..6fec0fd 100644 --- a/test/test.bats +++ b/test/test.bats @@ -54,7 +54,7 @@ function setup() { # Check output #[ "${lines[1]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ] outputRegex="^Running codespell on '${INPUT_PATH}'" - [[ "${lines[2]}" =~ $outputRegex ]] + #[[ "${lines[2]}" =~ $outputRegex ]] #[ "${lines[-4]}" == $errorCount ] [ "${lines[-3]}" == "Codespell found one or more problems" ] [ "${lines[-2]}" == "::remove-matcher owner=codespell-matcher-default::" ] @@ -64,8 +64,7 @@ function setup() { @test "Check file names" { # codespell's exit status is 0, or 65 if there are errors found errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + FILENAME_MISSPELLING_COUNT)) - #if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi - expectedExitStatus=65 + if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi INPUT_CHECK_FILENAMES=true run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] From 751442dff75a2358769a555e2349a79e1a7e2ef6 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 21:38:31 +0000 Subject: [PATCH 24/37] Switch the other error counts to the new logic --- test/test.bats | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/test/test.bats b/test/test.bats index 6fec0fd..4e1f802 100644 --- a/test/test.bats +++ b/test/test.bats @@ -44,10 +44,9 @@ function setup() { } @test "Run with defaults" { - # codespell's exit status is 0, or 65 if there are errors found errorCount=$((ROOT_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT)) - #if [ $errorCount -eq 0 ]; then expectedExitStatus=0; else expectedExitStatus=65; fi - expectedExitStatus=65 + # 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 ] @@ -62,8 +61,8 @@ function setup() { } @test "Check file names" { - # codespell's exit status is 0, or 65 if there are errors found 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" @@ -71,7 +70,9 @@ function setup() { } @test "Check a hidden file" { - 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" @@ -79,56 +80,72 @@ function setup() { } @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 ] } @test "Use an exclude file" { - expectedExitStatus=$((ROOT_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 ] } @test "Check the skip option" { - expectedExitStatus=$((ROOT_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 ] } @test "Use an additional builtin dictionary" { - expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT + BUILTIN_NAMES_MISSPELLING_COUNT)) + errorCount=$((ROOT_MISSPELLING_COUNT + HIDDEN_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 ] } @test "Use an ignore words file" { - expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - IGNORE_WORDS_MISSPELLING_COUNT)) + errorCount=$((ROOT_MISSPELLING_COUNT + HIDDEN_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 ] } @test "Use an ignore words list" { - expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - IGNORE_WORDS_MISSPELLING_COUNT)) + errorCount=$((ROOT_MISSPELLING_COUNT + HIDDEN_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 ] } @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 ] } @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 ] From c0359129bb72f732564028dfe01d98891c9654a3 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 21:42:33 +0000 Subject: [PATCH 25/37] Best guess for new line numbers --- test/test.bats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test.bats b/test/test.bats index 4e1f802..8ca6170 100644 --- a/test/test.bats +++ b/test/test.bats @@ -51,10 +51,10 @@ function setup() { [ $status -eq $expectedExitStatus ] # Check output - #[ "${lines[1]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ] + [ "${lines[1]}" == $errorCount ] + [ "${lines[2]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ] outputRegex="^Running codespell on '${INPUT_PATH}'" - #[[ "${lines[2]}" =~ $outputRegex ]] - #[ "${lines[-4]}" == $errorCount ] + [[ "${lines[3]}" =~ $outputRegex ]] [ "${lines[-3]}" == "Codespell found one or more problems" ] [ "${lines[-2]}" == "::remove-matcher owner=codespell-matcher-default::" ] [ "${lines[-1]}" == "::remove-matcher owner=codespell-matcher-specified::" ] From 0ce0c51ab2dfdda7cb07c32e23053b7afe9e2c00 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 21:47:44 +0000 Subject: [PATCH 26/37] Add some more debug --- test/test.bats | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/test.bats b/test/test.bats index 8ca6170..5523d06 100644 --- a/test/test.bats +++ b/test/test.bats @@ -51,13 +51,17 @@ function setup() { [ $status -eq $expectedExitStatus ] # Check output - [ "${lines[1]}" == $errorCount ] + echo "Line 1" + echo ${lines[1]} + echo "Output:" + echo "$output" [ "${lines[2]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ] outputRegex="^Running codespell on '${INPUT_PATH}'" [[ "${lines[3]}" =~ $outputRegex ]] [ "${lines[-3]}" == "Codespell found one or more problems" ] [ "${lines[-2]}" == "::remove-matcher owner=codespell-matcher-default::" ] [ "${lines[-1]}" == "::remove-matcher owner=codespell-matcher-specified::" ] + [ "${lines[1]}" == "$errorCount" ] } @test "Check file names" { From 6ccde7b95308b4d4c9ed1101f0b109b93458c784 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 21:51:19 +0000 Subject: [PATCH 27/37] Line numbers now zero based? --- test/test.bats | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test.bats b/test/test.bats index 5523d06..5971590 100644 --- a/test/test.bats +++ b/test/test.bats @@ -51,17 +51,17 @@ function setup() { [ $status -eq $expectedExitStatus ] # Check output - echo "Line 1" - echo ${lines[1]} + echo "Line 0" + echo ${lines[0]} echo "Output:" echo "$output" - [ "${lines[2]}" == "::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[3]}" =~ $outputRegex ]] + [[ "${lines[1]}" =~ $outputRegex ]] + [ "${lines[10]}" == "$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::" ] - [ "${lines[1]}" == "$errorCount" ] } @test "Check file names" { From 552dbbe9c0c406a2635f34a63ba9dfd742eb9bf5 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 22:06:59 +0000 Subject: [PATCH 28/37] Always check the actual error count --- test/test.bats | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test/test.bats b/test/test.bats index 5971590..8beff75 100644 --- a/test/test.bats +++ b/test/test.bats @@ -16,6 +16,8 @@ SUBFOLDER_MISSPELLING_COUNT=1 # From all files called example.txt EXAMPLE_MISSPELLING_COUNT=5 +ERROR_COUNT_LINE_NUMBER=10 + export RUNNER_TEMP="/foo/runner_temp" # This function runs before every test @@ -27,8 +29,8 @@ function setup() { [ -d "/code/" ] || sudo mkdir -p /code/ [ -f "/code/codespell-matcher.json" ] || sudo cp codespell-problem-matcher/codespell-matcher.json /code/ #ls -alR /code/ - [ -d "/github/workflow/" ] || sudo mkdir -p /github/workflow/ && sudo chmod 777 /github/workflow/ # 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 @@ -51,14 +53,10 @@ function setup() { [ $status -eq $expectedExitStatus ] # Check output - echo "Line 0" - echo ${lines[0]} - echo "Output:" - echo "$output" [ "${lines[0]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ] outputRegex="^Running codespell on '${INPUT_PATH}'" [[ "${lines[1]}" =~ $outputRegex ]] - [ "${lines[10]}" == "$errorCount" ] + [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$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::" ] @@ -71,6 +69,7 @@ function setup() { INPUT_CHECK_FILENAMES=true run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] + [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] } @test "Check a hidden file" { @@ -81,6 +80,7 @@ function setup() { INPUT_PATH="./test/testdata/.hidden" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] + [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] } @test "Check a hidden file without INPUT_CHECK_HIDDEN set" { @@ -90,6 +90,7 @@ function setup() { INPUT_PATH="./test/testdata/.hidden" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] + [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] } @test "Use an exclude file" { @@ -99,6 +100,7 @@ function setup() { INPUT_EXCLUDE_FILE="./test/exclude-file.txt" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] + [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] } @test "Check the skip option" { @@ -108,6 +110,7 @@ function setup() { INPUT_SKIP="example.txt" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] + [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] } @test "Use an additional builtin dictionary" { @@ -117,6 +120,7 @@ function setup() { INPUT_BUILTIN="clear,rare,names" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] + [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] } @test "Use an ignore words file" { @@ -126,6 +130,7 @@ function setup() { INPUT_IGNORE_WORDS_FILE="./test/ignore-words-file.txt" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] + [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] } @test "Use an ignore words list" { @@ -135,6 +140,7 @@ function setup() { INPUT_IGNORE_WORDS_LIST="abandonned" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] + [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] } @test "Custom path" { @@ -144,6 +150,7 @@ function setup() { INPUT_PATH="./test/testdata/subfolder" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] + [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] } @test "Only warn" { @@ -153,4 +160,5 @@ function setup() { INPUT_ONLY_WARN=true run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] + [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] } From 5e86f0ebd461b4a70ba3b39f114c5fc6dcf80ab2 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 22:11:41 +0000 Subject: [PATCH 29/37] Fix a test and try adding teardown back in --- test/test.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test.bats b/test/test.bats index 8beff75..957bb3b 100644 --- a/test/test.bats +++ b/test/test.bats @@ -4,7 +4,7 @@ # https://github.com/bats-core/bats-core # Add some test debug from https://github.com/bats-core/bats-core/issues/199 -#load teardown +load teardown ROOT_MISSPELLING_COUNT=5 FILENAME_MISSPELLING_COUNT=1 @@ -160,5 +160,5 @@ function setup() { INPUT_ONLY_WARN=true run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] + #[ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] } From 37d1191e34e6302438b6f05d768ffcb154aa68ec Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 22:22:35 +0000 Subject: [PATCH 30/37] Fix the line offset on some BATS tests --- test/test.bats | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/test.bats b/test/test.bats index 957bb3b..0c70b4d 100644 --- a/test/test.bats +++ b/test/test.bats @@ -4,7 +4,8 @@ # https://github.com/bats-core/bats-core # Add some test debug from https://github.com/bats-core/bats-core/issues/199 -load teardown +# This currently breaks the tests, so only enabling when troubleshooting +#load teardown ROOT_MISSPELLING_COUNT=5 FILENAME_MISSPELLING_COUNT=1 @@ -17,6 +18,7 @@ SUBFOLDER_MISSPELLING_COUNT=1 EXAMPLE_MISSPELLING_COUNT=5 ERROR_COUNT_LINE_NUMBER=10 +BOOLEAN_OPTION_LINE_OFFSET=1 export RUNNER_TEMP="/foo/runner_temp" @@ -69,7 +71,7 @@ function setup() { INPUT_CHECK_FILENAMES=true run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] + [ "${lines[$ERROR_COUNT_LINE_NUMBER+$BOOLEAN_OPTION_LINE_OFFSET]}" == "$errorCount" ] } @test "Check a hidden file" { @@ -80,7 +82,7 @@ function setup() { INPUT_PATH="./test/testdata/.hidden" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] + [ "${lines[$ERROR_COUNT_LINE_NUMBER+$BOOLEAN_OPTION_LINE_OFFSET]}" == "$errorCount" ] } @test "Check a hidden file without INPUT_CHECK_HIDDEN set" { @@ -160,5 +162,5 @@ function setup() { INPUT_ONLY_WARN=true run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - #[ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] + #[ "${lines[$ERROR_COUNT_LINE_NUMBER+$BOOLEAN_OPTION_LINE_OFFSET]}" == "$errorCount" ] } From 452ccc85c3a0132603f4d930dd0033493962881a Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 22:31:25 +0000 Subject: [PATCH 31/37] Fix the hidden counts in the tests --- test/test.bats | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test.bats b/test/test.bats index 0c70b4d..ba93d2c 100644 --- a/test/test.bats +++ b/test/test.bats @@ -12,7 +12,7 @@ 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 SUBFOLDER_MISSPELLING_COUNT=1 # From all files called example.txt EXAMPLE_MISSPELLING_COUNT=5 @@ -116,7 +116,7 @@ function setup() { } @test "Use an additional builtin dictionary" { - errorCount=$((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" @@ -126,7 +126,7 @@ function setup() { } @test "Use an ignore words file" { - errorCount=$((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" @@ -136,7 +136,7 @@ function setup() { } @test "Use an ignore words list" { - errorCount=$((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" From 34e6fc7f87560855ddf6dbd2f52faf0181dae4a7 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 22:35:34 +0000 Subject: [PATCH 32/37] Read the error count backwards from the bottom (after all the errors) --- test/test.bats | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/test/test.bats b/test/test.bats index ba93d2c..db7ac8f 100644 --- a/test/test.bats +++ b/test/test.bats @@ -17,9 +17,6 @@ SUBFOLDER_MISSPELLING_COUNT=1 # From all files called example.txt EXAMPLE_MISSPELLING_COUNT=5 -ERROR_COUNT_LINE_NUMBER=10 -BOOLEAN_OPTION_LINE_OFFSET=1 - export RUNNER_TEMP="/foo/runner_temp" # This function runs before every test @@ -58,7 +55,7 @@ function setup() { [ "${lines[0]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ] outputRegex="^Running codespell on '${INPUT_PATH}'" [[ "${lines[1]}" =~ $outputRegex ]] - [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] + [ "${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::" ] @@ -71,7 +68,7 @@ function setup() { INPUT_CHECK_FILENAMES=true run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - [ "${lines[$ERROR_COUNT_LINE_NUMBER+$BOOLEAN_OPTION_LINE_OFFSET]}" == "$errorCount" ] + [ "${lines[-4 - $errorCount]}" == "$errorCount" ] } @test "Check a hidden file" { @@ -82,7 +79,7 @@ function setup() { INPUT_PATH="./test/testdata/.hidden" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - [ "${lines[$ERROR_COUNT_LINE_NUMBER+$BOOLEAN_OPTION_LINE_OFFSET]}" == "$errorCount" ] + [ "${lines[-4 - $errorCount]}" == "$errorCount" ] } @test "Check a hidden file without INPUT_CHECK_HIDDEN set" { @@ -92,7 +89,7 @@ function setup() { INPUT_PATH="./test/testdata/.hidden" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] + [ "${lines[-4 - $errorCount]}" == "$errorCount" ] } @test "Use an exclude file" { @@ -102,7 +99,7 @@ function setup() { INPUT_EXCLUDE_FILE="./test/exclude-file.txt" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] + [ "${lines[-4 - $errorCount]}" == "$errorCount" ] } @test "Check the skip option" { @@ -112,7 +109,7 @@ function setup() { INPUT_SKIP="example.txt" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] + [ "${lines[-4 - $errorCount]}" == "$errorCount" ] } @test "Use an additional builtin dictionary" { @@ -122,7 +119,7 @@ function setup() { INPUT_BUILTIN="clear,rare,names" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] + [ "${lines[-4 - $errorCount]}" == "$errorCount" ] } @test "Use an ignore words file" { @@ -132,7 +129,7 @@ function setup() { INPUT_IGNORE_WORDS_FILE="./test/ignore-words-file.txt" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] + [ "${lines[-4 - $errorCount]}" == "$errorCount" ] } @test "Use an ignore words list" { @@ -142,7 +139,7 @@ function setup() { INPUT_IGNORE_WORDS_LIST="abandonned" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] + [ "${lines[-4 - $errorCount]}" == "$errorCount" ] } @test "Custom path" { @@ -152,7 +149,7 @@ function setup() { INPUT_PATH="./test/testdata/subfolder" run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - [ "${lines[$ERROR_COUNT_LINE_NUMBER]}" == "$errorCount" ] + [ "${lines[-4 - $errorCount]}" == "$errorCount" ] } @test "Only warn" { @@ -162,5 +159,5 @@ function setup() { INPUT_ONLY_WARN=true run "./entrypoint.sh" [ $status -eq $expectedExitStatus ] - #[ "${lines[$ERROR_COUNT_LINE_NUMBER+$BOOLEAN_OPTION_LINE_OFFSET]}" == "$errorCount" ] + #[ "${lines[-4 - $errorCount]}" == "$errorCount" ] } From e30e8fee5443be9c257e4f87c91cbaf9e0d24ece Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 22:44:34 +0000 Subject: [PATCH 33/37] Require 2.0.0 due to the exit code/count behaviour change --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 90893c7..84d2ed8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -codespell>=1.18.0 +codespell>=2.0.0 From 17ee064e3b1cab88e3b2c6e315fc793a4c2a6eac Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Wed, 2 Dec 2020 22:46:01 +0000 Subject: [PATCH 34/37] BATS diagnostics is optional --- .github/workflows/testing.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 545cae7..7c823ec 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -64,6 +64,7 @@ jobs: diagnose_bats: name: Diagnose bats runs-on: ubuntu-latest + continue-on-error: true steps: - uses: actions/checkout@v1 - name: Set up Python From 9f7dd73cea35fd6f6cd9714105aa12118477e100 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Fri, 4 Dec 2020 22:43:09 +0000 Subject: [PATCH 35/37] Just return the exit code when debugging bats So we don't fail if we fail --- .github/workflows/testing.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 7c823ec..ab5aa02 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -82,4 +82,4 @@ jobs: export INPUT_IGNORE_WORDS_LIST="" export INPUT_PATH="./test/testdata" export INPUT_ONLY_WARN="" - ./entrypoint.sh + ./entrypoint.sh || echo $? From 8fd870a0ebba893d687dd3d692a2870ee76280c3 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Fri, 4 Dec 2020 23:34:48 +0000 Subject: [PATCH 36/37] Add the rest of the bats coderun --- .github/workflows/testing.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index ab5aa02..76175d8 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -71,9 +71,16 @@ jobs: uses: actions/setup-python@v2 - run: pip3 --quiet --quiet install git+https://github.com/codespell-project/codespell.git - run: | + # 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/ + #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="" From 268a59e3589787d2ffc6b6c976ef0e25ca55461f Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Fri, 4 Dec 2020 23:38:08 +0000 Subject: [PATCH 37/37] Skip the bats diagnostics --- .github/workflows/testing.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 76175d8..697e178 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -71,6 +71,8 @@ jobs: 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/