-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from per1234/bats-tests
Add Bats tests for script
- Loading branch information
Showing
10 changed files
with
120 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1 abandonned 1 | ||
2 abandonned 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
abandonned |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
abandoned |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
abandonned | ||
1 abandonned 1 | ||
Abandonned | ||
ABANDONNED | ||
AbAnDoNnEd |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
abandonned |