Skip to content

Commit 167c1f3

Browse files
committed
Remove some unused testing utilities
This file was forked during the package split and some of the APIs are unused in the test package test. Remove or make private all members of the utils library that are unused other test suites.
1 parent fe38650 commit 167c1f3

File tree

1 file changed

+7
-76
lines changed

1 file changed

+7
-76
lines changed

pkgs/test/test/utils.dart

+7-76
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ import 'package:test_core/src/runner/suite.dart';
3535
final suitePlatform = SuitePlatform(Runtime.vm, compiler: null);
3636

3737
// The last state change detected via [expectStates].
38-
State? lastState;
38+
State? _lastState;
3939

4040
/// Asserts that exactly [states] will be emitted via [liveTest.onStateChange].
4141
///
4242
/// The most recent emitted state is stored in [_lastState].
4343
void expectStates(LiveTest liveTest, Iterable<State> statesIter) {
4444
var states = Queue.of(statesIter);
4545
liveTest.onStateChange.listen(expectAsync1((state) {
46-
lastState = state;
46+
_lastState = state;
4747
expect(state, equals(states.removeFirst()));
4848
}, count: states.length, max: states.length));
4949
}
@@ -67,37 +67,16 @@ void expectSingleFailure(LiveTest liveTest) {
6767

6868
expectErrors(liveTest, [
6969
(error) {
70-
expect(lastState!.status, equals(Status.complete));
71-
expect(error, isTestFailure('oh no'));
70+
expect(_lastState!.status, equals(Status.complete));
71+
expect(error, _isTestFailure('oh no'));
7272
}
7373
]);
7474
}
7575

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-
9776
/// Returns a matcher that matches a [TestFailure] with the given [message].
9877
///
9978
/// [message] can be a string or a [Matcher].
100-
Matcher isTestFailure(Object message) => const TypeMatcher<TestFailure>()
79+
Matcher _isTestFailure(Object message) => const TypeMatcher<TestFailure>()
10180
.having((e) => e.message, 'message', message);
10281

10382
/// Returns a matcher that matches a [ApplicationException] with the given
@@ -109,21 +88,12 @@ Matcher isApplicationException(Object message) =>
10988
.having((e) => e.message, 'message', message);
11089

11190
/// Returns a local [LiveTest] that runs [body].
112-
LiveTest createTest(dynamic Function() body) {
91+
LiveTest _createTest(dynamic Function() body) {
11392
var test = LocalTest('test', Metadata(chainStackTraces: true), body);
11493
var suite = Suite(Group.root([test]), suitePlatform, ignoreTimeouts: false);
11594
return test.load(suite);
11695
}
11796

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-
12797
/// Asserts that [liveTest] has completed and passed.
12898
///
12999
/// If the test had any errors, they're surfaced nicely into the outer test.
@@ -147,46 +117,7 @@ void expectTestFailed(LiveTest liveTest, Object message) {
147117
expect(liveTest.state.status, equals(Status.complete));
148118
expect(liveTest.state.result, equals(Result.failure));
149119
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);
120+
expect(liveTest.errors.first.error, _isTestFailure(message));
190121
}
191122

192123
/// Runs [body] with a declarer and returns the declared entries.

0 commit comments

Comments
 (0)