Skip to content

Commit 9a267de

Browse files
authored
Remove some unused testing utilities (#2413)
This file was forked during the package split and some of the APIs are unused in the test package tests. Remove or make private all members of the utils library that are unused in other test suites.
1 parent fe38650 commit 9a267de

File tree

1 file changed

+6
-85
lines changed

1 file changed

+6
-85
lines changed

Diff for: pkgs/test/test/utils.dart

+6-85
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ import 'package:test/test.dart';
1111
import 'package:test_api/src/backend/declarer.dart';
1212
import 'package:test_api/src/backend/group.dart';
1313
import 'package:test_api/src/backend/group_entry.dart';
14-
import 'package:test_api/src/backend/invoker.dart';
1514
import 'package:test_api/src/backend/live_test.dart';
16-
import 'package:test_api/src/backend/metadata.dart';
1715
import 'package:test_api/src/backend/platform_selector.dart';
1816
import 'package:test_api/src/backend/runtime.dart';
1917
import 'package:test_api/src/backend/state.dart';
20-
import 'package:test_api/src/backend/suite.dart';
2118
import 'package:test_api/src/backend/suite_platform.dart';
2219
import 'package:test_core/src/runner/application_exception.dart';
2320
import 'package:test_core/src/runner/compiler_selection.dart';
@@ -35,15 +32,15 @@ import 'package:test_core/src/runner/suite.dart';
3532
final suitePlatform = SuitePlatform(Runtime.vm, compiler: null);
3633

3734
// The last state change detected via [expectStates].
38-
State? lastState;
35+
State? _lastState;
3936

4037
/// Asserts that exactly [states] will be emitted via [liveTest.onStateChange].
4138
///
4239
/// The most recent emitted state is stored in [_lastState].
4340
void expectStates(LiveTest liveTest, Iterable<State> statesIter) {
4441
var states = Queue.of(statesIter);
4542
liveTest.onStateChange.listen(expectAsync1((state) {
46-
lastState = state;
43+
_lastState = state;
4744
expect(state, equals(states.removeFirst()));
4845
}, count: states.length, max: states.length));
4946
}
@@ -67,37 +64,16 @@ void expectSingleFailure(LiveTest liveTest) {
6764

6865
expectErrors(liveTest, [
6966
(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'));
7269
}
7370
]);
7471
}
7572

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-
9773
/// Returns a matcher that matches a [TestFailure] with the given [message].
9874
///
9975
/// [message] can be a string or a [Matcher].
100-
Matcher isTestFailure(Object message) => const TypeMatcher<TestFailure>()
76+
Matcher _isTestFailure(Object message) => const TypeMatcher<TestFailure>()
10177
.having((e) => e.message, 'message', message);
10278

10379
/// Returns a matcher that matches a [ApplicationException] with the given
@@ -108,22 +84,6 @@ Matcher isApplicationException(Object message) =>
10884
const TypeMatcher<ApplicationException>()
10985
.having((e) => e.message, 'message', message);
11086

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-
12787
/// Asserts that [liveTest] has completed and passed.
12888
///
12989
/// If the test had any errors, they're surfaced nicely into the outer test.
@@ -147,46 +107,7 @@ void expectTestFailed(LiveTest liveTest, Object message) {
147107
expect(liveTest.state.status, equals(Status.complete));
148108
expect(liveTest.state.result, equals(Result.failure));
149109
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));
190111
}
191112

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

0 commit comments

Comments
 (0)