Skip to content

Commit 0e2bfa1

Browse files
committed
Added tests (+ should actually work now)
1 parent 0aa6d72 commit 0e2bfa1

2 files changed

Lines changed: 53 additions & 2 deletions

File tree

hooks/command

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
set -eu -o pipefail
2+
set -eux -o pipefail
33

44
# Reads either a value or a list from plugin config
55
function plugin_read_list() {
@@ -41,7 +41,7 @@ if [[ -z ${files:-} ]] ; then
4141
fi
4242

4343
echo "+++ Running shellcheck on ${#files[@]} files"
44-
if docker run --rm -v "$PWD:/mnt" --workdir "/mnt" koalaman/shellcheck "${options[@]}" "${files[@]}" ; then
44+
if docker run --rm -v "$PWD:/mnt" --workdir "/mnt" koalaman/shellcheck "${options[@]+${options[@]}}" "${files[@]}" ; then
4545
echo "Files are ok ✅"
4646
else
4747
exit 1

tests/run.bats

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,57 @@ load '/usr/local/lib/bats/load.bash'
3434
unstub docker
3535
}
3636

37+
@test "Shellcheck a single file with single option" {
38+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/subdir/llamas.sh"
39+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_0="--exclude=SC2086"
40+
41+
stub docker \
42+
"run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck --exclude=SC2086 tests/testdata/subdir/llamas.sh : echo testing llamas.sh"
43+
44+
run "$PWD/hooks/command"
45+
46+
assert_success
47+
assert_output --partial "testing llamas.sh"
48+
49+
unstub docker
50+
}
51+
52+
@test "Shellcheck a single file with multiple options" {
53+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/subdir/llamas.sh"
54+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_0="--exclude=SC2086"
55+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_1="--format=gcc"
56+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_2="-x"
57+
58+
stub docker \
59+
"run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck --exclude=SC2086 --format=gcc -x tests/testdata/subdir/llamas.sh : echo testing llamas.sh"
60+
61+
run "$PWD/hooks/command"
62+
63+
assert_success
64+
assert_output --partial "testing llamas.sh"
65+
66+
unstub docker
67+
}
68+
69+
@test "Shellcheck multiple files with multiple options" {
70+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/test.sh"
71+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_1="tests/testdata/subdir/*"
72+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_2="missing"
73+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_0="--exclude=SC2086"
74+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_1="--format=gcc"
75+
export BUILDKITE_PLUGIN_SHELLCHECK_OPTIONS_2="-x"
76+
77+
stub docker \
78+
"run --rm -v $PWD:/mnt --workdir /mnt koalaman/shellcheck --exclude=SC2086 --format=gcc -x tests/testdata/test.sh tests/testdata/subdir/llamas.sh tests/testdata/subdir/shell\ with\ space.sh' : echo testing test.sh"
79+
80+
run "$PWD/hooks/command"
81+
82+
assert_success
83+
assert_output --partial "testing test.sh"
84+
85+
unstub docker
86+
}
87+
3788
@test "Shellcheck failure" {
3889
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/subdir/llamas.sh"
3990

0 commit comments

Comments
 (0)