Merge pull request #7 from per1234/bats-tests
Add Bats tests for script
This commit is contained in:
@@ -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
@@ -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
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
1 abandonned 1
|
||||
2 abandonned 2
|
||||
@@ -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 ]
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
abandonned
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
abandoned
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
abandonned
|
||||
1 abandonned 1
|
||||
Abandonned
|
||||
ABANDONNED
|
||||
AbAnDoNnEd
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
abandonned
|
||||
Reference in New Issue
Block a user