| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // SharedOptions=--assert-message | 4 // SharedOptions=--assert-message |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 @AssumeDynamic() @NoInline() | 8 @AssumeDynamic() |
| 9 @NoInline() |
| 9 confuse(x) => x; | 10 confuse(x) => x; |
| 10 | 11 |
| 11 | |
| 12 testFalse(name, fault) { | 12 testFalse(name, fault) { |
| 13 try { | 13 try { |
| 14 fault(); | 14 fault(); |
| 15 } catch (e) { | 15 } catch (e) { |
| 16 Expect.isTrue(e is AssertionError, '$name: is AssertionError'); | 16 Expect.isTrue(e is AssertionError, '$name: is AssertionError'); |
| 17 Expect.isTrue('$e'.contains('Mumble'), '$name: <<$e>> contains "Mumble"'); | 17 Expect.isTrue('$e'.contains('Mumble'), '$name: <<$e>> contains "Mumble"'); |
| 18 return; | 18 return; |
| 19 } | 19 } |
| 20 Expect.fail('Expected assert to throw'); | 20 Expect.fail('Expected assert to throw'); |
| 21 } | 21 } |
| 22 | 22 |
| 23 test1() { | 23 test1() { |
| 24 testFalse('constant false', () { assert(false, 'Mumble'); }); | 24 testFalse('constant false', () { |
| 25 assert(false, 'Mumble'); |
| 26 }); |
| 25 } | 27 } |
| 26 | 28 |
| 27 test2() { | 29 test2() { |
| 28 testFalse('constant function', () { assert(() => false, 'Mumble'); }); | 30 testFalse('constant function', () { |
| 31 assert(() => false, 'Mumble'); |
| 32 }); |
| 29 } | 33 } |
| 30 | 34 |
| 31 test3() { | 35 test3() { |
| 32 testFalse('variable false', () { assert(confuse(false), 'Mumble'); }); | 36 testFalse('variable false', () { |
| 37 assert(confuse(false), 'Mumble'); |
| 38 }); |
| 33 } | 39 } |
| 34 | 40 |
| 35 test4() { | 41 test4() { |
| 36 testFalse('variable function', | 42 testFalse('variable function', () { |
| 37 () { assert(confuse(() => false), 'Mumble'); }); | 43 assert(confuse(() => false), 'Mumble'); |
| 44 }); |
| 38 } | 45 } |
| 39 | 46 |
| 40 testTypeErrors() { | 47 testTypeErrors() { |
| 41 check(name, fault) { | 48 check(name, fault) { |
| 42 try { | 49 try { |
| 43 fault(); | 50 fault(); |
| 44 } catch (e) { | 51 } catch (e) { |
| 45 Expect.isTrue(e is TypeError, | 52 Expect.isTrue( |
| 46 'name: <<$e>> (${e.runtimeType}) is TypeError'); | 53 e is TypeError, 'name: <<$e>> (${e.runtimeType}) is TypeError'); |
| 47 return; | 54 return; |
| 48 } | 55 } |
| 49 Expect.fail('Expected assert to throw'); | 56 Expect.fail('Expected assert to throw'); |
| 50 } | 57 } |
| 51 | 58 |
| 52 check('constant type error', () { assert(null, 'Mumble'); }); | 59 check('constant type error', () { |
| 53 check('variable type error', () { assert(confuse(null), 'Mumble'); }); | 60 assert(null, 'Mumble'); |
| 54 check('function type error', () { assert(confuse(() => null), 'Mumble'); }); | 61 }); |
| 62 check('variable type error', () { |
| 63 assert(confuse(null), 'Mumble'); |
| 64 }); |
| 65 check('function type error', () { |
| 66 assert(confuse(() => null), 'Mumble'); |
| 67 }); |
| 55 } | 68 } |
| 56 | 69 |
| 57 testMessageEffect1() { | 70 testMessageEffect1() { |
| 58 var v = 1; | 71 var v = 1; |
| 59 // Message is not evaluated on succeeding assert. | 72 // Message is not evaluated on succeeding assert. |
| 60 assert(confuse(true), '${v = 123}'); | 73 assert(confuse(true), '${v = 123}'); |
| 61 Expect.equals(1, v); | 74 Expect.equals(1, v); |
| 62 } | 75 } |
| 63 | 76 |
| 64 testMessageEffect2() { | 77 testMessageEffect2() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 113 |
| 101 test1(); | 114 test1(); |
| 102 test2(); | 115 test2(); |
| 103 test3(); | 116 test3(); |
| 104 test4(); | 117 test4(); |
| 105 testTypeErrors(); | 118 testTypeErrors(); |
| 106 testMessageEffect1(); | 119 testMessageEffect1(); |
| 107 testMessageEffect2(); | 120 testMessageEffect2(); |
| 108 testMessageEffect3(); | 121 testMessageEffect3(); |
| 109 } | 122 } |
| OLD | NEW |