Merge pull request #7 from per1234/bats-tests

Add Bats tests for script
This commit is contained in:
Peter Newman
2020-05-30 16:43:38 +01:00
committed by GitHub
10 changed files with 120 additions and 4 deletions
+27 -1
View File
@@ -3,6 +3,32 @@ name: Testing
on: [push, pull_request]
jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v2
- name: Install codespell
run: pip3 --quiet --quiet install codespell
- name: Install Bats
run: |
git clone --quiet https://github.com/bats-core/bats-core.git
cd bats-core
git fetch --tags
# Checkout the latest tag
git checkout --quiet $(git describe --tags `git rev-list --tags --max-count=1`)
sudo ./install.sh "/usr/local" > /dev/null
- name: Run Bats tests
run: bats "./test"
run_action:
name: Test run action
runs-on: ubuntu-latest
@@ -10,5 +36,5 @@ jobs:
- uses: actions/checkout@v1
- uses: ./
with:
path: example
path: test/testdata
only_warn: 1
+3 -2
View File
@@ -33,8 +33,9 @@ else
echo "Codespell found one or more problems"
fi
# Remove the matcher, so no other jobs hit it.
echo "::remove-matcher owner=codespell::"
# Remove the matchers, so no other jobs hit them.
echo "::remove-matcher owner=codespell-matcher-default::"
echo "::remove-matcher owner=codespell-matcher-specified::"
# If we are in warn-only mode, return always as if we pass
if [ -n "${INPUT_ONLY_WARN}" ]; then
+2
View File
@@ -0,0 +1,2 @@
1 abandonned 1
2 abandonned 2
+84
View File
@@ -0,0 +1,84 @@
#!/usr/bin/env bats
# Tests using the Bats testing framework
# https://github.com/bats-core/bats-core
ROOT_MISSPELLING_COUNT=5
FILENAME_MISSPELLING_COUNT=1
HIDDEN_MISSPELLING_COUNT=1
EXCLUDED_MISSPELLING_COUNT=1
SUBFOLDER_MISSPELLING_COUNT=1
export RUNNER_TEMP="/foo/runner_temp"
# This function runs before every test
function setup() {
# Set default input values
export INPUT_CHECK_FILENAMES=""
export INPUT_CHECK_HIDDEN=""
export INPUT_EXCLUDE_FILE=""
export INPUT_PATH="./test/testdata"
export INPUT_ONLY_WARN=""
}
@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))
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
# Check output
[ "${lines[1]}" == "::add-matcher::${RUNNER_TEMP}/_github_workflow/codespell-matcher.json" ]
outputRegex="^Running codespell on '${INPUT_PATH}'"
[[ "${lines[2]}" =~ $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::" ]
}
@test "Check file names" {
expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_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"
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
}
@test "Check a hidden file without INPUT_CHECK_HIDDEN set" {
expectedExitStatus=0
INPUT_PATH="./test/testdata/.hidden"
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
}
@test "Use an exclude file" {
expectedExitStatus=$((ROOT_MISSPELLING_COUNT + HIDDEN_MISSPELLING_COUNT + SUBFOLDER_MISSPELLING_COUNT - EXCLUDED_MISSPELLING_COUNT))
INPUT_EXCLUDE_FILE="./test/exclude-file.txt"
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
}
@test "Custom path" {
expectedExitStatus=$((SUBFOLDER_MISSPELLING_COUNT))
INPUT_PATH="./test/testdata/subfolder"
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
}
@test "Only warn" {
expectedExitStatus=0
INPUT_ONLY_WARN=true
run "./entrypoint.sh"
[ $status -eq $expectedExitStatus ]
}
+1
View File
@@ -0,0 +1 @@
abandonned
+1
View File
@@ -0,0 +1 @@
abandoned
View File
+1 -1
View File
@@ -1,4 +1,4 @@
abandonned
1 abandonned 1
Abandonned
ABANDONNED
AbAnDoNnEd
+1
View File
@@ -0,0 +1 @@
abandonned