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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
#!/bin/sh
# vim: set filetype=sh :
# file: test.func
# copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2007-2021)
# license: GNU General Public License, version 3
# description: test using shell script functions
# see also: example.func
# The following tests are included:
# (1) Run this script without options
# (2) Run in interactive mode but continue with c where possible
# (3) Run this script with "ia -c" and without options
# (4) Run this script with "ia -c" and optin -i and use c to continue when possible
. ./tstlib
# change multiple + (as produced in bash set -x) to just one + (as produced in dash set -x)
UNIFY_set_x_onlycmd="grep -v -e \"^+ 2>/dev/null $\" -e \"^+ set +x$\""
shell=""
while [ $# -ne 0 ]; do
if [ "$1" = "-s" ]; then
shell="$2"
shift 2
else
echo "ERROR $0: unknown option <$1>" >&2
exit 1
fi
done
[ "$shell" ] && set -- "$@" -s "$shell"
[ "$shell" = "mksh" ] && set -- "$@" -u "$UNIFY_set_x_onlycmd"
[ "$shell" = "bash" ] && set -- "$@" -u "$UNIFY_bash"
bug913718_unify UNIFY_posh
[ "$shell" = "posh" ] && set -- "$@" -u "$UNIFY_posh"
cmd=$(dirname $0)/example.func
bug913718_cmd
ia_logfile=/dev/null
export ia_logfile
check "(1) Run this script without options" "$@" $cmd "1
2
2.1
2.2
2.3
2.3.1
2.3.2
2.4
2.5
2.6
2.7
3
4"
check "(2) Run in interactive mode but continue with c where possible" -i "echo \"c
c
c
\"" "$@" "$cmd -a -i" "=== example.func ===
1 echo 1
2 echo 2
3 sub -i
4 echo 3
5 echo 4
d ... change dbg: 0
i toggle -i flag
c continue without questions
q quit
? [1]
1
2
=== example.func/sub ===
1 echo 2.1
2 echo 2.2 >&2
3 echo 2.3
4 sub_sub -i
5 echo 2.4
6 sh -c \"echo 2.5; exit 5\"
7 sh -c \"echo 2.6; exit 4\"
8 echo 2.7
d ... change dbg: 0
i toggle -i flag
c continue without questions
q quit
? [1]
2.1
2.2
2.3
=== example.func/sub/sub_sub ===
1 echo 2.3.1
2 echo 2.3.2
d ... change dbg: 0
c continue without questions
q quit
? [1]
2.3.1
2.3.2
2.4
2.5
2.6
2.7
3
4"
cmd=$(dirname $0)/example.func.tmp.check
cat $(dirname $0)/example.func | sed -e "s|^\(\s*ia\>\).*|\1 -c|" > $cmd
chmod 755 $cmd
bug913718_cmd
# next test is stopped, because missing stdin is interpreted as q
check "(3) Run this script with \"ia -c\" and without options" -i "echo \"i
i
\"" "$@" "$cmd -a" "1
2
2.1
2.2
2.3
--- output with ERROR from <example.func.tmp.check/sub/sub_sub> running <echo 2.3.1> ---
e:2.3.1
--- (q)uit (r)edo (i)gnore (s)witch interactive ---
?
2.3.2
2.4
--- output with ERROR from <example.func.tmp.check/sub> running <sh -c \"echo 2.5; exit 5\"> ---
s:2.5
e:exit=5
--- (q)uit (r)edo (i)gnore (s)witch interactive ---
?
2.5
2.6
exit=4
2.7
3
4"
check "(4) Run this script with \"ia -c\" and optin -i and use c to continue when possible" -i "echo \"c
c
c
i
i
\"" "$@" "$cmd -a -i" "=== example.func.tmp.check ===
1 echo 1
2 echo 2
3 sub -i
4 echo 3
5 echo 4
d ... change dbg: 0
i toggle -i flag
c continue without questions
q quit
? [1]
1
2
=== example.func.tmp.check/sub ===
1 echo 2.1
2 echo 2.2 >&2
3 echo 2.3
4 sub_sub -i
5 echo 2.4
6 sh -c \"echo 2.5; exit 5\"
7 sh -c \"echo 2.6; exit 4\"
8 echo 2.7
d ... change dbg: 0
i toggle -i flag
c continue without questions
q quit
? [1]
2.1
2.2
2.3
=== example.func.tmp.check/sub/sub_sub ===
1 echo 2.3.1
2 echo 2.3.2
d ... change dbg: 0
c continue without questions
q quit
? [1]
--- output with ERROR from <example.func.tmp.check/sub/sub_sub> running <echo 2.3.1> ---
e:2.3.1
--- (q)uit (r)edo (i)gnore (s)witch interactive ---
?
2.3.2
2.4
--- output with ERROR from <example.func.tmp.check/sub> running <sh -c \"echo 2.5; exit 5\"> ---
s:2.5
e:exit=5
--- (q)uit (r)edo (i)gnore (s)witch interactive ---
?
2.5
2.6
exit=4
2.7
3
4"
|