Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 main() { | 7 main() { |
| 8 var assertsEnabled = false; | 8 var assertsEnabled = false; |
| 9 assert((assertsEnabled = true)); | 9 assert((assertsEnabled = true)); |
| 10 if (!assertsEnabled) return; | 10 if (!assertsEnabled) return; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 45 } catch (e) { | 45 } catch (e) { |
| 46 Expect.fail("Assert should not throw."); | 46 Expect.fail("Assert should not throw."); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 | 49 |
| 50 testNullMessage() { | 50 testNullMessage() { |
| 51 try { | 51 try { |
| 52 assert(false, null); | 52 assert(false, null); |
| 53 Expect.fail("Assert should throw."); | 53 Expect.fail("Assert should throw."); |
| 54 } catch (e) { | 54 } catch (e) { |
| 55 Expect.isTrue(e.toString().contains("null")); | 55 Expect.isTrue(e.toString().contains("is not true")); |
|
Jennifer Messerly
2017/07/07 23:43:17
this test now matches VM behavior
| |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 testDoesNotEvaluateMessageIfAssertSucceeds() { | 59 testDoesNotEvaluateMessageIfAssertSucceeds() { |
| 60 try { | 60 try { |
| 61 var evaluated = false; | 61 var evaluated = false; |
| 62 assert(true, evaluated = true); | 62 assert(true, evaluated = true); |
| 63 Expect.isFalse(evaluated); | 63 Expect.isFalse(evaluated); |
| 64 } catch (e) { | 64 } catch (e) { |
| 65 Expect.fail("Assert should not throw."); | 65 Expect.fail("Assert should not throw."); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 testMessageExpressionThatThrows() { | 69 testMessageExpressionThatThrows() { |
| 70 try { | 70 try { |
| 71 assert(false, throw "dang"); | 71 assert(false, throw "dang"); |
| 72 Expect.fail("Should throw"); | 72 Expect.fail("Should throw"); |
| 73 } catch (e) { | 73 } catch (e) { |
| 74 Expect.equals(e, "dang"); | 74 Expect.equals(e, "dang"); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 | 77 |
| 78 testCallsToStringOnMessageLazily() { | 78 testCallsToStringOnMessageLazily() { |
| 79 var toString = new ToString(); | 79 var toString = new ToString(); |
| 80 try { | 80 try { |
| 81 assert(false, toString); | 81 assert(false, toString); |
| 82 Expect.fail("Assert should throw."); | 82 Expect.fail("Assert should throw."); |
| 83 } catch (e) { | 83 } catch (e) { |
| 84 Expect.isFalse(toString.calledToString); | 84 Expect.isFalse(toString.calledToString); |
| 85 Expect.isTrue(e.toString().contains("toString!")); | 85 Expect.isTrue(e.toString().contains("Instance of 'ToString'")); |
|
Jennifer Messerly
2017/07/07 23:43:17
same here
| |
| 86 Expect.isTrue(toString.calledToString); | 86 Expect.isFalse(toString.calledToString); |
| 87 } | 87 } |
| 88 } | 88 } |
| OLD | NEW |