Root/b2/test/subbreak

1#!/bin/bash
2. ./Common
3
4###############################################################################
5
6tst "substitutions: break alone" -ds -q <<EOF
7!-s
8in = blah
9out = x
10in = (?)(*) {
11    out=\$out\$in
12    break /* does nothing useful */
13}
14EOF
15
16expect <<EOF
17in=blah
18out=x
19in=RE {
20    out=\${out}\${in}
21    break in
22}
23in=blah
24out=xblah
25EOF
26
27#------------------------------------------------------------------------------
28
29tst "substitutions: named break to inner block" -ds -q <<EOF
30!-s
31in = blah
32out = x
33in = (?)(*) {
34    out=\$out\$in
35    break in /* does nothing useful */
36}
37EOF
38
39expect <<EOF
40in=blah
41out=x
42in=RE {
43    out=\${out}\${in}
44    break in
45}
46in=blah
47out=xblah
48EOF
49
50#------------------------------------------------------------------------------
51
52tst "substitutions: named break to outer block (taken)" -q doit=y <<EOF
53!-s
54in = blah
55out = x
56in = (?)(*) {
57    out=\$out\$in
58    doit = y {
59        break in
60    }
61    out=\$out\$in
62}
63EOF
64
65expect <<EOF
66in=blah
67out=xblah
68EOF
69
70#------------------------------------------------------------------------------
71
72tst "substitutions: named break to outer block (not taken)" -q doit=n <<EOF
73!-s
74in = blah
75out = x
76in = (?)(*) {
77    out=\$out\$in
78    doit = y {
79        break in
80    }
81    out=\$out\$in
82}
83EOF
84
85expect <<EOF
86in=blah
87out=xblahblah
88EOF
89
90#------------------------------------------------------------------------------
91
92tst "substitutions: break with continue" -q <<EOF
93!-s
94res = x
95res = * {
96    res = \${res}x
97    /*
98     * We use a temporary variable here because the variable name also
99     * serves as a jump label. Alternatively, we could use a dummy
100     * variable for the outer block.
101     */
102    tmp = \$res
103    tmp = ????? { break res }
104    continue
105}
106EOF
107
108expect <<EOF
109res=xxxxx
110tmp=xxxxx
111EOF
112
113#------------------------------------------------------------------------------
114
115tst_fail "substitutions: unnamed break inside block " -q <<EOF
116!-s
117foo = x
118foo = * {
119    break
120    foo = x
121}
122EOF
123
124expect <<EOF
125s:4: syntax error
126EOF
127
128#------------------------------------------------------------------------------
129
130tst_fail "substitutions: nmbed break inside block " -q <<EOF
131!-s
132foo = x
133foo = * {
134    break bar
135    foo = x
136}
137EOF
138
139expect <<EOF
140s:5: unreachable code
141EOF
142
143#------------------------------------------------------------------------------
144
145tst_fail "substitutions: named break to unknown block" -q <<EOF
146!-s
147foo = x
148foo = * {
149    break bar
150}
151EOF
152
153expect <<EOF
154s:5: cannot find "bar"
155EOF
156
157#------------------------------------------------------------------------------
158
159tst_fail "substitutions: break without block" -q <<EOF
160!-s
161break
162EOF
163
164expect <<EOF
165s:2: jump without block
166EOF
167
168###############################################################################
169

Archive Download this file

Branches:
master



interactive