...
 
Commits (5)
#!/bin/sh
# Examples of indenting code blocks.
# @Test
idle_secs=3
......
#!/bin/sh
# Example of line continuations.
# @Test
path="${1:-.}"
......
#!/bin/bash
# Example of performing arithmetics.
# shellcheck disable=SC2003,SC2219
# @Test
a=1
b=10
......
#!/bin/sh
# Example for assignment of values.
# @Test
# Example for appending to a variable.
......
......@@ -2,6 +2,7 @@
# Example for here-documents using shell quoting mechanisms.
# Note: The sample output was generated with
# echo foobar | figlet
# @Test single-quote
default_type="none"
......
#!/bin/sh -e
# Example of setting shell options using shebang commandline or set command.
# @Test
=======
# Setting shell options using shebang commandline or `set`.
set -x
......
......@@ -13,5 +13,8 @@ shopt -s failglob
echo "search=\"$search\"; executing \"echo \$search\" (with bash option \"failglob\")"
echo $search
exit 0
# @Test
# syntastic=off
# vim: ai et sts=4 ts=4 sw=4
#!/bin/bash
# Example using sed and Bash arrays to parse single-letter-options.
# @Test -foo bar
# Enable extended patterns.
shopt -s extglob
......
......@@ -17,6 +17,17 @@ at_exit() {
fi
}
file2testparams() {
awk '
/^#[ \t]*@Test([ \t]*|$)/ {
sub("^#[ \t]*@Test[ \t]*", "")
print
lines++
}
END { if (lines==0) { exit 1 } }
' < "$1"
}
trap at_exit EXIT
if ! cd "$dir" ; then
......@@ -25,7 +36,7 @@ if ! cd "$dir" ; then
fi
for script in [0-9]*/[0-9]*sh ; do
if grep -q "^# syntastic=off$" "$script" ; then
if grep -q '^# syntastic=off$' "$script" ; then
echo "Warning: Skipping Shellcheck of \"$script\"." >&2
elif ! shellcheck "$script" ; then
echo "Error: ShellCheck of \"$script\" failed." >&2
......@@ -39,16 +50,30 @@ for script in [0-9]*/[0-9]*sh ; do
;;
*.bash|*.sh)
if ! test -x "$script" ; then
echo "Info: Skipping non-executable \"$script\"." >&2
fi
echo "Warning: Skipping non-executable \"$script\"." >&2
else
testparams="$(file2testparams "$script")"
test_rv=$?
if test "$test_rv" = "0" ; then
# shellcheck disable=SC2086
if "$script" $testparams ; then
echo "Info: \"$script $testparams\" successful."
else
echo "Error: \"$script $testparams\" failed."
testscript="tests/$script.t.sh"
RV=1
fi
else
testscript="tests/$script.t.sh"
if test -f "$testscript" && test -x "$testscript" ; then
if ! "$testscript" "$script" ; then
echo "Error: Unit test of \"$script\" failed." >&2
if test -f "$testscript" && test -x "$testscript" ; then
if ! "$testscript" "$script" ; then
echo "Error: Unit test of \"$script\" failed." >&2
RV=1
RV=1
fi
fi
fi
fi
;;
......