Commit cbb212e1 authored by Tilman Kranz's avatar Tilman Kranz

added test annotations

parent 97b47ae0
#!/bin/sh #!/bin/sh
# Indenting code blocks. # Indenting code blocks.
# @Test
idle_secs=3 idle_secs=3
...@@ -74,4 +73,5 @@ count() { ...@@ -74,4 +73,5 @@ count() {
count $idle_secs count $idle_secs
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
#!/bin/sh #!/bin/sh
# Breaking long lines with continuations. # Breaking long lines with continuations.
# @Test
path="${1:-.}" path="${1:-.}"
...@@ -11,7 +10,12 @@ find \ ...@@ -11,7 +10,12 @@ find \
\! -name '.git*' \ \! -name '.git*' \
-exec ls -ld "{}" \; -exec ls -ld "{}" \;
echo "Available space:\ echo "Available space: \
$( LC_ALL=C df -h .. | awk 'NR==2{print $4}')" $(
LC_ALL=C \
df -h .. |
awk 'NR==2{print $4}'
)"
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
#!/bin/bash #!/bin/bash
# Example of performing arithmetics. # Example of performing arithmetics.
# shellcheck disable=SC2003,SC2219 # shellcheck disable=SC2003,SC2219
# @Test
a=1 a=1
b=10 b=10
...@@ -29,4 +28,5 @@ echo "bc -l: $b / $a = $(echo "$b/$a" | bc -l)" ...@@ -29,4 +28,5 @@ echo "bc -l: $b / $a = $(echo "$b/$a" | bc -l)"
# Using bc(1) (with max. precision). # Using bc(1) (with max. precision).
echo "bc -l (scale=2): $b / $a = $(echo "scale=2; $b/$a" | bc -l)" echo "bc -l (scale=2): $b / $a = $(echo "scale=2; $b/$a" | bc -l)"
# @Test
# vim: ai et sts=4 ts=4 sw=4 nospell # vim: ai et sts=4 ts=4 sw=4 nospell
#!/bin/sh #!/bin/sh
# Assigning values to variables. # Assigning values to variables.
# @Test
# Example for appending to a variable. # Example for appending to a variable.
...@@ -41,5 +40,6 @@ touch $filename ...@@ -41,5 +40,6 @@ touch $filename
cd "$oldpwd" cd "$oldpwd"
# @Test
# syntastic=off # syntastic=off
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
# Generating output using quoting or here-documents. # Generating output using quoting or here-documents.
# Note: The sample output was generated with # Note: The sample output was generated with
# echo foobar | figlet # echo foobar | figlet
# @Test single-quote
default_type="none" default_type="none"
...@@ -68,5 +67,6 @@ EOF ...@@ -68,5 +67,6 @@ EOF
;; ;;
esac esac
# @Test single-quote
# syntastic=off # syntastic=off
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -27,3 +27,5 @@ fi ...@@ -27,3 +27,5 @@ fi
set -e set -e
cd "$workdir" cd "$workdir"
# @Test
# @TestRv 2
...@@ -10,4 +10,5 @@ name=$(basename "$0" .sh) ...@@ -10,4 +10,5 @@ name=$(basename "$0" .sh)
debug 'Hello, world.' debug 'Hello, world.'
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -15,4 +15,5 @@ b=4 ...@@ -15,4 +15,5 @@ b=4
sum_from_to $a $b sum_from_to $a $b
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -14,4 +14,5 @@ b=7 ...@@ -14,4 +14,5 @@ b=7
echo "The sum of integers from $a to $b is $(sum $a $b)." echo "The sum of integers from $a to $b is $(sum $a $b)."
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -7,4 +7,5 @@ word_filter() { ...@@ -7,4 +7,5 @@ word_filter() {
echo "Hello, world." | word_filter "hi" echo "Hello, world." | word_filter "hi"
echo "Hi, world." | word_filter "hi" echo "Hi, world." | word_filter "hi"
# @Test
# vim: ai et sts=4 ts=4 sw=4 nospell # vim: ai et sts=4 ts=4 sw=4 nospell
...@@ -12,4 +12,5 @@ word_filter_2() { ...@@ -12,4 +12,5 @@ word_filter_2() {
echo "Hi, world." | word_filter_2 "hi" || echo "Invalid input for word_filter_2." echo "Hi, world." | word_filter_2 "hi" || echo "Invalid input for word_filter_2."
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -8,4 +8,5 @@ word_filter_3() { ...@@ -8,4 +8,5 @@ word_filter_3() {
echo "Hi, world." | word_filter_3 "hi" || echo "Invalid input for word_filter_3." echo "Hi, world." | word_filter_3 "hi" || echo "Invalid input for word_filter_3."
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -35,4 +35,5 @@ test_format_args 'Argument Nummer %d: "%s"\n' "$@" ...@@ -35,4 +35,5 @@ test_format_args 'Argument Nummer %d: "%s"\n' "$@"
echo "Main program: counter=$counter" echo "Main program: counter=$counter"
echo "Main program: format=\"$format\"" echo "Main program: format=\"$format\""
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -21,5 +21,6 @@ foo() { echo "In function foo(): FOO=$FOO" ; } ...@@ -21,5 +21,6 @@ foo() { echo "In function foo(): FOO=$FOO" ; }
FOO=bar foo FOO=bar foo
echo "In main program: FOO=$FOO" echo "In main program: FOO=$FOO"
# @Test
# syntastic=off # syntastic=off
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
#!/bin/bash #!/bin/bash
# Example of local variables in Bash. # Using local variables in Bash.
test1() { test1() {
FOO=foo_test1 FOO=foo_test1
...@@ -33,4 +33,5 @@ FOO=foo ...@@ -33,4 +33,5 @@ FOO=foo
test3 test3
echo "In main program: FOO=$FOO" echo "In main program: FOO=$FOO"
# @Test
# vim: ai et sts=4 ts=4 sw=4 nospell # vim: ai et sts=4 ts=4 sw=4 nospell
...@@ -24,4 +24,5 @@ done ...@@ -24,4 +24,5 @@ done
echo "In main program: sum=$sum" echo "In main program: sum=$sum"
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -21,4 +21,5 @@ echo ...@@ -21,4 +21,5 @@ echo
echo '--' echo '--'
# @Test
# vim: ai et sts=4 ts=4 sw=4 nospell # vim: ai et sts=4 ts=4 sw=4 nospell
...@@ -57,5 +57,6 @@ done ...@@ -57,5 +57,6 @@ done
cd "$oldpwd" cd "$oldpwd"
# @Test foo "bar baz" --blah
# syntastic=off # syntastic=off
# vim: ai et sts=4 ts=4 sw=4 nospell # vim: ai et sts=4 ts=4 sw=4 nospell
...@@ -35,4 +35,5 @@ echo "Result:" ...@@ -35,4 +35,5 @@ echo "Result:"
echo "* path=\"$path\"" echo "* path=\"$path\""
echo "* arg=\"$arg\"" echo "* arg=\"$arg\""
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
#!/bin/bash #!/bin/bash
# Using sed and Bash arrays to parse single-letter-options. # Using sed and Bash arrays to parse single-letter-options.
# @Test -foo bar
# Enable extended patterns. # Enable extended patterns.
shopt -s extglob shopt -s extglob
...@@ -59,5 +58,6 @@ test $f = 1 && test $o = 2 && ...@@ -59,5 +58,6 @@ test $f = 1 && test $o = 2 &&
echo "$argument" | figlet -f lean echo "$argument" | figlet -f lean
done done
# @Test -foo bar
# syntastic=off # syntastic=off
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -14,4 +14,5 @@ for i in $(seq 1 10) ; do ...@@ -14,4 +14,5 @@ for i in $(seq 1 10) ; do
echo "Hello world #$i" echo "Hello world #$i"
done done
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
#!/bin/sh #!/bin/sh
# Appending script output to a logfile, repeating to standard output. # Appending output to a logfile, repeating to standard output.
NAME="$(basename "$0" .sh)" NAME="$(basename "$0" .sh)"
LOGFILE=$(mktemp) LOGFILE=$(mktemp)
...@@ -14,4 +14,5 @@ log "Operation started (LOGFILE=\"$LOGFILE\")." ...@@ -14,4 +14,5 @@ log "Operation started (LOGFILE=\"$LOGFILE\")."
log "Operation finished." log "Operation finished."
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
#!/bin/bash #!/bin/bash
# Example switching stdout and stderr to capture output of a function. # Switching stdout and stderr to capture output of a function.
read_password() { read_password() {
maxlen="${1:-5}" maxlen="${1:-5}"
...@@ -41,4 +41,5 @@ password=$(read_password 6) ...@@ -41,4 +41,5 @@ password=$(read_password 6)
echo "Done: password=\"$password\"" echo "Done: password=\"$password\""
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
#!/bin/bash #!/bin/bash
# Example using Bash'S PIPESTATUS array. # Using Bash'S PIPESTATUS array.
# Perform three tests #1, #2 and #3 on stdin using grep. # Perform three tests #1, #2 and #3 on stdin using grep.
# If one of the test fails, report its number on stderr. # If one of the test fails, report its number on stderr.
...@@ -30,4 +30,5 @@ echo "foo bla baz" | check_input ...@@ -30,4 +30,5 @@ echo "foo bla baz" | check_input
echo "baz foo bar" | check_input echo "baz foo bar" | check_input
echo "zeb foo bar" | check_input echo "zeb foo bar" | check_input
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -17,4 +17,5 @@ find "$path" -type f | ...@@ -17,4 +17,5 @@ find "$path" -type f |
echo "counter=$counter" echo "counter=$counter"
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -28,4 +28,5 @@ echo "counter=$counter" ...@@ -28,4 +28,5 @@ echo "counter=$counter"
rm -rf "$fifodir" rm -rf "$fifodir"
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -16,4 +16,5 @@ done < <( ...@@ -16,4 +16,5 @@ done < <(
echo "counter=$counter" echo "counter=$counter"
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -22,4 +22,5 @@ echo "counter=$counter" ...@@ -22,4 +22,5 @@ echo "counter=$counter"
rm "$listfile" rm "$listfile"
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -117,4 +117,5 @@ init_attrs ...@@ -117,4 +117,5 @@ init_attrs
ok 'This is good' ok 'This is good'
fail 'This is bad' fail 'This is bad'
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -85,4 +85,5 @@ show_box "$(echo "$text" | figlet)" ...@@ -85,4 +85,5 @@ show_box "$(echo "$text" | figlet)"
${FALLBACK:-false} || read -r input ${FALLBACK:-false} || read -r input
reset_terminal reset_terminal
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -25,4 +25,5 @@ done ...@@ -25,4 +25,5 @@ done
tput sgr0 tput sgr0
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -3,4 +3,5 @@ ...@@ -3,4 +3,5 @@
ps -eo cmd --no-headers | awk '!/^\[/ { print }' ps -eo cmd --no-headers | awk '!/^\[/ { print }'
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -3,4 +3,5 @@ ...@@ -3,4 +3,5 @@
ps -eo cmd --no-headers| sed -e '/^\[/d' ps -eo cmd --no-headers| sed -e '/^\[/d'
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -44,4 +44,5 @@ find "$path" -type f | ...@@ -44,4 +44,5 @@ find "$path" -type f |
' '
done done
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -8,4 +8,5 @@ find "$path" -type f | ...@@ -8,4 +8,5 @@ find "$path" -type f |
head -n 2 "$f" head -n 2 "$f"
done done
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -48,4 +48,5 @@ tac_ < /etc/passwd | cut_d_f__head_n : 1 1 ...@@ -48,4 +48,5 @@ tac_ < /etc/passwd | cut_d_f__head_n : 1 1
echo "Last 2 lines of /etc/passwd: " echo "Last 2 lines of /etc/passwd: "
tac_ < /etc/passwd | head_n 2 | tac_ tac_ < /etc/passwd | head_n 2 | tac_
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -78,4 +78,5 @@ find "$@" 2> /dev/null | sort -n | ...@@ -78,4 +78,5 @@ find "$@" 2> /dev/null | sort -n |
} }
' '
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -16,4 +16,6 @@ trap on_exit EXIT ...@@ -16,4 +16,6 @@ trap on_exit EXIT
exit "$rv" exit "$rv"
# @Test
# @TestRv 1
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
...@@ -21,4 +21,5 @@ done ...@@ -21,4 +21,5 @@ done
echo main loop finished echo main loop finished
# @Test
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
# Example for a simple wordlist completion. # Example for a simple wordlist completion.
# shellcheck disable=SC2148
complete -W "foo bar baz" 1-wordlist.sh complete -W "foo bar baz" 1-wordlist.sh
# vim: ai et sts=4 ts=4 sw=4
# Example for a function providing completions for a command. # Example for a function providing completions for a command.
# shellcheck disable=SC2207 # shellcheck disable=SC2148,SC2207
__function_completions() { __function_completions() {
# If not completing the 2nd word, do nothing. # If not completing the 2nd word, do nothing.
......
...@@ -12,4 +12,5 @@ case "$1" in ...@@ -12,4 +12,5 @@ case "$1" in
*) echo "ERROR: usage $name {foo|bar|baz}" >&2 ; exit 1 ;; *) echo "ERROR: usage $name {foo|bar|baz}" >&2 ; exit 1 ;;
esac esac
# @Test foo
# vim: ai et sts=4 ts=4 sw=4 # vim: ai et sts=4 ts=4 sw=4
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment