OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library malformed_test; |
| 6 |
| 7 // This part includes the actual tests. |
| 8 part 'malformed2_lib.dart'; /// 00: static type warning |
| 9 |
| 10 bool inCheckedMode() { |
| 11 try { |
| 12 var i = 42; |
| 13 String s = i; |
| 14 } on TypeError catch (e) { |
| 15 return true; |
| 16 } |
| 17 return false; |
| 18 } |
| 19 |
| 20 bool hasFailed = false; |
| 21 |
| 22 void fail(String message) { |
| 23 try { |
| 24 throw message; |
| 25 } catch (e, s) { |
| 26 print(e); |
| 27 print(s); |
| 28 } |
| 29 hasFailed = true; |
| 30 } |
| 31 |
| 32 void checkFailures() { |
| 33 if (hasFailed) throw 'Test failed.'; |
| 34 } |
| 35 |
| 36 test(bool expectTypeError, f(), [String message]) { |
| 37 message = message != null ? ' for $message' : ''; |
| 38 try { |
| 39 f(); |
| 40 if (expectTypeError) { |
| 41 fail('Missing type error$message.'); |
| 42 } |
| 43 } on TypeError catch (e) { |
| 44 if (expectTypeError) { |
| 45 print('Type error$message: $e'); |
| 46 } else { |
| 47 fail('Unexpected type error$message: $e'); |
| 48 } |
| 49 } |
| 50 } |
| 51 |
| 52 const Unresolved c1 = 0; /// 01: static type warning, compile-time error |
| 53 |
| 54 void main() { |
| 55 print(c1); /// 01: continued |
| 56 testValue(new List<String>()); /// 00: continued |
| 57 testValue(null); /// 00: continued |
| 58 checkFailures(); |
| 59 } |
OLD | NEW |