| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 library unittest; | 5 library unittest; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
| 10 | 10 |
| 11 import 'src/backend/declarer.dart'; | 11 import 'src/backend/declarer.dart'; |
| 12 import 'src/backend/invoker.dart'; | 12 import 'src/backend/invoker.dart'; |
| 13 import 'src/backend/suite.dart'; | 13 import 'src/backend/suite.dart'; |
| 14 import 'src/backend/test_platform.dart'; |
| 14 import 'src/deprecated/configuration.dart'; | 15 import 'src/deprecated/configuration.dart'; |
| 15 import 'src/deprecated/test_case.dart'; | 16 import 'src/deprecated/test_case.dart'; |
| 16 import 'src/runner/reporter/no_io_compact.dart'; | 17 import 'src/runner/reporter/no_io_compact.dart'; |
| 18 import 'src/utils.dart'; |
| 17 | 19 |
| 18 export 'package:matcher/matcher.dart'; | 20 export 'package:matcher/matcher.dart'; |
| 19 | 21 |
| 20 export 'src/deprecated/configuration.dart'; | 22 export 'src/deprecated/configuration.dart'; |
| 21 export 'src/deprecated/simple_configuration.dart'; | 23 export 'src/deprecated/simple_configuration.dart'; |
| 22 export 'src/deprecated/test_case.dart'; | 24 export 'src/deprecated/test_case.dart'; |
| 23 export 'src/frontend/expect.dart'; | 25 export 'src/frontend/expect.dart'; |
| 24 export 'src/frontend/expect_async.dart'; | 26 export 'src/frontend/expect_async.dart'; |
| 25 export 'src/frontend/future_matchers.dart'; | 27 export 'src/frontend/future_matchers.dart'; |
| 26 export 'src/frontend/prints_matcher.dart'; | 28 export 'src/frontend/prints_matcher.dart'; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 42 var declarer = Zone.current[#unittest.declarer]; | 44 var declarer = Zone.current[#unittest.declarer]; |
| 43 if (declarer != null) return declarer; | 45 if (declarer != null) return declarer; |
| 44 if (_globalDeclarer != null) return _globalDeclarer; | 46 if (_globalDeclarer != null) return _globalDeclarer; |
| 45 | 47 |
| 46 // Since there's no Zone-scoped declarer, the test file is being run directly. | 48 // Since there's no Zone-scoped declarer, the test file is being run directly. |
| 47 // In order to run the tests, we set up our own Declarer via | 49 // In order to run the tests, we set up our own Declarer via |
| 48 // [_globalDeclarer], and schedule a microtask to run the tests once they're | 50 // [_globalDeclarer], and schedule a microtask to run the tests once they're |
| 49 // finished being defined. | 51 // finished being defined. |
| 50 _globalDeclarer = new Declarer(); | 52 _globalDeclarer = new Declarer(); |
| 51 scheduleMicrotask(() { | 53 scheduleMicrotask(() { |
| 52 var suite = new Suite(_globalDeclarer.tests, | 54 var suite = |
| 53 path: p.prettyUri(Uri.base), | 55 new Suite(_globalDeclarer.tests, |
| 54 platform: "VM"); | 56 path: p.prettyUri(Uri.base), |
| 57 platform: "VM") |
| 58 .filter(TestPlatform.vm, os: currentOsGuess); |
| 55 // TODO(nweiz): Set the exit code on the VM when issue 6943 is fixed. | 59 // TODO(nweiz): Set the exit code on the VM when issue 6943 is fixed. |
| 56 new NoIoCompactReporter([suite], color: true).run(); | 60 new NoIoCompactReporter([suite], color: true).run(); |
| 57 }); | 61 }); |
| 58 return _globalDeclarer; | 62 return _globalDeclarer; |
| 59 } | 63 } |
| 60 | 64 |
| 61 // TODO(nweiz): This and other top-level functions should throw exceptions if | 65 // TODO(nweiz): This and other top-level functions should throw exceptions if |
| 62 // they're called after the declarer has finished declaring. | 66 // they're called after the declarer has finished declaring. |
| 63 void test(String description, body()) => _declarer.test(description, body); | 67 /// Creates a new test case with the given description and body. |
| 68 /// |
| 69 /// The description will be added to the descriptions of any surrounding |
| 70 /// [group]s. If [testOn] is passed, it's parsed as a [platform selector][]; the |
| 71 /// test will only be run on matching platforms. |
| 72 /// |
| 73 /// [platform selector]: https://github.com/dart-lang/unittest/#platform-selecto
r-syntax |
| 74 void test(String description, body(), {String testOn}) => |
| 75 _declarer.test(description, body, testOn: testOn); |
| 64 | 76 |
| 65 void group(String description, void body()) => | 77 /// Creates a group of tests. |
| 66 _declarer.group(description, body); | 78 /// |
| 79 /// A group's description is included in the descriptions of any tests or |
| 80 /// sub-groups it contains. [setUp] and [tearDown] are also scoped to the |
| 81 /// containing group. |
| 82 /// |
| 83 /// If [testOn] is passed, it's parsed as a [platform selector][]; the test will |
| 84 /// only be run on matching platforms. |
| 85 /// |
| 86 /// [platform selector]: https://github.com/dart-lang/unittest/#platform-selecto
r-syntax |
| 87 void group(String description, void body(), {String testOn}) => |
| 88 _declarer.group(description, body, testOn: testOn); |
| 67 | 89 |
| 90 /// Registers a function to be run before tests. |
| 91 /// |
| 92 /// This function will be called before each test is run. [callback] may be |
| 93 /// asynchronous; if so, it must return a [Future]. |
| 94 /// |
| 95 /// If this is called within a test group, it applies only to tests in that |
| 96 /// group. [callback] will be run after any set-up callbacks in parent groups or |
| 97 /// at the top level. |
| 68 void setUp(callback()) => _declarer.setUp(callback); | 98 void setUp(callback()) => _declarer.setUp(callback); |
| 69 | 99 |
| 100 /// Registers a function to be run after tests. |
| 101 /// |
| 102 /// This function will be called after each test is run. [callback] may be |
| 103 /// asynchronous; if so, it must return a [Future]. |
| 104 /// |
| 105 /// If this is called within a test group, it applies only to tests in that |
| 106 /// group. [callback] will be run before any tear-down callbacks in parent |
| 107 /// groups or at the top level. |
| 70 void tearDown(callback()) => _declarer.tearDown(callback); | 108 void tearDown(callback()) => _declarer.tearDown(callback); |
| 71 | 109 |
| 72 /// Handle an error that occurs outside of any test. | 110 /// Handle an error that occurs outside of any test. |
| 73 void handleExternalError(error, String message, [stackTrace]) { | 111 void handleExternalError(error, String message, [stackTrace]) { |
| 74 // TODO(nweiz): handle this better. | 112 // TODO(nweiz): handle this better. |
| 75 registerException(error, stackTrace); | 113 registerException(error, stackTrace); |
| 76 } | 114 } |
| 77 | 115 |
| 78 /// Registers an exception that was caught for the current test. | 116 /// Registers an exception that was caught for the current test. |
| 79 void registerException(error, [StackTrace stackTrace]) => | 117 void registerException(error, [StackTrace stackTrace]) => |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 void setSoloTest(int id) {} | 182 void setSoloTest(int id) {} |
| 145 | 183 |
| 146 @deprecated | 184 @deprecated |
| 147 void enableTest(int id) {} | 185 void enableTest(int id) {} |
| 148 | 186 |
| 149 @deprecated | 187 @deprecated |
| 150 void disableTest(int id) {} | 188 void disableTest(int id) {} |
| 151 | 189 |
| 152 @deprecated | 190 @deprecated |
| 153 withTestEnvironment(callback()) => callback(); | 191 withTestEnvironment(callback()) => callback(); |
| OLD | NEW |