| 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 // Dart test program testing assert statements. | 6 // Dart test program testing assert statements. |
| 7 |
| 6 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 7 | 9 |
| 8 class AssertTest { | 10 class AssertTest { |
| 9 static test() { | 11 static test() { |
| 10 try { | 12 try { |
| 11 assert(false); | 13 assert(false); |
| 12 Expect.fail("Assertion 'false' didn't fail."); | 14 Expect.fail("Assertion 'false' didn't fail."); |
| 13 } on AssertionError catch (error) { | 15 } on AssertionError catch (error) { |
| 14 Expect.equals("false", error.failedAssertion); | 16 Expect.isTrue(error.toString().contains("'false'")); |
| 15 int pos = error.url.lastIndexOf("/", error.url.length); | 17 Expect.isTrue(error.stackTrace.toString().contains( |
| 16 if (pos == -1) { | 18 "assert_test.dart:13:14")); |
| 17 pos = error.url.lastIndexOf("\\", error.url.length); | |
| 18 } | |
| 19 String subs = error.url.substring(pos + 1, error.url.length); | |
| 20 Expect.equals("assert_test.dart", subs); | |
| 21 Expect.equals(11, error.line); | |
| 22 Expect.equals(14, error.column); | |
| 23 } | 19 } |
| 24 } | 20 } |
| 25 static testClosure() { | 21 static testClosure() { |
| 26 try { | 22 try { |
| 27 assert(() => false); | 23 assert(() => false); |
| 28 Expect.fail("Assertion '() => false' didn't fail."); | 24 Expect.fail("Assertion '() => false' didn't fail."); |
| 29 } on AssertionError catch (error) { | 25 } on AssertionError catch (error) { |
| 30 Expect.equals("() => false", error.failedAssertion); | 26 Expect.isTrue(error.toString().contains("'() => false'")); |
| 31 int pos = error.url.lastIndexOf("/", error.url.length); | 27 Expect.isTrue(error.stackTrace.toString().contains( |
| 32 if (pos == -1) { | 28 "assert_test.dart:23:14")); |
| 33 pos = error.url.lastIndexOf("\\", error.url.length); | |
| 34 } | |
| 35 String subs = error.url.substring(pos + 1, error.url.length); | |
| 36 Expect.equals("assert_test.dart", subs); | |
| 37 Expect.equals(27, error.line); | |
| 38 Expect.equals(14, error.column); | |
| 39 } | 29 } |
| 40 } | 30 } |
| 41 | 31 |
| 42 static testMain() { | 32 static testMain() { |
| 43 test(); | 33 test(); |
| 44 testClosure(); | 34 testClosure(); |
| 45 } | 35 } |
| 46 } | 36 } |
| 47 | 37 |
| 48 main() { | 38 main() { |
| 49 AssertTest.testMain(); | 39 AssertTest.testMain(); |
| 50 } | 40 } |
| OLD | NEW |