OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // VMOptions=--enable_asserts | 4 // VMOptions=--enable_asserts |
5 | 5 |
6 // Dart test program testing assert statements. | 6 // Dart test program testing assert statements. |
7 | 7 |
8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
9 | 9 |
10 class AssertTest { | 10 class AssertTest { |
11 static test() { | 11 static test() { |
12 try { | 12 try { |
13 assert(false); | 13 assert(false); |
14 Expect.fail("Assertion 'false' didn't fail."); | 14 Expect.fail("Assertion 'false' didn't fail."); |
15 } on AssertionError catch (error) { | 15 } on AssertionError catch (error) { |
16 Expect.isTrue(error.toString().contains("'false'")); | 16 Expect.isTrue(error.toString().contains("'false'")); |
17 Expect.isTrue(error.stackTrace.toString().contains( | 17 Expect.isTrue( |
18 "assert_test.dart:13:14")); | 18 error.stackTrace.toString().contains("assert_test.dart:13:14")); |
19 } | 19 } |
20 } | 20 } |
| 21 |
21 static testClosure() { | 22 static testClosure() { |
22 try { | 23 try { |
23 assert(() => false); | 24 assert(() => false); |
24 Expect.fail("Assertion '() => false' didn't fail."); | 25 Expect.fail("Assertion '() => false' didn't fail."); |
25 } on AssertionError catch (error) { | 26 } on AssertionError catch (error) { |
26 Expect.isTrue(error.toString().contains("'() => false'")); | 27 Expect.isTrue(error.toString().contains("'() => false'")); |
27 Expect.isTrue(error.stackTrace.toString().contains( | 28 Expect.isTrue( |
28 "assert_test.dart:23:14")); | 29 error.stackTrace.toString().contains("assert_test.dart:24:14")); |
29 } | 30 } |
30 } | 31 } |
31 | 32 |
32 static testMain() { | 33 static testMain() { |
33 test(); | 34 test(); |
34 testClosure(); | 35 testClosure(); |
35 } | 36 } |
36 } | 37 } |
37 | 38 |
38 main() { | 39 main() { |
39 AssertTest.testMain(); | 40 AssertTest.testMain(); |
40 } | 41 } |
OLD | NEW |