OLD | NEW |
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 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
7 import '../backend/invoker.dart'; | 7 import '../backend/invoker.dart'; |
8 import 'expect.dart'; | 8 import 'expect.dart'; |
9 | 9 |
10 /// An object used to detect unpassed arguments. | 10 /// An object used to detect unpassed arguments. |
11 const _PLACEHOLDER = const Object(); | 11 const _PLACEHOLDER = const Object(); |
12 | 12 |
13 // Functions used to check how many arguments a callback takes. | 13 // Functions used to check how many arguments a callback takes. |
14 typedef _Func0(); | 14 typedef T Func0<T>(); |
15 typedef _Func1(a); | 15 typedef T Func1<T, A>(A a); |
16 typedef _Func2(a, b); | 16 typedef T Func2<T, A, B>(A a, B b); |
17 typedef _Func3(a, b, c); | 17 typedef T Func3<T, A, B, C>(A a, B b, C c); |
18 typedef _Func4(a, b, c, d); | 18 typedef T Func4<T, A, B, C, D>(A a, B b, C c, D d); |
19 typedef _Func5(a, b, c, d, e); | 19 typedef T Func5<T, A, B, C, D, E>(A a, B b, C c, D d, E e); |
20 typedef _Func6(a, b, c, d, e, f); | 20 typedef T Func6<T, A, B, C, D, E, F>(A a, B b, C c, D d, E e, F f); |
21 | 21 |
22 typedef bool _IsDoneCallback(); | 22 typedef bool _IsDoneCallback(); |
23 | 23 |
24 /// A wrapper for a function that ensures that it's called the appropriate | 24 /// A wrapper for a function that ensures that it's called the appropriate |
25 /// number of times. | 25 /// number of times. |
26 /// | 26 /// |
27 /// The containing test won't be considered to have completed successfully until | 27 /// The containing test won't be considered to have completed successfully until |
28 /// this function has been called the appropriate number of times. | 28 /// this function has been called the appropriate number of times. |
29 /// | 29 /// |
30 /// The wrapper function is accessible via [func]. It supports up to six | 30 /// The wrapper function is accessible via [func]. It supports up to six |
31 /// optional and/or required positional arguments, but no named arguments. | 31 /// optional and/or required positional arguments, but no named arguments. |
32 class _ExpectedFunction { | 32 class _ExpectedFunction<T> { |
33 /// The wrapped callback. | 33 /// The wrapped callback. |
34 final Function _callback; | 34 final Function _callback; |
35 | 35 |
36 /// The minimum number of calls that are expected to be made to the function. | 36 /// The minimum number of calls that are expected to be made to the function. |
37 /// | 37 /// |
38 /// If fewer calls than this are made, the test will fail. | 38 /// If fewer calls than this are made, the test will fail. |
39 final int _minExpectedCalls; | 39 final int _minExpectedCalls; |
40 | 40 |
41 /// The maximum number of calls that are expected to be made to the function. | 41 /// The maximum number of calls that are expected to be made to the function. |
42 /// | 42 /// |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 start += prefix.length; | 122 start += prefix.length; |
123 var end = toString.indexOf("'", start); | 123 var end = toString.indexOf("'", start); |
124 if (end == -1) return ''; | 124 if (end == -1) return ''; |
125 return "${toString.substring(start, end)} "; | 125 return "${toString.substring(start, end)} "; |
126 } | 126 } |
127 | 127 |
128 /// Returns a function that has the same number of positional arguments as the | 128 /// Returns a function that has the same number of positional arguments as the |
129 /// wrapped function (up to a total of 6). | 129 /// wrapped function (up to a total of 6). |
130 Function get func { | 130 Function get func { |
131 if (_callback is _Func6) return _max6; | 131 if (_callback is Func6) return max6; |
132 if (_callback is _Func5) return _max5; | 132 if (_callback is Func5) return max5; |
133 if (_callback is _Func4) return _max4; | 133 if (_callback is Func4) return max4; |
134 if (_callback is _Func3) return _max3; | 134 if (_callback is Func3) return max3; |
135 if (_callback is _Func2) return _max2; | 135 if (_callback is Func2) return max2; |
136 if (_callback is _Func1) return _max1; | 136 if (_callback is Func1) return max1; |
137 if (_callback is _Func0) return _max0; | 137 if (_callback is Func0) return max0; |
138 | 138 |
139 _invoker.removeOutstandingCallback(); | 139 _invoker.removeOutstandingCallback(); |
140 throw new ArgumentError( | 140 throw new ArgumentError( |
141 'The wrapped function has more than 6 required arguments'); | 141 'The wrapped function has more than 6 required arguments'); |
142 } | 142 } |
143 | 143 |
144 // This indirection is critical. It ensures the returned function has an | 144 // This indirection is critical. It ensures the returned function has an |
145 // argument count of zero. | 145 // argument count of zero. |
146 _max0() => _max6(); | 146 T max0() => max6(); |
147 | 147 |
148 _max1([a0 = _PLACEHOLDER]) => _max6(a0); | 148 T max1([Object a0 = _PLACEHOLDER]) => max6(a0); |
149 | 149 |
150 _max2([a0 = _PLACEHOLDER, a1 = _PLACEHOLDER]) => _max6(a0, a1); | 150 T max2([Object a0 = _PLACEHOLDER, Object a1 = _PLACEHOLDER]) => max6(a0, a1); |
151 | 151 |
152 _max3([a0 = _PLACEHOLDER, a1 = _PLACEHOLDER, a2 = _PLACEHOLDER]) => | 152 T max3( |
153 _max6(a0, a1, a2); | 153 [Object a0 = _PLACEHOLDER, |
| 154 Object a1 = _PLACEHOLDER, |
| 155 Object a2 = _PLACEHOLDER]) => |
| 156 max6(a0, a1, a2); |
154 | 157 |
155 _max4([a0 = _PLACEHOLDER, a1 = _PLACEHOLDER, a2 = _PLACEHOLDER, | 158 T max4( |
156 a3 = _PLACEHOLDER]) => _max6(a0, a1, a2, a3); | 159 [Object a0 = _PLACEHOLDER, |
| 160 Object a1 = _PLACEHOLDER, |
| 161 Object a2 = _PLACEHOLDER, |
| 162 Object a3 = _PLACEHOLDER]) => |
| 163 max6(a0, a1, a2, a3); |
157 | 164 |
158 _max5([a0 = _PLACEHOLDER, a1 = _PLACEHOLDER, a2 = _PLACEHOLDER, | 165 T max5( |
159 a3 = _PLACEHOLDER, a4 = _PLACEHOLDER]) => _max6(a0, a1, a2, a3, a4); | 166 [Object a0 = _PLACEHOLDER, |
| 167 Object a1 = _PLACEHOLDER, |
| 168 Object a2 = _PLACEHOLDER, |
| 169 Object a3 = _PLACEHOLDER, |
| 170 Object a4 = _PLACEHOLDER]) => |
| 171 max6(a0, a1, a2, a3, a4); |
160 | 172 |
161 _max6([a0 = _PLACEHOLDER, a1 = _PLACEHOLDER, a2 = _PLACEHOLDER, | 173 T max6( |
162 a3 = _PLACEHOLDER, a4 = _PLACEHOLDER, a5 = _PLACEHOLDER]) => | 174 [Object a0 = _PLACEHOLDER, |
| 175 Object a1 = _PLACEHOLDER, |
| 176 Object a2 = _PLACEHOLDER, |
| 177 Object a3 = _PLACEHOLDER, |
| 178 Object a4 = _PLACEHOLDER, |
| 179 Object a5 = _PLACEHOLDER]) => |
163 _run([a0, a1, a2, a3, a4, a5].where((a) => a != _PLACEHOLDER)); | 180 _run([a0, a1, a2, a3, a4, a5].where((a) => a != _PLACEHOLDER)); |
164 | 181 |
165 /// Runs the wrapped function with [args] and returns its return value. | 182 /// Runs the wrapped function with [args] and returns its return value. |
166 _run(Iterable args) { | 183 T _run(Iterable args) { |
167 // Note that in the old test, this returned `null` if it encountered an | 184 // Note that in the old test, this returned `null` if it encountered an |
168 // error, where now it just re-throws that error because Zone machinery will | 185 // error, where now it just re-throws that error because Zone machinery will |
169 // pass it to the invoker anyway. | 186 // pass it to the invoker anyway. |
170 try { | 187 try { |
171 _actualCalls++; | 188 _actualCalls++; |
172 if (_invoker.liveTest.state.shouldBeDone) { | 189 if (_invoker.liveTest.state.shouldBeDone) { |
173 throw 'Callback ${_id}called ($_actualCalls) after test case ' | 190 throw 'Callback ${_id}called ($_actualCalls) after test case ' |
174 '${_invoker.liveTest.test.name} had already completed.$_reason'; | 191 '${_invoker.liveTest.test.name} had already completed.$_reason'; |
175 } else if (_maxExpectedCalls >= 0 && _actualCalls > _maxExpectedCalls) { | 192 } else if (_maxExpectedCalls >= 0 && _actualCalls > _maxExpectedCalls) { |
176 throw new TestFailure('Callback ${_id}called more times than expected ' | 193 throw new TestFailure('Callback ${_id}called more times than expected ' |
177 '($_maxExpectedCalls).$_reason'); | 194 '($_maxExpectedCalls).$_reason'); |
178 } | 195 } |
179 | 196 |
180 return Function.apply(_callback, args.toList()); | 197 return Function.apply(_callback, args.toList()) as T; |
181 } catch (error, stackTrace) { | 198 } catch (error, stackTrace) { |
182 _zone.handleUncaughtError(error, stackTrace); | 199 _zone.handleUncaughtError(error, stackTrace); |
183 return null; | 200 return null; |
184 } finally { | 201 } finally { |
185 _afterRun(); | 202 _afterRun(); |
186 } | 203 } |
187 } | 204 } |
188 | 205 |
189 /// After each time the function is run, check to see if it's complete. | 206 /// After each time the function is run, check to see if it's complete. |
190 void _afterRun() { | 207 void _afterRun() { |
191 if (_complete) return; | 208 if (_complete) return; |
192 if (_minExpectedCalls > 0 && _actualCalls < _minExpectedCalls) return; | 209 if (_minExpectedCalls > 0 && _actualCalls < _minExpectedCalls) return; |
193 if (_isDone != null && !_isDone()) return; | 210 if (_isDone != null && !_isDone()) return; |
194 | 211 |
195 // Mark this callback as complete and remove it from the test case's | 212 // Mark this callback as complete and remove it from the test case's |
196 // oustanding callback count; if that hits zero the test is done. | 213 // oustanding callback count; if that hits zero the test is done. |
197 _complete = true; | 214 _complete = true; |
198 _invoker.removeOutstandingCallback(); | 215 _invoker.removeOutstandingCallback(); |
199 } | 216 } |
200 } | 217 } |
201 | 218 |
202 /// Indicate that [callback] is expected to be called [count] number of times | 219 /// This function is deprecated because it doesn't work well with strong mode. |
203 /// (by default 1). | 220 /// Use [expectAsync0], [expectAsync1], |
| 221 /// [expectAsync2], [expectAsync3], [expectAsync4], [expectAsync5], or |
| 222 /// [expectAsync6] instead. |
| 223 @Deprecated("Will be removed in 0.13.0") |
| 224 Function expectAsync(Function callback, |
| 225 {int count: 1, int max: 0, String id, String reason}) { |
| 226 if (Invoker.current == null) { |
| 227 throw new StateError("expectAsync() may only be called within a test."); |
| 228 } |
| 229 |
| 230 return new _ExpectedFunction(callback, count, max, id: id, reason: reason) |
| 231 .func; |
| 232 } |
| 233 |
| 234 /// Informs the framework that the given [callback] of arity 0 is expected to be |
| 235 /// called [count] number of times (by default 1). |
| 236 /// |
| 237 /// Returns a wrapped function that should be used as a replacement of the |
| 238 /// original callback. |
204 /// | 239 /// |
205 /// The test framework will wait for the callback to run the [count] times | 240 /// The test framework will wait for the callback to run the [count] times |
206 /// before it considers the current test to be complete. [callback] may take up | 241 /// before it considers the current test to be complete. |
207 /// to six optional or required positional arguments; named arguments are not | |
208 /// supported. | |
209 /// | 242 /// |
210 /// [max] can be used to specify an upper bound on the number of calls; if this | 243 /// [max] can be used to specify an upper bound on the number of calls; if this |
211 /// is exceeded the test will fail. If [max] is `0` (the default), the callback | 244 /// is exceeded the test will fail. If [max] is `0` (the default), the callback |
212 /// is expected to be called exactly [count] times. If [max] is `-1`, the | 245 /// is expected to be called exactly [count] times. If [max] is `-1`, the |
213 /// callback is allowed to be called any number of times greater than [count]. | 246 /// callback is allowed to be called any number of times greater than [count]. |
214 /// | 247 /// |
215 /// Both [id] and [reason] are optional and provide extra information about the | 248 /// Both [id] and [reason] are optional and provide extra information about the |
216 /// callback when debugging. [id] should be the name of the callback, while | 249 /// callback when debugging. [id] should be the name of the callback, while |
217 /// [reason] should be the reason the callback is expected to be called. | 250 /// [reason] should be the reason the callback is expected to be called. |
218 Function expectAsync(Function callback, | 251 /// |
219 {int count: 1, int max: 0, String id, String reason}) { | 252 /// This method takes callbacks with zero arguments. See also |
220 if (Invoker.current == null) { | 253 /// [expectAsync1], [expectAsync2], [expectAsync3], [expectAsync4], |
221 throw new StateError("expectAsync() may only be called within a test."); | 254 /// [expectAsync5], and [expectAsync6] for callbacks with different arity. |
222 } | 255 Func0<dynamic/*=T*/ > expectAsync0/*<T>*/(dynamic/*=T*/ callback(), |
223 | 256 {int count: 1, int max: 0, String id, String reason}) { |
224 return new _ExpectedFunction(callback, count, max, id: id, reason: reason) | 257 if (Invoker.current == null) { |
225 .func; | 258 throw new StateError("expectAsync0() may only be called within a test."); |
226 } | 259 } |
227 | 260 |
228 /// Indicate that [callback] is expected to be called until [isDone] returns | 261 return new _ExpectedFunction/*<T>*/(callback, count, max, |
229 /// true. | 262 id: id, reason: reason) |
230 /// | 263 .max0; |
231 /// [isDone] is called after each time the function is run. Only when it returns | 264 } |
232 /// true will the callback be considered complete. [callback] may take up to six | 265 |
233 /// optional or required positional arguments; named arguments are not | 266 /// Informs the framework that the given [callback] of arity 1 is expected to be |
234 /// supported. | 267 /// called [count] number of times (by default 1). |
235 /// | 268 /// |
236 /// Both [id] and [reason] are optional and provide extra information about the | 269 /// Returns a wrapped function that should be used as a replacement of the |
237 /// callback when debugging. [id] should be the name of the callback, while | 270 /// original callback. |
238 /// [reason] should be the reason the callback is expected to be called. | 271 /// |
| 272 /// The test framework will wait for the callback to run the [count] times |
| 273 /// before it considers the current test to be complete. |
| 274 /// |
| 275 /// [max] can be used to specify an upper bound on the number of calls; if this |
| 276 /// is exceeded the test will fail. If [max] is `0` (the default), the callback |
| 277 /// is expected to be called exactly [count] times. If [max] is `-1`, the |
| 278 /// callback is allowed to be called any number of times greater than [count]. |
| 279 /// |
| 280 /// Both [id] and [reason] are optional and provide extra information about the |
| 281 /// callback when debugging. [id] should be the name of the callback, while |
| 282 /// [reason] should be the reason the callback is expected to be called. |
| 283 /// |
| 284 /// This method takes callbacks with one argument. See also |
| 285 /// [expectAsync0], [expectAsync2], [expectAsync3], [expectAsync4], |
| 286 /// [expectAsync5], and [expectAsync6] for callbacks with different arity. |
| 287 Func1<dynamic/*=T*/, dynamic/*=A*/ > expectAsync1/*<T, A>*/( |
| 288 dynamic/*=T*/ callback(dynamic/*=A*/ a), |
| 289 {int count: 1, |
| 290 int max: 0, |
| 291 String id, |
| 292 String reason}) { |
| 293 if (Invoker.current == null) { |
| 294 throw new StateError("expectAsync1() may only be called within a test."); |
| 295 } |
| 296 |
| 297 return new _ExpectedFunction/*<T>*/(callback, count, max, |
| 298 id: id, reason: reason) |
| 299 .max1; |
| 300 } |
| 301 |
| 302 /// Informs the framework that the given [callback] of arity 2 is expected to be |
| 303 /// called [count] number of times (by default 1). |
| 304 /// |
| 305 /// Returns a wrapped function that should be used as a replacement of the |
| 306 /// original callback. |
| 307 /// |
| 308 /// The test framework will wait for the callback to run the [count] times |
| 309 /// before it considers the current test to be complete. |
| 310 /// |
| 311 /// [max] can be used to specify an upper bound on the number of calls; if this |
| 312 /// is exceeded the test will fail. If [max] is `0` (the default), the callback |
| 313 /// is expected to be called exactly [count] times. If [max] is `-1`, the |
| 314 /// callback is allowed to be called any number of times greater than [count]. |
| 315 /// |
| 316 /// Both [id] and [reason] are optional and provide extra information about the |
| 317 /// callback when debugging. [id] should be the name of the callback, while |
| 318 /// [reason] should be the reason the callback is expected to be called. |
| 319 /// |
| 320 /// This method takes callbacks with two arguments. See also |
| 321 /// [expectAsync0], [expectAsync1], [expectAsync3], [expectAsync4], |
| 322 /// [expectAsync5], and [expectAsync6] for callbacks with different arity. |
| 323 Func2<dynamic/*=T*/, dynamic/*=A*/, dynamic/*=B*/ > expectAsync2/*<T, A, B>*/( |
| 324 dynamic/*=T*/ callback(dynamic/*=A*/ a, dynamic/*=B*/ b), |
| 325 {int count: 1, |
| 326 int max: 0, |
| 327 String id, |
| 328 String reason}) { |
| 329 if (Invoker.current == null) { |
| 330 throw new StateError("expectAsync2() may only be called within a test."); |
| 331 } |
| 332 |
| 333 return new _ExpectedFunction/*<T>*/(callback, count, max, |
| 334 id: id, reason: reason) |
| 335 .max2; |
| 336 } |
| 337 |
| 338 /// Informs the framework that the given [callback] of arity 3 is expected to be |
| 339 /// called [count] number of times (by default 1). |
| 340 /// |
| 341 /// Returns a wrapped function that should be used as a replacement of the |
| 342 /// original callback. |
| 343 /// |
| 344 /// The test framework will wait for the callback to run the [count] times |
| 345 /// before it considers the current test to be complete. |
| 346 /// |
| 347 /// [max] can be used to specify an upper bound on the number of calls; if this |
| 348 /// is exceeded the test will fail. If [max] is `0` (the default), the callback |
| 349 /// is expected to be called exactly [count] times. If [max] is `-1`, the |
| 350 /// callback is allowed to be called any number of times greater than [count]. |
| 351 /// |
| 352 /// Both [id] and [reason] are optional and provide extra information about the |
| 353 /// callback when debugging. [id] should be the name of the callback, while |
| 354 /// [reason] should be the reason the callback is expected to be called. |
| 355 /// |
| 356 /// This method takes callbacks with three arguments. See also |
| 357 /// [expectAsync0], [expectAsync1], [expectAsync2], [expectAsync4], |
| 358 /// [expectAsync5], and [expectAsync6] for callbacks with different arity. |
| 359 Func3<dynamic/*=T*/, dynamic/*=A*/, dynamic/*=B*/, dynamic/*=C*/ > |
| 360 expectAsync3/*<T, A, B, C>*/( |
| 361 dynamic/*=T*/ callback( |
| 362 dynamic/*=A*/ a, dynamic/*=B*/ b, dynamic/*=C*/ c), |
| 363 {int count: 1, |
| 364 int max: 0, |
| 365 String id, |
| 366 String reason}) { |
| 367 if (Invoker.current == null) { |
| 368 throw new StateError("expectAsync3() may only be called within a test."); |
| 369 } |
| 370 |
| 371 return new _ExpectedFunction/*<T>*/(callback, count, max, |
| 372 id: id, reason: reason) |
| 373 .max3; |
| 374 } |
| 375 |
| 376 /// Informs the framework that the given [callback] of arity 4 is expected to be |
| 377 /// called [count] number of times (by default 1). |
| 378 /// |
| 379 /// Returns a wrapped function that should be used as a replacement of the |
| 380 /// original callback. |
| 381 /// |
| 382 /// The test framework will wait for the callback to run the [count] times |
| 383 /// before it considers the current test to be complete. |
| 384 /// |
| 385 /// [max] can be used to specify an upper bound on the number of calls; if this |
| 386 /// is exceeded the test will fail. If [max] is `0` (the default), the callback |
| 387 /// is expected to be called exactly [count] times. If [max] is `-1`, the |
| 388 /// callback is allowed to be called any number of times greater than [count]. |
| 389 /// |
| 390 /// Both [id] and [reason] are optional and provide extra information about the |
| 391 /// callback when debugging. [id] should be the name of the callback, while |
| 392 /// [reason] should be the reason the callback is expected to be called. |
| 393 /// |
| 394 /// This method takes callbacks with four arguments. See also |
| 395 /// [expectAsync0], [expectAsync1], [expectAsync2], [expectAsync3], |
| 396 /// [expectAsync5], and [expectAsync6] for callbacks with different arity. |
| 397 Func4<dynamic/*=T*/, dynamic/*=A*/, dynamic/*=B*/, dynamic/*=C*/, |
| 398 dynamic/*=D*/ > |
| 399 expectAsync4/*<T, A, B, C, D>*/( |
| 400 dynamic/*=T*/ callback( |
| 401 dynamic/*=A*/ a, dynamic/*=B*/ b, dynamic/*=C*/ c, dynamic/*=D*/ d), |
| 402 {int count: 1, |
| 403 int max: 0, |
| 404 String id, |
| 405 String reason}) { |
| 406 if (Invoker.current == null) { |
| 407 throw new StateError("expectAsync4() may only be called within a test."); |
| 408 } |
| 409 |
| 410 return new _ExpectedFunction/*<T>*/(callback, count, max, |
| 411 id: id, reason: reason) |
| 412 .max4; |
| 413 } |
| 414 |
| 415 /// Informs the framework that the given [callback] of arity 5 is expected to be |
| 416 /// called [count] number of times (by default 1). |
| 417 /// |
| 418 /// Returns a wrapped function that should be used as a replacement of the |
| 419 /// original callback. |
| 420 /// |
| 421 /// The test framework will wait for the callback to run the [count] times |
| 422 /// before it considers the current test to be complete. |
| 423 /// |
| 424 /// [max] can be used to specify an upper bound on the number of calls; if this |
| 425 /// is exceeded the test will fail. If [max] is `0` (the default), the callback |
| 426 /// is expected to be called exactly [count] times. If [max] is `-1`, the |
| 427 /// callback is allowed to be called any number of times greater than [count]. |
| 428 /// |
| 429 /// Both [id] and [reason] are optional and provide extra information about the |
| 430 /// callback when debugging. [id] should be the name of the callback, while |
| 431 /// [reason] should be the reason the callback is expected to be called. |
| 432 /// |
| 433 /// This method takes callbacks with five arguments. See also |
| 434 /// [expectAsync0], [expectAsync1], [expectAsync2], [expectAsync3], |
| 435 /// [expectAsync4], and [expectAsync6] for callbacks with different arity. |
| 436 Func5<dynamic/*=T*/, dynamic/*=A*/, dynamic/*=B*/, dynamic/*=C*/, |
| 437 dynamic/*=D*/, dynamic/*=E*/ > |
| 438 expectAsync5/*<T, A, B, C, D, E>*/( |
| 439 dynamic/*=T*/ callback(dynamic/*=A*/ a, dynamic/*=B*/ b, |
| 440 dynamic/*=C*/ c, dynamic/*=D*/ d, dynamic/*=E*/ e), |
| 441 {int count: 1, |
| 442 int max: 0, |
| 443 String id, |
| 444 String reason}) { |
| 445 if (Invoker.current == null) { |
| 446 throw new StateError("expectAsync5() may only be called within a test."); |
| 447 } |
| 448 |
| 449 return new _ExpectedFunction/*<T>*/(callback, count, max, |
| 450 id: id, reason: reason) |
| 451 .max5; |
| 452 } |
| 453 |
| 454 /// Informs the framework that the given [callback] of arity 6 is expected to be |
| 455 /// called [count] number of times (by default 1). |
| 456 /// |
| 457 /// Returns a wrapped function that should be used as a replacement of the |
| 458 /// original callback. |
| 459 /// |
| 460 /// The test framework will wait for the callback to run the [count] times |
| 461 /// before it considers the current test to be complete. |
| 462 /// |
| 463 /// [max] can be used to specify an upper bound on the number of calls; if this |
| 464 /// is exceeded the test will fail. If [max] is `0` (the default), the callback |
| 465 /// is expected to be called exactly [count] times. If [max] is `-1`, the |
| 466 /// callback is allowed to be called any number of times greater than [count]. |
| 467 /// |
| 468 /// Both [id] and [reason] are optional and provide extra information about the |
| 469 /// callback when debugging. [id] should be the name of the callback, while |
| 470 /// [reason] should be the reason the callback is expected to be called. |
| 471 /// |
| 472 /// This method takes callbacks with six arguments. See also |
| 473 /// [expectAsync0], [expectAsync1], [expectAsync2], [expectAsync3], |
| 474 /// [expectAsync4], and [expectAsync5] for callbacks with different arity. |
| 475 Func6<dynamic/*=T*/, dynamic/*=A*/, dynamic/*=B*/, dynamic/*=C*/, |
| 476 dynamic/*=D*/, dynamic/*=E*/, dynamic/*=F*/ > |
| 477 expectAsync6/*<T, A, B, C, D, E, F>*/( |
| 478 dynamic/*=T*/ callback(dynamic/*=A*/ a, dynamic/*=B*/ b, |
| 479 dynamic/*=C*/ c, dynamic/*=D*/ d, dynamic/*=E*/ e, dynamic/*=F*/ f), |
| 480 {int count: 1, |
| 481 int max: 0, |
| 482 String id, |
| 483 String reason}) { |
| 484 if (Invoker.current == null) { |
| 485 throw new StateError("expectAsync6() may only be called within a test."); |
| 486 } |
| 487 |
| 488 return new _ExpectedFunction/*<T>*/(callback, count, max, |
| 489 id: id, reason: reason) |
| 490 .max6; |
| 491 } |
| 492 |
| 493 /// This function is deprecated because it doesn't work well with strong mode. |
| 494 /// Use [expectAsyncUntil0], [expectAsyncUntil1], |
| 495 /// [expectAsyncUntil2], [expectAsyncUntil3], [expectAsyncUntil4], |
| 496 /// [expectAsyncUntil5], or [expectAsyncUntil6] instead. |
| 497 @Deprecated("Will be removed in 0.13.0") |
239 Function expectAsyncUntil(Function callback, bool isDone(), | 498 Function expectAsyncUntil(Function callback, bool isDone(), |
240 {String id, String reason}) { | 499 {String id, String reason}) { |
241 if (Invoker.current == null) { | 500 if (Invoker.current == null) { |
242 throw new StateError( | 501 throw new StateError( |
243 "expectAsyncUntil() may only be called within a test."); | 502 "expectAsyncUntil() may only be called within a test."); |
244 } | 503 } |
245 | 504 |
246 return new _ExpectedFunction(callback, 0, -1, | 505 return new _ExpectedFunction(callback, 0, -1, |
247 id: id, reason: reason, isDone: isDone).func; | 506 id: id, reason: reason, isDone: isDone) |
248 } | 507 .func; |
| 508 } |
| 509 |
| 510 /// Informs the framework that the given [callback] of arity 0 is expected to be |
| 511 /// called until [isDone] returns true. |
| 512 /// |
| 513 /// Returns a wrapped function that should be used as a replacement of the |
| 514 /// original callback. |
| 515 /// |
| 516 /// [isDone] is called after each time the function is run. Only when it returns |
| 517 /// true will the callback be considered complete. |
| 518 /// |
| 519 /// Both [id] and [reason] are optional and provide extra information about the |
| 520 /// callback when debugging. [id] should be the name of the callback, while |
| 521 /// [reason] should be the reason the callback is expected to be called. |
| 522 /// |
| 523 /// This method takes callbacks with zero arguments. See also |
| 524 /// [expectAsyncUntil1], [expectAsyncUntil2], [expectAsyncUntil3], |
| 525 /// [expectAsyncUntil4], [expectAsyncUntil5], and [expectAsyncUntil6] for |
| 526 /// callbacks with different arity. |
| 527 Func0<dynamic/*=T*/ > expectAsyncUntil0/*<T>*/( |
| 528 dynamic/*=T*/ callback(), bool isDone(), |
| 529 {String id, String reason}) { |
| 530 if (Invoker.current == null) { |
| 531 throw new StateError( |
| 532 "expectAsyncUntil0() may only be called within a test."); |
| 533 } |
| 534 |
| 535 return new _ExpectedFunction/*<T>*/(callback, 0, -1, |
| 536 id: id, reason: reason, isDone: isDone) |
| 537 .max0; |
| 538 } |
| 539 |
| 540 /// Informs the framework that the given [callback] of arity 1 is expected to be |
| 541 /// called until [isDone] returns true. |
| 542 /// |
| 543 /// Returns a wrapped function that should be used as a replacement of the |
| 544 /// original callback. |
| 545 /// |
| 546 /// [isDone] is called after each time the function is run. Only when it returns |
| 547 /// true will the callback be considered complete. |
| 548 /// |
| 549 /// Both [id] and [reason] are optional and provide extra information about the |
| 550 /// callback when debugging. [id] should be the name of the callback, while |
| 551 /// [reason] should be the reason the callback is expected to be called. |
| 552 /// |
| 553 /// This method takes callbacks with one argument. See also |
| 554 /// [expectAsyncUntil0], [expectAsyncUntil2], [expectAsyncUntil3], |
| 555 /// [expectAsyncUntil4], [expectAsyncUntil5], and [expectAsyncUntil6] for |
| 556 /// callbacks with different arity. |
| 557 Func1<dynamic/*=T*/, dynamic/*=A*/ > expectAsyncUntil1/*<T, A>*/( |
| 558 dynamic/*=T*/ callback(dynamic/*=A*/ a), bool isDone(), |
| 559 {String id, String reason}) { |
| 560 if (Invoker.current == null) { |
| 561 throw new StateError( |
| 562 "expectAsyncUntil1() may only be called within a test."); |
| 563 } |
| 564 |
| 565 return new _ExpectedFunction/*<T>*/(callback, 0, -1, |
| 566 id: id, reason: reason, isDone: isDone) |
| 567 .max1; |
| 568 } |
| 569 |
| 570 /// Informs the framework that the given [callback] of arity 2 is expected to be |
| 571 /// called until [isDone] returns true. |
| 572 /// |
| 573 /// Returns a wrapped function that should be used as a replacement of the |
| 574 /// original callback. |
| 575 /// |
| 576 /// [isDone] is called after each time the function is run. Only when it returns |
| 577 /// true will the callback be considered complete. |
| 578 /// |
| 579 /// Both [id] and [reason] are optional and provide extra information about the |
| 580 /// callback when debugging. [id] should be the name of the callback, while |
| 581 /// [reason] should be the reason the callback is expected to be called. |
| 582 /// |
| 583 /// This method takes callbacks with two arguments. See also |
| 584 /// [expectAsyncUntil0], [expectAsyncUntil1], [expectAsyncUntil3], |
| 585 /// [expectAsyncUntil4], [expectAsyncUntil5], and [expectAsyncUntil6] for |
| 586 /// callbacks with different arity. |
| 587 Func2<dynamic/*=T*/, dynamic/*=A*/, dynamic/*=B*/ > |
| 588 expectAsyncUntil2/*<T, A, B>*/( |
| 589 dynamic/*=T*/ callback(dynamic/*=A*/ a, dynamic/*=B*/ b), bool isDone(), |
| 590 {String id, String reason}) { |
| 591 if (Invoker.current == null) { |
| 592 throw new StateError( |
| 593 "expectAsyncUntil2() may only be called within a test."); |
| 594 } |
| 595 |
| 596 return new _ExpectedFunction/*<T>*/(callback, 0, -1, |
| 597 id: id, reason: reason, isDone: isDone) |
| 598 .max2; |
| 599 } |
| 600 |
| 601 /// Informs the framework that the given [callback] of arity 3 is expected to be |
| 602 /// called until [isDone] returns true. |
| 603 /// |
| 604 /// Returns a wrapped function that should be used as a replacement of the |
| 605 /// original callback. |
| 606 /// |
| 607 /// [isDone] is called after each time the function is run. Only when it returns |
| 608 /// true will the callback be considered complete. |
| 609 /// |
| 610 /// Both [id] and [reason] are optional and provide extra information about the |
| 611 /// callback when debugging. [id] should be the name of the callback, while |
| 612 /// [reason] should be the reason the callback is expected to be called. |
| 613 /// |
| 614 /// This method takes callbacks with three arguments. See also |
| 615 /// [expectAsyncUntil0], [expectAsyncUntil1], [expectAsyncUntil2], |
| 616 /// [expectAsyncUntil4], [expectAsyncUntil5], and [expectAsyncUntil6] for |
| 617 /// callbacks with different arity. |
| 618 Func3<dynamic/*=T*/, dynamic/*=A*/, dynamic/*=B*/, dynamic/*=C*/ > |
| 619 expectAsyncUntil3/*<T, A, B, C>*/( |
| 620 dynamic/*=T*/ callback( |
| 621 dynamic/*=A*/ a, dynamic/*=B*/ b, dynamic/*=C*/ c), |
| 622 bool isDone(), |
| 623 {String id, |
| 624 String reason}) { |
| 625 if (Invoker.current == null) { |
| 626 throw new StateError( |
| 627 "expectAsyncUntil3() may only be called within a test."); |
| 628 } |
| 629 |
| 630 return new _ExpectedFunction/*<T>*/(callback, 0, -1, |
| 631 id: id, reason: reason, isDone: isDone) |
| 632 .max3; |
| 633 } |
| 634 |
| 635 /// Informs the framework that the given [callback] of arity 4 is expected to be |
| 636 /// called until [isDone] returns true. |
| 637 /// |
| 638 /// Returns a wrapped function that should be used as a replacement of the |
| 639 /// original callback. |
| 640 /// |
| 641 /// [isDone] is called after each time the function is run. Only when it returns |
| 642 /// true will the callback be considered complete. |
| 643 /// |
| 644 /// Both [id] and [reason] are optional and provide extra information about the |
| 645 /// callback when debugging. [id] should be the name of the callback, while |
| 646 /// [reason] should be the reason the callback is expected to be called. |
| 647 /// |
| 648 /// This method takes callbacks with four arguments. See also |
| 649 /// [expectAsyncUntil0], [expectAsyncUntil1], [expectAsyncUntil2], |
| 650 /// [expectAsyncUntil3], [expectAsyncUntil5], and [expectAsyncUntil6] for |
| 651 /// callbacks with different arity. |
| 652 Func4<dynamic/*=T*/, dynamic/*=A*/, dynamic/*=B*/, dynamic/*=C*/, |
| 653 dynamic/*=D*/ > |
| 654 expectAsyncUntil4/*<T, A, B, C, D>*/( |
| 655 dynamic/*=T*/ callback( |
| 656 dynamic/*=A*/ a, dynamic/*=B*/ b, dynamic/*=C*/ c, dynamic/*=D*/ d), |
| 657 bool isDone(), |
| 658 {String id, |
| 659 String reason}) { |
| 660 if (Invoker.current == null) { |
| 661 throw new StateError( |
| 662 "expectAsyncUntil4() may only be called within a test."); |
| 663 } |
| 664 |
| 665 return new _ExpectedFunction/*<T>*/(callback, 0, -1, |
| 666 id: id, reason: reason, isDone: isDone) |
| 667 .max4; |
| 668 } |
| 669 |
| 670 /// Informs the framework that the given [callback] of arity 5 is expected to be |
| 671 /// called until [isDone] returns true. |
| 672 /// |
| 673 /// Returns a wrapped function that should be used as a replacement of the |
| 674 /// original callback. |
| 675 /// |
| 676 /// [isDone] is called after each time the function is run. Only when it returns |
| 677 /// true will the callback be considered complete. |
| 678 /// |
| 679 /// Both [id] and [reason] are optional and provide extra information about the |
| 680 /// callback when debugging. [id] should be the name of the callback, while |
| 681 /// [reason] should be the reason the callback is expected to be called. |
| 682 /// |
| 683 /// This method takes callbacks with five arguments. See also |
| 684 /// [expectAsyncUntil0], [expectAsyncUntil1], [expectAsyncUntil2], |
| 685 /// [expectAsyncUntil3], [expectAsyncUntil4], and [expectAsyncUntil6] for |
| 686 /// callbacks with different arity. |
| 687 Func5<dynamic/*=T*/, dynamic/*=A*/, dynamic/*=B*/, dynamic/*=C*/, |
| 688 dynamic/*=D*/, dynamic/*=E*/ > |
| 689 expectAsyncUntil5/*<T, A, B, C, D, E>*/( |
| 690 dynamic/*=T*/ callback(dynamic/*=A*/ a, dynamic/*=B*/ b, |
| 691 dynamic/*=C*/ c, dynamic/*=D*/ d, dynamic/*=E*/ e), |
| 692 bool isDone(), |
| 693 {String id, |
| 694 String reason}) { |
| 695 if (Invoker.current == null) { |
| 696 throw new StateError( |
| 697 "expectAsyncUntil5() may only be called within a test."); |
| 698 } |
| 699 |
| 700 return new _ExpectedFunction/*<T>*/(callback, 0, -1, |
| 701 id: id, reason: reason, isDone: isDone) |
| 702 .max5; |
| 703 } |
| 704 |
| 705 /// Informs the framework that the given [callback] of arity 6 is expected to be |
| 706 /// called until [isDone] returns true. |
| 707 /// |
| 708 /// Returns a wrapped function that should be used as a replacement of the |
| 709 /// original callback. |
| 710 /// |
| 711 /// [isDone] is called after each time the function is run. Only when it returns |
| 712 /// true will the callback be considered complete. |
| 713 /// |
| 714 /// Both [id] and [reason] are optional and provide extra information about the |
| 715 /// callback when debugging. [id] should be the name of the callback, while |
| 716 /// [reason] should be the reason the callback is expected to be called. |
| 717 /// |
| 718 /// This method takes callbacks with six arguments. See also |
| 719 /// [expectAsyncUntil0], [expectAsyncUntil1], [expectAsyncUntil2], |
| 720 /// [expectAsyncUntil3], [expectAsyncUntil4], and [expectAsyncUntil5] for |
| 721 /// callbacks with different arity. |
| 722 Func6<dynamic/*=T*/, dynamic/*=A*/, dynamic/*=B*/, dynamic/*=C*/, |
| 723 dynamic/*=D*/, dynamic/*=E*/, dynamic/*=F*/ > |
| 724 expectAsyncUntil6/*<T, A, B, C, D, E, F>*/( |
| 725 dynamic/*=T*/ callback(dynamic/*=A*/ a, dynamic/*=B*/ b, |
| 726 dynamic/*=C*/ c, dynamic/*=D*/ d, dynamic/*=E*/ e, dynamic/*=F*/ f), |
| 727 bool isDone(), |
| 728 {String id, |
| 729 String reason}) { |
| 730 if (Invoker.current == null) { |
| 731 throw new StateError( |
| 732 "expectAsyncUntil() may only be called within a test."); |
| 733 } |
| 734 |
| 735 return new _ExpectedFunction/*<T>*/(callback, 0, -1, |
| 736 id: id, reason: reason, isDone: isDone) |
| 737 .max6; |
| 738 } |
OLD | NEW |