| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /** | 5 /** |
| 6 * This library contains an Expect class with static methods that can be used | 6 * This library contains an Expect class with static methods that can be used |
| 7 * for simple unit-tests. | 7 * for simple unit-tests. |
| 8 */ | 8 */ |
| 9 library expect; | 9 library expect; |
| 10 | 10 |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 * | 356 * |
| 357 * Expect.throws(myThrowingFunction, (e) => e is MyException); | 357 * Expect.throws(myThrowingFunction, (e) => e is MyException); |
| 358 */ | 358 */ |
| 359 static void throws(void f(), | 359 static void throws(void f(), |
| 360 [_CheckExceptionFn check = null, | 360 [_CheckExceptionFn check = null, |
| 361 String reason = null]) { | 361 String reason = null]) { |
| 362 String msg = reason == null ? "" : "($reason)"; | 362 String msg = reason == null ? "" : "($reason)"; |
| 363 if (f is! _Nullary) { | 363 if (f is! _Nullary) { |
| 364 // Only throws from executing the funtion body should count as throwing. | 364 // Only throws from executing the funtion body should count as throwing. |
| 365 // The failure to even call `f` should throw outside the try/catch. | 365 // The failure to even call `f` should throw outside the try/catch. |
| 366 _fail("Expect.throws$msg: Funciton f not callable with zero arguments"); | 366 _fail("Expect.throws$msg: Function f not callable with zero arguments"); |
| 367 } | 367 } |
| 368 try { | 368 try { |
| 369 f(); | 369 f(); |
| 370 } catch (e, s) { | 370 } catch (e, s) { |
| 371 if (check != null) { | 371 if (check != null) { |
| 372 if (!check(e)) { | 372 if (!check(e)) { |
| 373 _fail("Expect.throws$msg: Unexpected '$e'\n$s"); | 373 _fail("Expect.throws$msg: Unexpected '$e'\n$s"); |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 return; | 376 return; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 399 | 399 |
| 400 /// Annotation class for testing of dart2js. Use this as metadata on method | 400 /// Annotation class for testing of dart2js. Use this as metadata on method |
| 401 /// declarations to disable inlining of the annotated method. | 401 /// declarations to disable inlining of the annotated method. |
| 402 class NoInline { | 402 class NoInline { |
| 403 const NoInline(); | 403 const NoInline(); |
| 404 } | 404 } |
| 405 | 405 |
| 406 /// Annotation class for testing of dart2js. Use this as metadata on method | 406 /// Annotation class for testing of dart2js. Use this as metadata on method |
| 407 /// declarations to make the type inferrer trust the parameter and return types, | 407 /// declarations to make the type inferrer trust the parameter and return types, |
| 408 /// effectively asserting the runtime values will (at least) be subtypes of the | 408 /// effectively asserting the runtime values will (at least) be subtypes of the |
| 409 /// annotated types. | 409 /// annotated types. |
| 410 /// | 410 /// |
| 411 /// While the actually inferred type is guaranteed to be a subtype of the | 411 /// While the actually inferred type is guaranteed to be a subtype of the |
| 412 /// annotation, it often is more precise. In particular, if a method is only | 412 /// annotation, it often is more precise. In particular, if a method is only |
| 413 /// called with `null`, the inferrer will still infer null. To ensure that | 413 /// called with `null`, the inferrer will still infer null. To ensure that |
| 414 /// the annotated type is also the inferred type, additionally use | 414 /// the annotated type is also the inferred type, additionally use |
| 415 /// [AssumeDynamic]. | 415 /// [AssumeDynamic]. |
| 416 class TrustTypeAnnotations { | 416 class TrustTypeAnnotations { |
| 417 const TrustTypeAnnotations(); | 417 const TrustTypeAnnotations(); |
| 418 } | 418 } |
| 419 | 419 |
| 420 /// Annotation class for testing of dart2js. Use this as metadata on method | 420 /// Annotation class for testing of dart2js. Use this as metadata on method |
| 421 /// declarations to disable closed world assumptions on parameters, effectively | 421 /// declarations to disable closed world assumptions on parameters, effectively |
| 422 /// assuming that the runtime arguments could be any value. Note that the | 422 /// assuming that the runtime arguments could be any value. Note that the |
| 423 /// constraints due to [TrustTypeAnnotations] still apply. | 423 /// constraints due to [TrustTypeAnnotations] still apply. |
| 424 class AssumeDynamic { | 424 class AssumeDynamic { |
| 425 const AssumeDynamic(); | 425 const AssumeDynamic(); |
| 426 } | 426 } |
| OLD | NEW |