1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#!/bin/dash
# vim: set filetype=sh :
# file: example.func
# copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2007-2020)
# license: GNU General Public License, version 3
# description: test using shell script functions
# warning: do not use "set -e" if "exit 5" or "exit 4" should be tested
# see also: test.func
#set -e # this line can not be used, because we really want to test errors
set -u
. ./ia
sub_sub()
{
{ set +x; } 2>/dev/null
eval "$ia_init"
# next line should give an error if checked with option -c
ia_add "echo 2.3.1"
ia_stdout "^2.3.2$"
ia_add "echo 2.3.2"
ia
}
sub()
{
{ set +x; } 2>/dev/null
eval "$ia_init"
ia_stdout "^2.1$"
ia_add "echo 2.1"
ia_stdout "^2.2$"
# stderr should be handled like stdout
ia_add "echo 2.2 >&2"
ia_stdout "^2.3$"
ia_add "echo 2.3"
ia_nocheck
ia_add "sub_sub <-i>"
ia_stdout "^2.4$"
ia_add "echo 2.4"
ia_stdout "^2.5$"
# next line should give error if checked with option -c
ia_add "sh -c \"echo 2.5; exit 5\""
ia_stdout "^2.6$"
ia_stdout "^exit=4$"
ia_add "sh -c \"echo 2.6; exit 4\""
ia_stdout "^2.7$"
ia_add "echo 2.7"
ia
}
eval "$ia_init"
ia_stdout "^1$"
ia_add "echo 1"
ia_stdout "^2$"
ia_add "echo 2"
ia_nocheck
ia_add "sub <-i>"
ia_stdout "^3$"
ia_add "echo 3"
ia_stdout "^4$"
ia_add "echo 4"
ia -c
|