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