File: test.multiply

package info (click to toggle)
shellia 5.10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 792 kB
  • sloc: sh: 7,840; makefile: 34
file content (187 lines) | stat: -rwxr-xr-x 4,383 bytes parent folder | download | duplicates (3)
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
#!/bin/sh
# vim: set filetype=sh :
#        file: test.multiply
#   copyright: Bernd Schumacher <bernd.schumacher@hpe.com> (2007-2021)
#     license: GNU General Public License, version 3
# description: test a script that changes global and local variables in functions
#    see also: example.multiply

# The following tests are included:
# (1) Run this script without options
# (2) check the logfile
# (3) Try to run in interactive mode but continue with c where possible
# (4) check the logfile.
# (5) Run this script with "ia -c" and without options
# (6) check the logfile

. ./tstlib

# change multiple + (as produced in bash set -x) to just one + (as produced in dash 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_mksh"
[ "$shell" = "bash" ] && set -- "$@" -u "$UNIFY_bash"
bug913718_unify UNIFY_posh
[ "$shell" = "posh" ] && set -- "$@" -u "$UNIFY_posh"
[ "$shell" = "busybox sh" ] && set -- "$@" -u "$UNIFY_busybox"
cmd=$(dirname $0)/example.multiply
bug913718_cmd

ia_logfile="$(mktemp)"
export ia_logfile

rm -f $ia_logfile
check "(1) Run this script without options" "$@" "$cmd" "x=6"

check "(2) check the logfile" "$@" "cat $ia_logfile" "|example.multiply
||example.multiply/x=\$(mult
|||example.multiply/x=\$(mult/ret=\$(plus
|||s:2
|||example.multiply/x=\$(mult/ret=\$(plus
|||s:4
|||example.multiply/x=\$(mult/ret=\$(plus
|||s:6
||s:6
|s:x=6"

rm -f $ia_logfile
check "(3) Try to run in interactive mode but continue with c where possible" -i "echo \"c
c
c
c
c
\"" "$@" "$cmd -a -i" "=== example.multiply ===
1 x=\$(mult -i 3 2)
2 echo x=\$x
d ... change dbg: 0
i toggle -i flag
c continue without questions
q quit
? [1] 
=== example.multiply/x=\$(mult ===
1 ret=0
2 ret=\$(plus -i \$ret 2)
3 ret=\$(plus -i \$ret 2)
4 ret=\$(plus -i \$ret 2)
5 echo \$ret
d ... change dbg: 0
i toggle -i flag
c continue without questions
q quit
? [1] 
=== example.multiply/x=\$(mult/ret=\$(plus ===
1 echo 2
d ... change dbg: 0
q quit
? [1] 
=== example.multiply/x=\$(mult/ret=\$(plus ===
1 echo 4
d ... change dbg: 0
q quit
? [1] 
=== example.multiply/x=\$(mult/ret=\$(plus ===
1 echo 6
d ... change dbg: 0
q quit
? [1] 
x=6"

check "(4) check the logfile." "$@" "cat $ia_logfile" "|=== example.multiply ===
|1 x=\$(mult -i 3 2)
|2 echo x=\$x
|d ... change dbg: 0
|i toggle -i flag
|c continue without questions
|q quit
|? [1] c<RETURN>
||=== example.multiply/x=\$(mult ===
||1 ret=0
||2 ret=\$(plus -i \$ret 2)
||3 ret=\$(plus -i \$ret 2)
||4 ret=\$(plus -i \$ret 2)
||5 echo \$ret
||d ... change dbg: 0
||i toggle -i flag
||c continue without questions
||q quit
||? [1] c<RETURN>
|||=== example.multiply/x=\$(mult/ret=\$(plus ===
|||1 echo 2
|||d ... change dbg: 0
|||q quit
|||? [1] c<RETURN>
|||s:2
|||=== example.multiply/x=\$(mult/ret=\$(plus ===
|||1 echo 4
|||d ... change dbg: 0
|||q quit
|||? [1] c<RETURN>
|||s:4
|||=== example.multiply/x=\$(mult/ret=\$(plus ===
|||1 echo 6
|||d ... change dbg: 0
|||q quit
|||? [1] c<RETURN>
|||s:6
||s:6
|s:x=6"

cmd=$(dirname $0)/example.multiply.tmp.trace
cat $(dirname $0)/example.multiply | set_ia_x > $cmd
chmod 755 $cmd
bug913718_cmd

rm -f $ia_logfile
check "(5) Run this script with \"ia -x\" and without options" "$@" "$cmd" "+ mult 3 2
+ local ret
+ ret=0
+ plus 0 2
+ echo 2
+ ret=2
+ plus 2 2
+ echo 4
+ ret=4
+ plus 4 2
+ echo 6
+ ret=6
+ echo 6
+ x=6
+ echo x=6
x=6"

check "(6) check the logfile" "$@" "cat $ia_logfile" "|example.multiply.tmp.trace
||example.multiply.tmp.trace/x=\$(mult
|||example.multiply.tmp.trace/x=\$(mult/ret=\$(plus
|||example.multiply.tmp.trace/x=\$(mult/ret=\$(plus
|||example.multiply.tmp.trace/x=\$(mult/ret=\$(plus"

cmd=$(dirname $0)/example.multiply.tmp.-C
cat $(dirname $0)/example.multiply | sed "s/^\(\s*\)ia\>.*/\1ia -C/" > $cmd
chmod 755 $cmd
bug913718_cmd
rm -f $ia_logfile
check "(7) Run this script with \"ia -C\" and without options" "$@" "$cmd" "x=6"

check "(8) check the logfile" "$@" "cat $ia_logfile" "|example.multiply.tmp.-C
||example.multiply.tmp.-C/x=\$(mult
|||example.multiply.tmp.-C/x=\$(mult/ret=\$(plus
|||s:2
|||example.multiply.tmp.-C/x=\$(mult/ret=\$(plus
|||s:4
|||example.multiply.tmp.-C/x=\$(mult/ret=\$(plus
|||s:6
||s:6
|s:x=6"

rm -f $ia_logfile