Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: test/utils.dart

Issue 914963003: Add a VmListener and IsolateTest class for running tests in other isolates. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Code review changes Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/invoker_test.dart ('k') | test/vm_listener_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/utils.dart
diff --git a/test/utils.dart b/test/utils.dart
index 17caceade76d789046cb438d4b71d0700521b302..f9b4075d70df066393024421491889b9a0561c3b 100644
--- a/test/utils.dart
+++ b/test/utils.dart
@@ -5,14 +5,72 @@
library unittest.test.utils;
import 'dart:async';
+import 'dart:collection';
+import 'package:unittest/src/live_test.dart';
+import 'package:unittest/src/remote_exception.dart';
+import 'package:unittest/src/state.dart';
import 'package:unittest/unittest.dart';
+// The last state change detected via [expectStates].
+State lastState;
+
+/// Asserts that exactly [states] will be emitted via [liveTest.onStateChange].
+///
+/// The most recent emitted state is stored in [_lastState].
+void expectStates(LiveTest liveTest, Iterable<State> statesIter) {
+ var states = new Queue.from(statesIter);
+ liveTest.onStateChange.listen(expectAsync((state) {
+ lastState = state;
+ expect(state, equals(states.removeFirst()));
+ }, count: states.length, max: states.length));
+}
+
+/// Asserts that errors will be emitted via [liveTest.onError] that match
+/// [validators], in order.
+void expectErrors(LiveTest liveTest, Iterable<Function> validatorsIter) {
+ var validators = new Queue.from(validatorsIter);
+ liveTest.onError.listen(expectAsync((error) {
+ validators.removeFirst()(error.error);
+ }, count: validators.length, max: validators.length));
+}
+
+/// Asserts that [liveTest] will have a single failure with message `"oh no"`.
+void expectSingleFailure(LiveTest liveTest) {
+ expectStates(liveTest, [
+ const State(Status.running, Result.success),
+ const State(Status.complete, Result.failure)
+ ]);
+
+ expectErrors(liveTest, [(error) {
+ expect(lastState.status, equals(Status.complete));
+ expect(error, isTestFailure("oh no"));
+ }]);
+}
+
+/// Asserts that [liveTest] will have a single error, the string `"oh no"`.
+void expectSingleError(LiveTest liveTest) {
+ expectStates(liveTest, [
+ const State(Status.running, Result.success),
+ const State(Status.complete, Result.error)
+ ]);
+
+ expectErrors(liveTest, [(error) {
+ expect(lastState.status, equals(Status.complete));
+ expect(error, equals("oh no"));
+ }]);
+}
+
/// Returns a matcher that matches a [TestFailure] with the given [message].
Matcher isTestFailure(String message) => predicate(
(error) => error is TestFailure && error.message == message,
'is a TestFailure with message "$message"');
+/// Returns a matcher that matches a [RemoteException] with the given [message].
+Matcher isRemoteException(String message) => predicate(
+ (error) => error is RemoteException && error.message == message,
+ 'is a RemoteException with message "$message"');
+
/// Returns a [Future] that completes after pumping the event queue [times]
/// times.
///
« no previous file with comments | « test/invoker_test.dart ('k') | test/vm_listener_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698