@@ -11,13 +11,10 @@ import 'package:test/test.dart';
11
11
import 'package:test_api/src/backend/declarer.dart' ;
12
12
import 'package:test_api/src/backend/group.dart' ;
13
13
import 'package:test_api/src/backend/group_entry.dart' ;
14
- import 'package:test_api/src/backend/invoker.dart' ;
15
14
import 'package:test_api/src/backend/live_test.dart' ;
16
- import 'package:test_api/src/backend/metadata.dart' ;
17
15
import 'package:test_api/src/backend/platform_selector.dart' ;
18
16
import 'package:test_api/src/backend/runtime.dart' ;
19
17
import 'package:test_api/src/backend/state.dart' ;
20
- import 'package:test_api/src/backend/suite.dart' ;
21
18
import 'package:test_api/src/backend/suite_platform.dart' ;
22
19
import 'package:test_core/src/runner/application_exception.dart' ;
23
20
import 'package:test_core/src/runner/compiler_selection.dart' ;
@@ -35,15 +32,15 @@ import 'package:test_core/src/runner/suite.dart';
35
32
final suitePlatform = SuitePlatform (Runtime .vm, compiler: null );
36
33
37
34
// The last state change detected via [expectStates].
38
- State ? lastState ;
35
+ State ? _lastState ;
39
36
40
37
/// Asserts that exactly [states] will be emitted via [liveTest.onStateChange] .
41
38
///
42
39
/// The most recent emitted state is stored in [_lastState] .
43
40
void expectStates (LiveTest liveTest, Iterable <State > statesIter) {
44
41
var states = Queue .of (statesIter);
45
42
liveTest.onStateChange.listen (expectAsync1 ((state) {
46
- lastState = state;
43
+ _lastState = state;
47
44
expect (state, equals (states.removeFirst ()));
48
45
}, count: states.length, max: states.length));
49
46
}
@@ -67,37 +64,16 @@ void expectSingleFailure(LiveTest liveTest) {
67
64
68
65
expectErrors (liveTest, [
69
66
(error) {
70
- expect (lastState ! .status, equals (Status .complete));
71
- expect (error, isTestFailure ('oh no' ));
67
+ expect (_lastState ! .status, equals (Status .complete));
68
+ expect (error, _isTestFailure ('oh no' ));
72
69
}
73
70
]);
74
71
}
75
72
76
- /// Asserts that [liveTest] will have a single error, the string `"oh no"` .
77
- void expectSingleError (LiveTest liveTest) {
78
- expectStates (liveTest, [
79
- const State (Status .running, Result .success),
80
- const State (Status .complete, Result .error)
81
- ]);
82
-
83
- expectErrors (liveTest, [
84
- (error) {
85
- expect (lastState! .status, equals (Status .complete));
86
- expect (error, equals ('oh no' ));
87
- }
88
- ]);
89
- }
90
-
91
- /// Returns a matcher that matches a callback or Future that throws a
92
- /// [TestFailure] with the given [message] .
93
- ///
94
- /// [message] can be a string or a [Matcher] .
95
- Matcher throwsTestFailure (Object message) => throwsA (isTestFailure (message));
96
-
97
73
/// Returns a matcher that matches a [TestFailure] with the given [message] .
98
74
///
99
75
/// [message] can be a string or a [Matcher] .
100
- Matcher isTestFailure (Object message) => const TypeMatcher <TestFailure >()
76
+ Matcher _isTestFailure (Object message) => const TypeMatcher <TestFailure >()
101
77
.having ((e) => e.message, 'message' , message);
102
78
103
79
/// Returns a matcher that matches a [ApplicationException] with the given
@@ -108,22 +84,6 @@ Matcher isApplicationException(Object message) =>
108
84
const TypeMatcher <ApplicationException >()
109
85
.having ((e) => e.message, 'message' , message);
110
86
111
- /// Returns a local [LiveTest] that runs [body] .
112
- LiveTest createTest (dynamic Function () body) {
113
- var test = LocalTest ('test' , Metadata (chainStackTraces: true ), body);
114
- var suite = Suite (Group .root ([test]), suitePlatform, ignoreTimeouts: false );
115
- return test.load (suite);
116
- }
117
-
118
- /// Runs [body] as a test.
119
- ///
120
- /// Once it completes, returns the [LiveTest] used to run it.
121
- Future <LiveTest > runTestBody (dynamic Function () body) async {
122
- var liveTest = createTest (body);
123
- await liveTest.run ();
124
- return liveTest;
125
- }
126
-
127
87
/// Asserts that [liveTest] has completed and passed.
128
88
///
129
89
/// If the test had any errors, they're surfaced nicely into the outer test.
@@ -147,46 +107,7 @@ void expectTestFailed(LiveTest liveTest, Object message) {
147
107
expect (liveTest.state.status, equals (Status .complete));
148
108
expect (liveTest.state.result, equals (Result .failure));
149
109
expect (liveTest.errors, hasLength (1 ));
150
- expect (liveTest.errors.first.error, isTestFailure (message));
151
- }
152
-
153
- /// Assert that the [test] callback causes a test to block until [stopBlocking]
154
- /// is called at some later time.
155
- ///
156
- /// [stopBlocking] is passed the return value of [test] .
157
- Future <void > expectTestBlocks (
158
- dynamic Function () test, dynamic Function (dynamic ) stopBlocking) async {
159
- late LiveTest liveTest;
160
- late Future <void > future;
161
- liveTest = createTest (() {
162
- var value = test ();
163
- future = pumpEventQueue ().then ((_) {
164
- expect (liveTest.state.status, equals (Status .running));
165
- stopBlocking (value);
166
- });
167
- });
168
-
169
- await liveTest.run ();
170
- expectTestPassed (liveTest);
171
- // Ensure that the outer test doesn't complete until the inner future
172
- // completes.
173
- return future;
174
- }
175
-
176
- /// Runs [body] with a declarer, runs all the declared tests, and asserts that
177
- /// they pass.
178
- ///
179
- /// This is typically used to run multiple tests where later tests make
180
- /// assertions about the results of previous ones.
181
- Future <void > expectTestsPass (void Function () body) async {
182
- var engine = declareEngine (body);
183
- var success = await engine.run ();
184
-
185
- for (var test in engine.liveTests) {
186
- expectTestPassed (test);
187
- }
188
-
189
- expect (success, isTrue);
110
+ expect (liveTest.errors.first.error, _isTestFailure (message));
190
111
}
191
112
192
113
/// Runs [body] with a declarer and returns the declared entries.
0 commit comments