OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 unittestTest; | 5 library unittest.expect_async_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:isolate'; | |
9 | 8 |
10 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
11 | 10 |
12 part 'utils.dart'; | 11 import 'package:metatest/metatest.dart'; |
13 | 12 |
14 var testFunction = (TestConfiguration testConfig) { | 13 void main() => initTests(_test); |
15 test('expectAsync zero params', () { | |
16 _defer(expectAsync(() { | |
17 ++testConfig.count; | |
18 })); | |
19 }); | |
20 | 14 |
21 test('expectAsync 1 param', () { | 15 void _test(message) { |
22 var func = expectAsync((arg) { | 16 initMetatest(message); |
23 expect(arg, 0); | |
24 ++testConfig.count; | |
25 }); | |
26 _defer(() => func(0)); | |
27 }); | |
28 | 17 |
29 test('expectAsync 2 param', () { | 18 var count = 0; |
30 var func = expectAsync((arg0, arg1) { | |
31 expect(arg0, 0); | |
32 expect(arg1, 1); | |
33 ++testConfig.count; | |
34 }); | |
35 _defer(() => func(0, 1)); | |
36 }); | |
37 | 19 |
38 test('single arg to Future.catchError', () { | 20 expectTestResults('expect async test', () { |
39 var func = expectAsync((error) { | 21 test('expectAsync zero params', () { |
40 expect(error, isStateError); | 22 defer(expectAsync(() { |
41 ++testConfig.count; | 23 ++count; |
| 24 })); |
42 }); | 25 }); |
43 | 26 |
44 new Future(() { | 27 test('expectAsync 1 param', () { |
45 throw new StateError('test'); | 28 var func = expectAsync((arg) { |
46 }).catchError(func); | 29 expect(arg, 0); |
47 }); | 30 ++count; |
48 | 31 }); |
49 test('2 args to Future.catchError', () { | 32 defer(() => func(0)); |
50 var func = expectAsync((error, stack) { | |
51 expect(error, isStateError); | |
52 expect(stack is StackTrace, isTrue); | |
53 ++testConfig.count; | |
54 }); | 33 }); |
55 | 34 |
56 new Future(() { | 35 test('expectAsync 2 param', () { |
57 throw new StateError('test'); | 36 var func = expectAsync((arg0, arg1) { |
58 }).catchError(func); | 37 expect(arg0, 0); |
59 }); | 38 expect(arg1, 1); |
60 | 39 ++count; |
61 test('zero of two optional positional args', () { | 40 }); |
62 var func = expectAsync(([arg0 = true, arg1 = true]) { | 41 defer(() => func(0, 1)); |
63 expect(arg0, isTrue); | |
64 expect(arg1, isTrue); | |
65 ++testConfig.count; | |
66 }); | 42 }); |
67 | 43 |
68 _defer(() => func()); | 44 test('single arg to Future.catchError', () { |
69 }); | 45 var func = expectAsync((error) { |
| 46 expect(error, isStateError); |
| 47 ++count; |
| 48 }); |
70 | 49 |
71 test('one of two optional positional args', () { | 50 new Future(() { |
72 var func = expectAsync(([arg0 = true, arg1 = true]) { | 51 throw new StateError('test'); |
73 expect(arg0, isFalse); | 52 }).catchError(func); |
74 expect(arg1, isTrue); | |
75 ++testConfig.count; | |
76 }); | 53 }); |
77 | 54 |
78 _defer(() => func(false)); | 55 test('2 args to Future.catchError', () { |
79 }); | 56 var func = expectAsync((error, stack) { |
| 57 expect(error, isStateError); |
| 58 expect(stack is StackTrace, isTrue); |
| 59 ++count; |
| 60 }); |
80 | 61 |
81 test('two of two optional positional args', () { | 62 new Future(() { |
82 var func = expectAsync(([arg0 = true, arg1 = true]) { | 63 throw new StateError('test'); |
83 expect(arg0, isFalse); | 64 }).catchError(func); |
84 expect(arg1, isNull); | |
85 ++testConfig.count; | |
86 }); | 65 }); |
87 | 66 |
88 _defer(() => func(false, null)); | 67 test('zero of two optional positional args', () { |
89 }); | 68 var func = expectAsync(([arg0 = true, arg1 = true]) { |
90 }; | 69 expect(arg0, isTrue); |
| 70 expect(arg1, isTrue); |
| 71 ++count; |
| 72 }); |
91 | 73 |
92 final expected = '8:0:0:8:8:::null:expectAsync zero params:' | 74 defer(() => func()); |
93 ':expectAsync 1 param::expectAsync 2 param:' | 75 }); |
94 ':single arg to Future.catchError::2 args to Future.catchError:' | 76 |
95 ':zero of two optional positional args:' | 77 test('one of two optional positional args', () { |
96 ':one of two optional positional args:' | 78 var func = expectAsync(([arg0 = true, arg1 = true]) { |
97 ':two of two optional positional args:'; | 79 expect(arg0, isFalse); |
| 80 expect(arg1, isTrue); |
| 81 ++count; |
| 82 }); |
| 83 |
| 84 defer(() => func(false)); |
| 85 }); |
| 86 |
| 87 test('two of two optional positional args', () { |
| 88 var func = expectAsync(([arg0 = true, arg1 = true]) { |
| 89 expect(arg0, isFalse); |
| 90 expect(arg1, isNull); |
| 91 ++count; |
| 92 }); |
| 93 |
| 94 defer(() => func(false, null)); |
| 95 }); |
| 96 |
| 97 test('verify count', () { |
| 98 expect(count, 8); |
| 99 }); |
| 100 }, new List.filled(9, {'result': 'pass' })); |
| 101 } |
OLD | NEW |