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

Side by Side Diff: test/utils.dart

Issue 920703006: Add a Loader class for loading tests from files. (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 unified diff | Download patch
« no previous file with comments | « test/loader_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library unittest.test.utils; 5 library unittest.test.utils;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:io';
10
11 import 'package:path/path.dart' as p;
12 import 'package:stack_trace/stack_trace.dart';
9 13
10 import 'package:unittest/src/live_test.dart'; 14 import 'package:unittest/src/live_test.dart';
11 import 'package:unittest/src/remote_exception.dart'; 15 import 'package:unittest/src/remote_exception.dart';
12 import 'package:unittest/src/state.dart'; 16 import 'package:unittest/src/state.dart';
13 import 'package:unittest/unittest.dart'; 17 import 'package:unittest/unittest.dart';
14 18
15 // The last state change detected via [expectStates]. 19 // The last state change detected via [expectStates].
16 State lastState; 20 State lastState;
17 21
22 final String packageDir = _computePackageDir();
23
24 String _computePackageDir() {
25 var trace = new Trace.current();
26 return p.dirname(p.dirname(p.fromUri(trace.frames.first.uri)));
27 }
28
18 /// Asserts that exactly [states] will be emitted via [liveTest.onStateChange]. 29 /// Asserts that exactly [states] will be emitted via [liveTest.onStateChange].
19 /// 30 ///
20 /// The most recent emitted state is stored in [_lastState]. 31 /// The most recent emitted state is stored in [_lastState].
21 void expectStates(LiveTest liveTest, Iterable<State> statesIter) { 32 void expectStates(LiveTest liveTest, Iterable<State> statesIter) {
22 var states = new Queue.from(statesIter); 33 var states = new Queue.from(statesIter);
23 liveTest.onStateChange.listen(expectAsync((state) { 34 liveTest.onStateChange.listen(expectAsync((state) {
24 lastState = state; 35 lastState = state;
25 expect(state, equals(states.removeFirst())); 36 expect(state, equals(states.removeFirst()));
26 }, count: states.length, max: states.length)); 37 }, count: states.length, max: states.length));
27 } 38 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 /// Returns a matcher that matches a [TestFailure] with the given [message]. 75 /// Returns a matcher that matches a [TestFailure] with the given [message].
65 Matcher isTestFailure(String message) => predicate( 76 Matcher isTestFailure(String message) => predicate(
66 (error) => error is TestFailure && error.message == message, 77 (error) => error is TestFailure && error.message == message,
67 'is a TestFailure with message "$message"'); 78 'is a TestFailure with message "$message"');
68 79
69 /// Returns a matcher that matches a [RemoteException] with the given [message]. 80 /// Returns a matcher that matches a [RemoteException] with the given [message].
70 Matcher isRemoteException(String message) => predicate( 81 Matcher isRemoteException(String message) => predicate(
71 (error) => error is RemoteException && error.message == message, 82 (error) => error is RemoteException && error.message == message,
72 'is a RemoteException with message "$message"'); 83 'is a RemoteException with message "$message"');
73 84
85 /// Returns a matcher that matches a [FileSystemException] with the given
86 /// [message].
87 Matcher isFileSystemException(String message) => predicate(
88 (error) => error is FileSystemException && error.message == message,
89 'is a FileSystemException with message "$message"');
90
74 /// Returns a [Future] that completes after pumping the event queue [times] 91 /// Returns a [Future] that completes after pumping the event queue [times]
75 /// times. 92 /// times.
76 /// 93 ///
77 /// By default, this should pump the event queue enough times to allow any code 94 /// By default, this should pump the event queue enough times to allow any code
78 /// to run, as long as it's not waiting on some external event. 95 /// to run, as long as it's not waiting on some external event.
79 Future pumpEventQueue([int times=20]) { 96 Future pumpEventQueue([int times=20]) {
80 if (times == 0) return new Future.value(); 97 if (times == 0) return new Future.value();
81 // Use [new Future] future to allow microtask events to finish. The [new 98 // Use [new Future] future to allow microtask events to finish. The [new
82 // Future.value] constructor uses scheduleMicrotask itself and would therefore 99 // Future.value] constructor uses scheduleMicrotask itself and would therefore
83 // not wait for microtask callbacks that are scheduled after invoking this 100 // not wait for microtask callbacks that are scheduled after invoking this
84 // method. 101 // method.
85 return new Future(() => pumpEventQueue(times - 1)); 102 return new Future(() => pumpEventQueue(times - 1));
86 } 103 }
OLDNEW
« no previous file with comments | « test/loader_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698