OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 part of unittest; | 5 library unittest.test_environment; |
6 | 6 |
7 /// Class for encapsulating test environment state. | 7 import 'dart:async'; |
| 8 |
| 9 import 'configuration.dart'; |
| 10 import 'group_context.dart'; |
| 11 import 'internal_test_case.dart'; |
| 12 |
| 13 /// The default unittest environment. |
| 14 final _defaultEnvironment = new TestEnvironment(); |
| 15 |
| 16 /// The current unittest environment. |
| 17 TestEnvironment get environment { |
| 18 var environment = Zone.current[#unittest.environment]; |
| 19 return environment == null ? _defaultEnvironment : environment; |
| 20 } |
| 21 |
| 22 // The current environment's configuration. |
| 23 Configuration get config => environment.config; |
| 24 |
| 25 /// Encapsulates the state of the test environment. |
8 /// | 26 /// |
9 /// This is used by the [withTestEnvironment] method to support multiple | 27 /// This is used by the [withTestEnvironment] method to support multiple |
10 /// invocations of the unittest library within the same application | 28 /// invocations of the unittest library within the same application |
11 /// instance. | 29 /// instance. |
12 class _TestEnvironment { | 30 class TestEnvironment { |
| 31 /// The environment's configuration. |
13 Configuration config; | 32 Configuration config; |
14 | 33 |
15 // We use a 'dummy' context for the top level to eliminate null | 34 /// The top-level group context. |
16 // checks when querying the context. This allows us to easily | 35 /// |
17 // support top-level [setUp]/[tearDown] functions as well. | 36 /// We use a 'dummy' context for the top level to eliminate null checks when |
18 final rootContext = new _GroupContext(); | 37 /// querying the context. This allows us to easily support top-level |
19 _GroupContext currentContext; | 38 /// [setUp]/[tearDown] functions as well. |
| 39 final rootContext = new GroupContext.root(); |
| 40 |
| 41 /// The current group context. |
| 42 GroupContext currentContext; |
20 | 43 |
21 /// The [currentTestCaseIndex] represents the index of the currently running | 44 /// The [currentTestCaseIndex] represents the index of the currently running |
22 /// test case. | 45 /// test case. |
23 /// | 46 /// |
24 /// If this is -1 it implies the test system is not running. | 47 /// If this is -1 it implies the test system is not running. |
25 /// It will be set to [number of test cases] as a short-lived state flagging | 48 /// It will be set to [number of test cases] as a short-lived state flagging |
26 /// that the last test has completed. | 49 /// that the last test has completed. |
27 int currentTestCaseIndex = -1; | 50 int currentTestCaseIndex = -1; |
28 | 51 |
29 /// The [initialized] variable specifies whether the framework | 52 /// The [initialized] variable specifies whether the framework |
30 /// has been initialized. | 53 /// has been initialized. |
31 bool initialized = false; | 54 bool initialized = false; |
32 | 55 |
33 /// The time since we last gave asynchronous code a chance to be scheduled. | 56 /// The time since we last gave asynchronous code a chance to be scheduled. |
34 int lastBreath = new DateTime.now().millisecondsSinceEpoch; | 57 int lastBreath = new DateTime.now().millisecondsSinceEpoch; |
35 | 58 |
36 /// The set of tests to run can be restricted by using [solo_test] and | 59 /// The number of [solo_group]s deep we are currently. |
37 /// [solo_group]. | |
38 /// | |
39 /// As groups can be nested we use a counter to keep track of the nesting | |
40 /// level of soloing, and a flag to tell if we have seen any solo tests. | |
41 int soloNestingLevel = 0; | 60 int soloNestingLevel = 0; |
| 61 |
| 62 /// Whether we've seen a [solo_test]. |
42 bool soloTestSeen = false; | 63 bool soloTestSeen = false; |
43 | 64 |
44 /// The list of test cases to run. | 65 /// The list of test cases to run. |
45 final List<TestCase> testCases = new List<TestCase>(); | 66 final testCases = new List<InternalTestCase>(); |
46 | 67 |
47 /// The [uncaughtErrorMessage] holds the error messages that are printed | 68 /// The error message that is printed in the test summary. |
48 /// in the test summary. | |
49 String uncaughtErrorMessage; | 69 String uncaughtErrorMessage; |
50 | 70 |
51 _TestEnvironment() { | 71 TestEnvironment() { |
52 currentContext = rootContext; | 72 currentContext = rootContext; |
53 } | 73 } |
54 } | 74 } |
OLD | NEW |