OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library unittest.test_environment; | |
6 | |
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. | |
26 /// | |
27 /// This is used by the [withTestEnvironment] method to support multiple | |
28 /// invocations of the unittest library within the same application | |
29 /// instance. | |
30 class TestEnvironment { | |
31 /// The environment's configuration. | |
32 Configuration config; | |
33 | |
34 /// The top-level group context. | |
35 /// | |
36 /// We use a 'dummy' context for the top level to eliminate null checks when | |
37 /// querying the context. This allows us to easily support top-level | |
38 /// [setUp]/[tearDown] functions as well. | |
39 final rootContext = new GroupContext.root(); | |
40 | |
41 /// The current group context. | |
42 GroupContext currentContext; | |
43 | |
44 /// The [currentTestCaseIndex] represents the index of the currently running | |
45 /// test case. | |
46 /// | |
47 /// If this is -1 it implies the test system is not running. | |
48 /// It will be set to [number of test cases] as a short-lived state flagging | |
49 /// that the last test has completed. | |
50 int currentTestCaseIndex = -1; | |
51 | |
52 /// The [initialized] variable specifies whether the framework | |
53 /// has been initialized. | |
54 bool initialized = false; | |
55 | |
56 /// The time since we last gave asynchronous code a chance to be scheduled. | |
57 int lastBreath = new DateTime.now().millisecondsSinceEpoch; | |
58 | |
59 /// The number of [solo_group]s deep we are currently. | |
60 int soloNestingLevel = 0; | |
61 | |
62 /// Whether we've seen a [solo_test]. | |
63 bool soloTestSeen = false; | |
64 | |
65 /// The list of test cases to run. | |
66 final testCases = new List<InternalTestCase>(); | |
67 | |
68 /// The error message that is printed in the test summary. | |
69 String uncaughtErrorMessage; | |
70 | |
71 TestEnvironment() { | |
72 currentContext = rootContext; | |
73 } | |
74 } | |
OLD | NEW |