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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
|
#!/bin/sh
# vim: set filetype=sh :
# file: test.ia-c-s-m
# copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2007-2021)
# license: GNU General Public License, version 3
# description: test handling ia options -c -s -m
# see also: example.ia-c-s-m
# The following tests are included:
# Next tests use example.ia-c-s-m
# (1) Switch to interactive, choose next command and use default until end
# (2) check logfile
# (3) Ignore Error
# (4) check the logfile
# (5) Quit
# (6) check the logfile
# (7) Use option -s and run without input
# (8) check the logfile
# (9) Use option -m and exit
# (10) check the logfile
# Next tests use example.ia-c-s-m.tmp.silent
# (11) Change Script to silent and run without input
# (12) check the logfile
# (13) run script in minimal control mode, retry once and exit
# (14) check the logfile
# Next tests use example.ia-c-s-m.tmp.set-e
# (15) Change Script to set -e and run without input
# (16) check the logfile
. ./tstlib
# bash "e:./ia.run: line 71: nonexisting-command: command not found"
# dash "e:./example.ia-c-s-m: 1: eval: nonexisting-command: not found"
UNIFY_command_not_found="sed -e \"s/e:.*nonexisting-command:.*not found.*/e:nonexisting-command: not found/\""
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"
bug913718_unify UNIFY_command_not_found
set -- "$@" -u "$UNIFY_command_not_found"
cmd=$(dirname $0)/example.ia-c-s-m
bug913718_cmd
ia_logfile="$(mktemp)"
export ia_logfile
rm -f $ia_logfile
check "(1) Switch to interactive, choose next command and use default until end" -i "echo \"s
4
\"" "$@" "$cmd -a" "--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
e:nonexisting-command: not found
e:exit=127
--- (q)uit (r)edo (i)gnore (s)witch interactive ---
?
switching to interactive mode to point (3) which failed
=== example.ia-c-s-m ===
1 a=1
2 a=\$((a+1))
3 nonexisting-command
4 echo \"a=\$a\"
d ... change dbg: 0
c continue without questions
q quit
? [3]
a=2
=== example.ia-c-s-m ===
1 a=1
2 a=\$((a+1))
3 nonexisting-command
4 echo \"a=\$a\"
d ... change dbg: 0
q quit
? [q] "
check "(2) check logfile" "$@" "cat $ia_logfile" "|example.ia-c-s-m
|--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
|e:nonexisting-command: not found
|e:exit=127
|--- (q)uit (r)edo (i)gnore (s)witch interactive ---
|? s<RETURN>
|=== example.ia-c-s-m ===
|1 a=1
|2 a=\$((a+1))
|3 nonexisting-command
|4 echo \"a=\$a\"
|d ... change dbg: 0
|c continue without questions
|q quit
|? [3] 4<RETURN>
|s:a=2
|=== example.ia-c-s-m ===
|1 a=1
|2 a=\$((a+1))
|3 nonexisting-command
|4 echo \"a=\$a\"
|d ... change dbg: 0
|q quit
|? [q] <RETURN>"
rm -f $ia_logfile
check "(3) Ignore Error" -i "echo \"i
\"" "$@" "$cmd -a" "--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
e:nonexisting-command: not found
e:exit=127
--- (q)uit (r)edo (i)gnore (s)witch interactive ---
?
a=2"
check "(4) check the logfile" "$@" "cat $ia_logfile" "|example.ia-c-s-m
|--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
|e:nonexisting-command: not found
|e:exit=127
|--- (q)uit (r)edo (i)gnore (s)witch interactive ---
|? i<RETURN>
|s:a=2"
rm -f $ia_logfile
check "(5) Quit" -i "echo \"q
\"" "$@" "$cmd -a" "--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
e:nonexisting-command: not found
e:exit=127
--- (q)uit (r)edo (i)gnore (s)witch interactive ---
?
Command exited with non-zero status 127"
check "(6) check the logfile" "$@" "cat $ia_logfile" "|example.ia-c-s-m
|--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
|e:nonexisting-command: not found
|e:exit=127
|--- (q)uit (r)edo (i)gnore (s)witch interactive ---
|? q<RETURN>"
rm -f $ia_logfile
check "(7) Use option -s and run without input" "$@" "$cmd -a -s" \
"--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
e:nonexisting-command: not found
e:exit=127
Exit because of ERROR and no interactive question allowed.
Command exited with non-zero status 127"
check "(8) check the logfile" "$@" "cat $ia_logfile" "|example.ia-c-s-m
|--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
|e:nonexisting-command: not found
|e:exit=127
|Exit because of ERROR and no interactive question allowed."
rm -f $ia_logfile
check "(9) Use option -m and exit" -i "echo \"q
\"" "$@" "$cmd -a -m" "--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
e:nonexisting-command: not found
e:exit=127
--- (q)uit (r)edo (i)gnore ---
?
Command exited with non-zero status 127"
check "(10) check the logfile" "$@" "cat $ia_logfile" "|example.ia-c-s-m
|--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
|e:nonexisting-command: not found
|e:exit=127
|--- (q)uit (r)edo (i)gnore ---
|? q<RETURN>"
cmd=$(dirname $0)/example.ia-c-s-m.tmp.minimal
cat $(dirname $0)/example.ia-c-s-m | sed "s/^ia .*/ia -c -m/" > $cmd
chmod 755 $cmd
rm -f $ia_logfile
bug913718_cmd
check "(11) Change Script to minimal and ignore once" -i "echo \"i
\"" "$@" "$cmd -a" "--- output with ERROR from <example.ia-c-s-m.tmp.minimal> running <nonexisting-command> ---
e:nonexisting-command: not found
e:exit=127
--- (q)uit (r)edo (i)gnore ---
?
a=2"
check "(12) check the logfile" "$@" "cat $ia_logfile" "|example.ia-c-s-m.tmp.minimal
|--- output with ERROR from <example.ia-c-s-m.tmp.minimal> running <nonexisting-command> ---
|e:nonexisting-command: not found
|e:exit=127
|--- (q)uit (r)edo (i)gnore ---
|? i<RETURN>
|s:a=2"
rm -f $ia_logfile
cmd=$(dirname $0)/example.ia-c-s-m
bug913718_cmd
check "(13) run script in silent control mode" "$@" "$cmd -a -s" "--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
e:nonexisting-command: not found
e:exit=127
Exit because of ERROR and no interactive question allowed.
Command exited with non-zero status 127"
check "(14) check the logfile" "$@" "cat $ia_logfile" "|example.ia-c-s-m
|--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
|e:nonexisting-command: not found
|e:exit=127
|Exit because of ERROR and no interactive question allowed."
cmd=$(dirname $0)/example.ia-c-s-m.tmp.silent
cat $(dirname $0)/example.ia-c-s-m | sed "s/^ia .*/ia -c -s/" > $cmd
chmod 755 $cmd
rm -f $ia_logfile
bug913718_cmd
check "(15) Change Script to silent and run without input" "$@" "$cmd -a" \
"--- output with ERROR from <example.ia-c-s-m.tmp.silent> running <nonexisting-command> ---
e:nonexisting-command: not found
e:exit=127
Exit because of ERROR and no interactive question allowed.
Command exited with non-zero status 127"
check "(16) check the logfile" "$@" "cat $ia_logfile" "|example.ia-c-s-m.tmp.silent
|--- output with ERROR from <example.ia-c-s-m.tmp.silent> running <nonexisting-command> ---
|e:nonexisting-command: not found
|e:exit=127
|Exit because of ERROR and no interactive question allowed."
rm -f $ia_logfile
cmd=$(dirname $0)/example.ia-c-s-m
bug913718_cmd
check "(17) run script in minimal control mode, retry once and exit" -i "echo \"r
q
\"" "$@" "$cmd -a -m" "--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
e:nonexisting-command: not found
e:exit=127
--- (q)uit (r)edo (i)gnore ---
?
--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
e:nonexisting-command: not found
e:exit=127
--- (q)uit (r)edo (i)gnore ---
?
Command exited with non-zero status 127"
check "(18) check the logfile" "$@" "cat $ia_logfile" "|example.ia-c-s-m
|--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
|e:nonexisting-command: not found
|e:exit=127
|--- (q)uit (r)edo (i)gnore ---
|? r<RETURN>
|--- output with ERROR from <example.ia-c-s-m> running <nonexisting-command> ---
|e:nonexisting-command: not found
|e:exit=127
|--- (q)uit (r)edo (i)gnore ---
|? q<RETURN>"
cmd=$(dirname $0)/example.ia-c-s-m.tmp.set-e
cat $(dirname $0)/example.ia-c-s-m | sed "s/^#set -e.*/set -e/" > $cmd
chmod 755 $cmd
rm -f $ia_logfile
bug913718_cmd
extrawurst="" # if mksh is too old we need extra handling
if [ "$shell" = "mksh" ]; then
if dpkg --compare-versions "$(dpkg-query -W -f='${Version}' mksh)" lt "57-6"; then
extrawurst="1"
fi
fi
if [ "$extrawurst" ]; then
res=\
"ERROR: ia premature exit of <nonexisting-command>
unchecked output: <./tests/example.ia-c-s-m.tmp.set-e:nonexisting-command: not found
Command exited with non-zero status 127"
else
res=\
"--- output with ERROR from <example.ia-c-s-m.tmp.set-e> running <nonexisting-command> ---
e:nonexisting-command: not found
e:[0;31mexit=127[0m
--- (q)uit (r)edo (i)gnore (s)witch interactive ---
?
a=2"
fi
check "(19) Change Script to set -e and run without input" -i "echo \"i
\"" "$@" "$cmd" "$res"
extrawurst="" # if mksh is too old we need extra handling
if [ "$shell" = "mksh" ]; then
if dpkg --compare-versions "$(dpkg-query -W -f='${Version}' mksh)" lt "57-6"; then
extrawurst="1"
fi
fi
if [ "$extrawurst" ]; then
res=\
"|example.ia-c-s-m.tmp.set-e"
else
res=\
"|example.ia-c-s-m.tmp.set-e
|--- output with ERROR from <example.ia-c-s-m.tmp.set-e> running <nonexisting-command> ---
|e:nonexisting-command: not found
|e:[0;31mexit=127[0m
|--- (q)uit (r)edo (i)gnore (s)witch interactive ---
|? i<RETURN>
|s:a=2"
fi
check "(20) check the logfile" "$@" "cat $ia_logfile" "$res"
rm -f $ia_logfile
|