| 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 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 * The optional [check] function can provide additional validation | 433 * The optional [check] function can provide additional validation |
| 434 * that the correct exception is being thrown. For example, to check | 434 * that the correct exception is being thrown. For example, to check |
| 435 * the type of the exception you could write this: | 435 * the type of the exception you could write this: |
| 436 * | 436 * |
| 437 * Expect.throws(myThrowingFunction, (e) => e is MyException); | 437 * Expect.throws(myThrowingFunction, (e) => e is MyException); |
| 438 */ | 438 */ |
| 439 static void throws(void f(), | 439 static void throws(void f(), |
| 440 [_CheckExceptionFn check = null, String reason = null]) { | 440 [_CheckExceptionFn check = null, String reason = null]) { |
| 441 String msg = reason == null ? "" : "($reason)"; | 441 String msg = reason == null ? "" : "($reason)"; |
| 442 if (f is! _Nullary) { | 442 if (f is! _Nullary) { |
| 443 // Only throws from executing the funtion body should count as throwing. | 443 // Only throws from executing the function body should count as throwing. |
| 444 // The failure to even call `f` should throw outside the try/catch. | 444 // The failure to even call `f` should throw outside the try/catch. |
| 445 _fail("Expect.throws$msg: Function f not callable with zero arguments"); | 445 _fail("Expect.throws$msg: Function f not callable with zero arguments"); |
| 446 } | 446 } |
| 447 try { | 447 try { |
| 448 f(); | 448 f(); |
| 449 } catch (e, s) { | 449 } catch (e, s) { |
| 450 if (check != null) { | 450 if (check != null) { |
| 451 if (!check(e)) { | 451 if (!check(e)) { |
| 452 _fail("Expect.throws$msg: Unexpected '$e'\n$s"); | 452 _fail("Expect.throws$msg: Unexpected '$e'\n$s"); |
| 453 } | 453 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 const TrustTypeAnnotations(); | 496 const TrustTypeAnnotations(); |
| 497 } | 497 } |
| 498 | 498 |
| 499 /// Annotation class for testing of dart2js. Use this as metadata on method | 499 /// Annotation class for testing of dart2js. Use this as metadata on method |
| 500 /// declarations to disable closed world assumptions on parameters, effectively | 500 /// declarations to disable closed world assumptions on parameters, effectively |
| 501 /// assuming that the runtime arguments could be any value. Note that the | 501 /// assuming that the runtime arguments could be any value. Note that the |
| 502 /// constraints due to [TrustTypeAnnotations] still apply. | 502 /// constraints due to [TrustTypeAnnotations] still apply. |
| 503 class AssumeDynamic { | 503 class AssumeDynamic { |
| 504 const AssumeDynamic(); | 504 const AssumeDynamic(); |
| 505 } | 505 } |
| OLD | NEW |