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 test; | 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/frontend/timeout.dart'; |
15 import 'src/runner/reporter/no_io_compact.dart'; | 16 import 'src/runner/reporter/no_io_compact.dart'; |
16 import 'src/utils.dart'; | 17 import 'src/utils.dart'; |
17 | 18 |
18 export 'package:matcher/matcher.dart'; | 19 export 'package:matcher/matcher.dart'; |
19 | 20 |
20 export 'src/frontend/expect.dart'; | 21 export 'src/frontend/expect.dart'; |
21 export 'src/frontend/expect_async.dart'; | 22 export 'src/frontend/expect_async.dart'; |
22 export 'src/frontend/future_matchers.dart'; | 23 export 'src/frontend/future_matchers.dart'; |
23 export 'src/frontend/prints_matcher.dart'; | 24 export 'src/frontend/prints_matcher.dart'; |
24 export 'src/frontend/test_on.dart'; | 25 export 'src/frontend/test_on.dart'; |
25 export 'src/frontend/throws_matcher.dart'; | 26 export 'src/frontend/throws_matcher.dart'; |
26 export 'src/frontend/throws_matchers.dart'; | 27 export 'src/frontend/throws_matchers.dart'; |
| 28 export 'src/frontend/timeout.dart'; |
27 | 29 |
28 /// The global declarer. | 30 /// The global declarer. |
29 /// | 31 /// |
30 /// This is used if a test file is run directly, rather than through the runner. | 32 /// This is used if a test file is run directly, rather than through the runner. |
31 Declarer _globalDeclarer; | 33 Declarer _globalDeclarer; |
32 | 34 |
33 /// Gets the declarer for the current scope. | 35 /// Gets the declarer for the current scope. |
34 /// | 36 /// |
35 /// When using the runner, this returns the [Zone]-scoped declarer that's set by | 37 /// When using the runner, this returns the [Zone]-scoped declarer that's set by |
36 /// [IsolateListener] or [IframeListener]. If the test file is run directly, | 38 /// [IsolateListener] or [IframeListener]. If the test file is run directly, |
(...skipping 22 matching lines...) Expand all Loading... |
59 | 61 |
60 // TODO(nweiz): This and other top-level functions should throw exceptions if | 62 // TODO(nweiz): This and other top-level functions should throw exceptions if |
61 // they're called after the declarer has finished declaring. | 63 // they're called after the declarer has finished declaring. |
62 /// Creates a new test case with the given description and body. | 64 /// Creates a new test case with the given description and body. |
63 /// | 65 /// |
64 /// The description will be added to the descriptions of any surrounding | 66 /// The description will be added to the descriptions of any surrounding |
65 /// [group]s. If [testOn] is passed, it's parsed as a [platform selector][]; the | 67 /// [group]s. If [testOn] is passed, it's parsed as a [platform selector][]; the |
66 /// test will only be run on matching platforms. | 68 /// test will only be run on matching platforms. |
67 /// | 69 /// |
68 /// [platform selector]: https://github.com/dart-lang/test/#platform-selector-sy
ntax | 70 /// [platform selector]: https://github.com/dart-lang/test/#platform-selector-sy
ntax |
69 void test(String description, body(), {String testOn}) => | 71 /// |
70 _declarer.test(description, body, testOn: testOn); | 72 /// If [timeout] is passed, it's used to modify or replace the default timeout |
| 73 /// of 30 seconds. Timeout modifications take precedence in suite-group-test |
| 74 /// order, so [timeout] will also modify any timeouts set on the group or suite. |
| 75 void test(String description, body(), {String testOn, Timeout timeout}) => |
| 76 _declarer.test(description, body, testOn: testOn, timeout: timeout); |
71 | 77 |
72 /// Creates a group of tests. | 78 /// Creates a group of tests. |
73 /// | 79 /// |
74 /// A group's description is included in the descriptions of any tests or | 80 /// A group's description is included in the descriptions of any tests or |
75 /// sub-groups it contains. [setUp] and [tearDown] are also scoped to the | 81 /// sub-groups it contains. [setUp] and [tearDown] are also scoped to the |
76 /// containing group. | 82 /// containing group. |
77 /// | 83 /// |
78 /// If [testOn] is passed, it's parsed as a [platform selector][]; the test will | 84 /// If [testOn] is passed, it's parsed as a [platform selector][]; the test will |
79 /// only be run on matching platforms. | 85 /// only be run on matching platforms. |
80 /// | 86 /// |
81 /// [platform selector]: https://github.com/dart-lang/test/#platform-selector-sy
ntax | 87 /// [platform selector]: https://github.com/dart-lang/test/#platform-selector-sy
ntax |
82 void group(String description, void body(), {String testOn}) => | 88 /// |
83 _declarer.group(description, body, testOn: testOn); | 89 /// If [timeout] is passed, it's used to modify or replace the default timeout |
| 90 /// of 30 seconds. Timeout modifications take precedence in suite-group-test |
| 91 /// order, so [timeout] will also modify any timeouts set on the suite, and will |
| 92 /// be modified by any timeouts set on individual tests. |
| 93 void group(String description, void body(), {String testOn, Timeout timeout}) => |
| 94 _declarer.group(description, body, testOn: testOn, timeout: timeout); |
84 | 95 |
85 /// Registers a function to be run before tests. | 96 /// Registers a function to be run before tests. |
86 /// | 97 /// |
87 /// This function will be called before each test is run. [callback] may be | 98 /// This function will be called before each test is run. [callback] may be |
88 /// asynchronous; if so, it must return a [Future]. | 99 /// asynchronous; if so, it must return a [Future]. |
89 /// | 100 /// |
90 /// If this is called within a test group, it applies only to tests in that | 101 /// If this is called within a test group, it applies only to tests in that |
91 /// group. [callback] will be run after any set-up callbacks in parent groups or | 102 /// group. [callback] will be run after any set-up callbacks in parent groups or |
92 /// at the top level. | 103 /// at the top level. |
93 void setUp(callback()) => _declarer.setUp(callback); | 104 void setUp(callback()) => _declarer.setUp(callback); |
(...skipping 10 matching lines...) Expand all Loading... |
104 | 115 |
105 /// Handle an error that occurs outside of any test. | 116 /// Handle an error that occurs outside of any test. |
106 void handleExternalError(error, String message, [stackTrace]) { | 117 void handleExternalError(error, String message, [stackTrace]) { |
107 // TODO(nweiz): handle this better. | 118 // TODO(nweiz): handle this better. |
108 registerException(error, stackTrace); | 119 registerException(error, stackTrace); |
109 } | 120 } |
110 | 121 |
111 /// Registers an exception that was caught for the current test. | 122 /// Registers an exception that was caught for the current test. |
112 void registerException(error, [StackTrace stackTrace]) => | 123 void registerException(error, [StackTrace stackTrace]) => |
113 Invoker.current.handleError(error, stackTrace); | 124 Invoker.current.handleError(error, stackTrace); |
OLD | NEW |