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 test; |
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/backend/test_platform.dart'; |
15 import 'src/deprecated/configuration.dart'; | 15 import 'src/deprecated/configuration.dart'; |
(...skipping 18 matching lines...) Expand all Loading... |
34 /// | 34 /// |
35 /// This is used if a test file is run directly, rather than through the runner. | 35 /// This is used if a test file is run directly, rather than through the runner. |
36 Declarer _globalDeclarer; | 36 Declarer _globalDeclarer; |
37 | 37 |
38 /// Gets the declarer for the current scope. | 38 /// Gets the declarer for the current scope. |
39 /// | 39 /// |
40 /// When using the runner, this returns the [Zone]-scoped declarer that's set by | 40 /// When using the runner, this returns the [Zone]-scoped declarer that's set by |
41 /// [IsolateListener] or [IframeListener]. If the test file is run directly, | 41 /// [IsolateListener] or [IframeListener]. If the test file is run directly, |
42 /// this returns [_globalDeclarer] (and sets it up on the first call). | 42 /// this returns [_globalDeclarer] (and sets it up on the first call). |
43 Declarer get _declarer { | 43 Declarer get _declarer { |
44 var declarer = Zone.current[#unittest.declarer]; | 44 var declarer = Zone.current[#test.declarer]; |
45 if (declarer != null) return declarer; | 45 if (declarer != null) return declarer; |
46 if (_globalDeclarer != null) return _globalDeclarer; | 46 if (_globalDeclarer != null) return _globalDeclarer; |
47 | 47 |
48 // 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. |
49 // 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 |
50 // [_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 |
51 // finished being defined. | 51 // finished being defined. |
52 _globalDeclarer = new Declarer(); | 52 _globalDeclarer = new Declarer(); |
53 scheduleMicrotask(() { | 53 scheduleMicrotask(() { |
54 var suite = | 54 var suite = |
55 new Suite(_globalDeclarer.tests, | 55 new Suite(_globalDeclarer.tests, |
56 path: p.prettyUri(Uri.base), | 56 path: p.prettyUri(Uri.base), |
57 platform: "VM") | 57 platform: "VM") |
58 .filter(TestPlatform.vm, os: currentOSGuess); | 58 .filter(TestPlatform.vm, os: currentOSGuess); |
59 // 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. |
60 new NoIoCompactReporter([suite], color: true).run(); | 60 new NoIoCompactReporter([suite], color: true).run(); |
61 }); | 61 }); |
62 return _globalDeclarer; | 62 return _globalDeclarer; |
63 } | 63 } |
64 | 64 |
65 // 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 |
66 // they're called after the declarer has finished declaring. | 66 // they're called after the declarer has finished declaring. |
67 /// Creates a new test case with the given description and body. | 67 /// Creates a new test case with the given description and body. |
68 /// | 68 /// |
69 /// The description will be added to the descriptions of any surrounding | 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 | 70 /// [group]s. If [testOn] is passed, it's parsed as a [platform selector][]; the |
71 /// test will only be run on matching platforms. | 71 /// test will only be run on matching platforms. |
72 /// | 72 /// |
73 /// [platform selector]: https://github.com/dart-lang/unittest/#platform-selecto
r-syntax | 73 /// [platform selector]: https://github.com/dart-lang/test/#platform-selector-sy
ntax |
74 void test(String description, body(), {String testOn}) => | 74 void test(String description, body(), {String testOn}) => |
75 _declarer.test(description, body, testOn: testOn); | 75 _declarer.test(description, body, testOn: testOn); |
76 | 76 |
77 /// Creates a group of tests. | 77 /// Creates a group of tests. |
78 /// | 78 /// |
79 /// A group's description is included in the descriptions of any tests or | 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 | 80 /// sub-groups it contains. [setUp] and [tearDown] are also scoped to the |
81 /// containing group. | 81 /// containing group. |
82 /// | 82 /// |
83 /// If [testOn] is passed, it's parsed as a [platform selector][]; the test will | 83 /// If [testOn] is passed, it's parsed as a [platform selector][]; the test will |
84 /// only be run on matching platforms. | 84 /// only be run on matching platforms. |
85 /// | 85 /// |
86 /// [platform selector]: https://github.com/dart-lang/unittest/#platform-selecto
r-syntax | 86 /// [platform selector]: https://github.com/dart-lang/test/#platform-selector-sy
ntax |
87 void group(String description, void body(), {String testOn}) => | 87 void group(String description, void body(), {String testOn}) => |
88 _declarer.group(description, body, testOn: testOn); | 88 _declarer.group(description, body, testOn: testOn); |
89 | 89 |
90 /// Registers a function to be run before tests. | 90 /// Registers a function to be run before tests. |
91 /// | 91 /// |
92 /// This function will be called before each test is run. [callback] may be | 92 /// This function will be called before each test is run. [callback] may be |
93 /// asynchronous; if so, it must return a [Future]. | 93 /// asynchronous; if so, it must return a [Future]. |
94 /// | 94 /// |
95 /// If this is called within a test group, it applies only to tests in that | 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 | 96 /// group. [callback] will be run after any set-up callbacks in parent groups or |
(...skipping 21 matching lines...) Expand all Loading... |
118 Invoker.current.handleError(error, stackTrace); | 118 Invoker.current.handleError(error, stackTrace); |
119 | 119 |
120 // What follows are stubs for various top-level names supported by unittest | 120 // What follows are stubs for various top-level names supported by unittest |
121 // 0.11.*. These are preserved for the time being for ease of migration, but | 121 // 0.11.*. These are preserved for the time being for ease of migration, but |
122 // should be removed before this is released as stable. | 122 // should be removed before this is released as stable. |
123 | 123 |
124 @deprecated | 124 @deprecated |
125 typedef dynamic TestFunction(); | 125 typedef dynamic TestFunction(); |
126 | 126 |
127 @deprecated | 127 @deprecated |
128 Configuration unittestConfiguration = new Configuration(); | 128 Configuration testConfiguration = new Configuration(); |
129 | 129 |
130 @deprecated | 130 @deprecated |
131 bool formatStacks = true; | 131 bool formatStacks = true; |
132 | 132 |
133 @deprecated | 133 @deprecated |
134 bool filterStacks = true; | 134 bool filterStacks = true; |
135 | 135 |
136 @deprecated | 136 @deprecated |
137 String groupSep = ' '; | 137 String groupSep = ' '; |
138 | 138 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 void setSoloTest(int id) {} | 182 void setSoloTest(int id) {} |
183 | 183 |
184 @deprecated | 184 @deprecated |
185 void enableTest(int id) {} | 185 void enableTest(int id) {} |
186 | 186 |
187 @deprecated | 187 @deprecated |
188 void disableTest(int id) {} | 188 void disableTest(int id) {} |
189 | 189 |
190 @deprecated | 190 @deprecated |
191 withTestEnvironment(callback()) => callback(); | 191 withTestEnvironment(callback()) => callback(); |
OLD | NEW |