Skip to content

Commit 879b6d3

Browse files
committed
Add some more detailed tests
1 parent e9a1237 commit 879b6d3

6 files changed

Lines changed: 36 additions & 15 deletions

File tree

.buildkite/pipeline.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash
2-
32
set -eu
43

54
# If you build HEAD the pipeline.sh step, because it runs first, won't yet
@@ -22,7 +21,7 @@ steps:
2221
2322
- label: run shellcheck
2423
plugins:
25-
${BUILDKITE_REPO}#${commit}:
24+
shellcheck#${commit}:
2625
files:
2726
- hooks/*
2827
- buildkite/*.sh

hooks/command

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,22 @@ function plugin_read_list() {
1919
fi
2020
}
2121

22+
IFS=$'\n\t'
2223
files=()
2324

24-
for pattern in $(plugin_read_list FILES) ; do
25-
while IFS=$'\n' read -r line; do
26-
files+=("$line")
27-
done < <(ls -1 "$pattern" 2>/dev/null)
25+
# Evaluate all the globs and return the files that exist
26+
for file in $(plugin_read_list FILES) ; do
27+
if [[ -e $file ]] ; then
28+
files+=("$file")
29+
fi
2830
done
2931

3032
if [[ -z ${files:-} ]] ; then
3133
echo "No files found to shellcheck"
3234
exit 1
3335
fi
3436

35-
docker run --rm -v "$PWD:/mnt" koalaman/shellcheck "${files[@]}"
37+
echo "+++ Running shellcheck on ${#files[@]} files"
38+
if docker run --rm -v "$PWD:/mnt" koalaman/shellcheck "${files[@]}" ; then
39+
echo "Files are ok ✅"
40+
fi

tests/run.bats

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,34 @@
22

33
load '/usr/local/lib/bats/load.bash'
44

5-
export DOCKER_STUB_DEBUG=/dev/tty
6-
export LS_STUB_DEBUG=/dev/tty
5+
# export DOCKER_STUB_DEBUG=/dev/tty
76

87
@test "Shellcheck a single file" {
9-
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="llamas.sh"
8+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/test.sh"
109

11-
stub ls \
12-
"-1 llamas.sh : echo llamas.sh"
10+
stub docker \
11+
"run --rm -v $PWD:/mnt koalaman/shellcheck tests/testdata/test.sh : echo testing test.sh"
12+
13+
run "$PWD/hooks/command"
14+
15+
assert_success
16+
assert_output --partial "testing test.sh"
17+
18+
unstub docker
19+
}
20+
21+
@test "Shellcheck multiple files" {
22+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_0="tests/testdata/test.sh"
23+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_1="tests/testdata/subdir/*"
24+
export BUILDKITE_PLUGIN_SHELLCHECK_FILES_2="missing"
1325

1426
stub docker \
15-
"run --rm -v $PWD:/mnt koalaman/shellcheck llamas.sh : echo testing llamas.sh"
27+
"run --rm -v $PWD:/mnt koalaman/shellcheck tests/testdata/test.sh tests/testdata/subdir/llamas.sh tests/testdata/subdir/shell\ with\ space.sh' : echo testing test.sh"
1628

1729
run "$PWD/hooks/command"
1830

1931
assert_success
20-
assert_output --partial "testing llamas.sh"
32+
assert_output --partial "testing test.sh"
2133

22-
unstub ls
2334
unstub docker
2435
}

tests/testdata/subdir/llamas.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
echo $UNDEFINED_VAR
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
echo "Ain't nobody likes spaces in filenames"

tests/testdata/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
echo blah

0 commit comments

Comments
 (0)