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 | |
7 var x = ""; | 5 var x = ""; |
8 | 6 |
9 test(String str, [onError(String)]) { | 7 test(String str, [onError(String)]) { |
10 return (() { | 8 return (() { |
11 try { | 9 try { |
12 throw ""; | 10 throw ""; |
13 } catch(e) { | 11 } catch(e) { |
14 if (?onError) { | 12 if (?onError) { |
15 onError(str); | 13 onError(str); |
16 } else { | 14 } else { |
17 x = "${str} error"; | 15 x = "${str} error"; |
18 } | 16 } |
19 } | 17 } |
20 }); | 18 }); |
21 } | 19 } |
22 | 20 |
23 ignoreError(String str) { | 21 ignoreError(String str) { |
24 x = "${str} error ignored"; | 22 x = "${str} error ignored"; |
25 } | 23 } |
26 | 24 |
27 main() { | 25 main() { |
28 Expect.equals("", x); | 26 Expect.equals("", x); |
29 test("test")(); | 27 test("test")(); |
30 Expect.equals("test error", x); | 28 Expect.equals("test error", x); |
31 test("test", ignoreError)(); | 29 test("test", ignoreError)(); |
32 Expect.equals("test error ignored", x); | 30 Expect.equals("test error ignored", x); |
33 } | 31 } |
OLD | NEW |