OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
| 5 import "package:expect/expect.dart"; |
| 6 |
5 var x = ""; | 7 var x = ""; |
6 | 8 |
7 test(String str, [onError(String)]) { | 9 test(String str, [onError(String)]) { |
8 return (() { | 10 return (() { |
9 try { | 11 try { |
10 throw ""; | 12 throw ""; |
11 } catch(e) { | 13 } catch(e) { |
12 if (?onError) { | 14 if (?onError) { |
13 onError(str); | 15 onError(str); |
14 } else { | 16 } else { |
15 x = "${str} error"; | 17 x = "${str} error"; |
16 } | 18 } |
17 } | 19 } |
18 }); | 20 }); |
19 } | 21 } |
20 | 22 |
21 ignoreError(String str) { | 23 ignoreError(String str) { |
22 x = "${str} error ignored"; | 24 x = "${str} error ignored"; |
23 } | 25 } |
24 | 26 |
25 main() { | 27 main() { |
26 Expect.equals("", x); | 28 Expect.equals("", x); |
27 test("test")(); | 29 test("test")(); |
28 Expect.equals("test error", x); | 30 Expect.equals("test error", x); |
29 test("test", ignoreError)(); | 31 test("test", ignoreError)(); |
30 Expect.equals("test error ignored", x); | 32 Expect.equals("test error ignored", x); |
31 } | 33 } |
OLD | NEW |