|
1 |
| -package compile |
| 1 | +package symtable |
2 | 2 |
|
3 | 3 | //go:generate ./make_symtable_test.py
|
4 | 4 |
|
@@ -131,45 +131,34 @@ func EqSymTable(t *testing.T, name string, a, b *SymTable) {
|
131 | 131 | func TestSymTable(t *testing.T) {
|
132 | 132 | for _, test := range symtableTestData {
|
133 | 133 | var symtab *SymTable
|
134 |
| - func() { |
135 |
| - defer func() { |
136 |
| - if r := recover(); r != nil { |
137 |
| - if test.exceptionType == nil { |
138 |
| - t.Errorf("%s: Got exception %v when not expecting one", test.in, r) |
139 |
| - return |
140 |
| - } |
141 |
| - exc, ok := r.(*py.Exception) |
142 |
| - if !ok { |
143 |
| - t.Errorf("%s: Got non python exception %T %v", test.in, r, r) |
144 |
| - return |
145 |
| - } |
146 |
| - if exc.Type() != test.exceptionType { |
147 |
| - t.Errorf("%s: want exception type %v got %v", test.in, test.exceptionType, exc.Type()) |
148 |
| - return |
149 |
| - } |
150 |
| - if exc.Type() != test.exceptionType { |
151 |
| - t.Errorf("%s: want exception type %v got %v", test.in, test.exceptionType, exc.Type()) |
152 |
| - return |
153 |
| - } |
154 |
| - msg := string(exc.Args.(py.Tuple)[0].(py.String)) |
155 |
| - if msg != test.errString { |
156 |
| - t.Errorf("%s: want exception text %q got %q", test.in, test.errString, msg) |
157 |
| - } |
158 |
| - |
| 134 | + Ast, err := parser.ParseString(test.in, test.mode) |
| 135 | + if err != nil { |
| 136 | + t.Fatalf("Unexpected parse error: %v", err) |
| 137 | + } |
| 138 | + symtab, err = NewSymTable(Ast) |
| 139 | + if err != nil { |
| 140 | + if test.exceptionType == nil { |
| 141 | + t.Errorf("%s: Got exception %v when not expecting one", test.in, err) |
| 142 | + } else if exc, ok := err.(*py.Exception); !ok { |
| 143 | + t.Errorf("%s: Got non python exception %T %v", test.in, err, err) |
| 144 | + } else if exc.Type() != test.exceptionType { |
| 145 | + t.Errorf("%s: want exception type %v got %v", test.in, test.exceptionType, exc.Type()) |
| 146 | + } else if exc.Type() != test.exceptionType { |
| 147 | + t.Errorf("%s: want exception type %v got %v", test.in, test.exceptionType, exc.Type()) |
| 148 | + } else { |
| 149 | + msg := string(exc.Args.(py.Tuple)[0].(py.String)) |
| 150 | + if msg != test.errString { |
| 151 | + t.Errorf("%s: want exception text %q got %q", test.in, test.errString, msg) |
159 | 152 | }
|
160 |
| - }() |
161 |
| - Ast, err := parser.ParseString(test.in, test.mode) |
162 |
| - if err != nil { |
163 |
| - panic(err) // FIXME error handling! |
164 |
| - } |
165 |
| - symtab = NewSymTable(Ast) |
166 |
| - }() |
167 |
| - if test.out == nil { |
168 |
| - if symtab != nil { |
169 |
| - t.Errorf("%s: Expecting nil *py.Code but got %T", test.in, symtab) |
170 | 153 | }
|
171 | 154 | } else {
|
172 |
| - EqSymTable(t, test.in, test.out, symtab) |
| 155 | + if test.exceptionType != nil { |
| 156 | + t.Errorf("%s: Didn't get exception %v", test.in, err) |
| 157 | + } else if test.out == nil && symtab != nil { |
| 158 | + t.Errorf("%s: Expecting nil *SymbolTab but got %T", test.in, symtab) |
| 159 | + } else { |
| 160 | + EqSymTable(t, test.in, test.out, symtab) |
| 161 | + } |
173 | 162 | }
|
174 | 163 | }
|
175 | 164 | }
|
|
0 commit comments