Added basic tests
This commit is contained in:
Executable
+37
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
pass=0
|
||||
fail=0
|
||||
|
||||
EXTRA_SHELLCHECK_OPTS="${SHELLCHECK_OPTS:-}"
|
||||
|
||||
shellcheck_tmpl() {
|
||||
local tmpl=$1
|
||||
# Strip Go template tags ({{ ... }} and {{- ... -}}) into whitespace
|
||||
# so shellcheck can parse the remaining bash.
|
||||
local cleaned
|
||||
cleaned=$(sed 's/{{[-]*[^}]*[-]*}}/true/g' "$tmpl")
|
||||
|
||||
local tmpfile
|
||||
tmpfile=$(mktemp)
|
||||
printf '%s\n' "$cleaned" > "$tmpfile"
|
||||
|
||||
if shellcheck $EXTRA_SHELLCHECK_OPTS "$tmpfile"; then
|
||||
echo " PASS $tmpl"
|
||||
pass=$((pass + 1))
|
||||
else
|
||||
echo " FAIL $tmpl"
|
||||
fail=$((fail + 1))
|
||||
fi
|
||||
rm -f "$tmpfile"
|
||||
}
|
||||
|
||||
echo "=== ShellCheck ==="
|
||||
for f in "$@"; do
|
||||
[ -f "$f" ] && shellcheck_tmpl "$f"
|
||||
done
|
||||
|
||||
echo "---"
|
||||
echo "Passed: $pass Failed: $fail"
|
||||
[ "$fail" -eq 0 ]
|
||||
Reference in New Issue
Block a user