OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
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. | |
4 | |
5 library unittest.prints_matchers_test; | |
6 | |
7 import 'dart:async'; | |
8 | |
9 import 'package:metatest/metatest.dart'; | |
10 import 'package:unittest/unittest.dart'; | |
11 | |
12 /// The VM and dart2js have different toStrings for closures. | |
13 final closureToString = (() {}).toString(); | |
14 | |
15 void main() => initTests(_test); | |
16 | |
17 void _test(message) { | |
18 initMetatest(message); | |
19 | |
20 expectTestResults('synchronous', () { | |
21 test("passes with an expected print", () { | |
22 expect(() => print("Hello, world!"), prints("Hello, world!\n")); | |
23 }); | |
24 | |
25 test("combines multiple prints", () { | |
26 expect(() { | |
27 print("Hello"); | |
28 print("World!"); | |
29 }, prints("Hello\nWorld!\n")); | |
30 }); | |
31 | |
32 test("works with a Matcher", () { | |
33 expect(() => print("Hello, world!"), prints(contains("Hello"))); | |
34 }); | |
35 | |
36 test("describes a failure nicely", () { | |
37 expect(() => print("Hello, world!"), prints("Goodbye, world!\n")); | |
38 }); | |
39 | |
40 test("describes a failure with a non-descriptive Matcher nicely", () { | |
41 expect(() => print("Hello, world!"), prints(contains("Goodbye"))); | |
42 }); | |
43 | |
44 test("describes a failure with no text nicely", () { | |
45 expect(() {}, prints(contains("Goodbye"))); | |
46 }); | |
47 }, [ | |
48 {'result': 'pass'}, | |
49 {'result': 'pass'}, | |
50 {'result': 'pass'}, | |
51 { | |
52 'result': 'fail', | |
53 'message': r'''Expected: prints 'Goodbye, world!\n' | |
54 '' | |
55 Actual: <Closure: () => dynamic> | |
56 Which: printed 'Hello, world!\n' | |
57 '' | |
58 Which: is different. | |
59 Expected: Goodbye, w ... | |
60 Actual: Hello, wor ... | |
61 ^ | |
62 Differ at offset 0 | |
63 ''' | |
64 }, | |
65 { | |
66 'result': 'fail', | |
67 'message': r'''Expected: prints contains 'Goodbye' | |
68 Actual: <Closure: () => dynamic> | |
69 Which: printed 'Hello, world!\n' | |
70 '' | |
71 ''' | |
72 }, | |
73 { | |
74 'result': 'fail', | |
75 'message': r'''Expected: prints contains 'Goodbye' | |
76 Actual: <Closure: () => dynamic> | |
77 Which: printed nothing. | |
78 ''' | |
79 } | |
80 ]); | |
81 | |
82 expectTestResults('asynchronous', () { | |
83 test("passes with an expected print", () { | |
84 expect(() => new Future(() => print("Hello, world!")), | |
85 prints("Hello, world!\n")); | |
86 }); | |
87 | |
88 test("combines multiple prints", () { | |
89 expect(() => new Future(() { | |
90 print("Hello"); | |
91 print("World!"); | |
92 }), prints("Hello\nWorld!\n")); | |
93 }); | |
94 | |
95 test("works with a Matcher", () { | |
96 expect(() => new Future(() => print("Hello, world!")), | |
97 prints(contains("Hello"))); | |
98 }); | |
99 | |
100 test("describes a failure nicely", () { | |
101 expect(() => new Future(() => print("Hello, world!")), | |
102 prints("Goodbye, world!\n")); | |
103 }); | |
104 | |
105 test("describes a failure with a non-descriptive Matcher nicely", () { | |
106 expect(() => new Future(() => print("Hello, world!")), | |
107 prints(contains("Goodbye"))); | |
108 }); | |
109 | |
110 test("describes a failure with no text nicely", () { | |
111 expect(() => new Future.value(), prints(contains("Goodbye"))); | |
112 }); | |
113 }, [ | |
114 {'result': 'pass'}, | |
115 {'result': 'pass'}, | |
116 {'result': 'pass'}, | |
117 { | |
118 'result': 'fail', | |
119 'message': startsWith(r'''Expected future to complete successfully, but it
failed with Expected: 'Goodbye, world!\n' | |
120 '' | |
121 Actual: 'Hello, world!\n' | |
122 '' | |
123 Which: is different. | |
124 Expected: Goodbye, w ... | |
125 Actual: Hello, wor ... | |
126 ^ | |
127 Differ at offset 0 | |
128 ''') | |
129 }, | |
130 { | |
131 'result': 'fail', | |
132 'message': startsWith(r'''Expected future to complete successfully, but it
failed with Expected: contains 'Goodbye' | |
133 Actual: 'Hello, world!\n' | |
134 '' | |
135 ''') | |
136 }, | |
137 { | |
138 'result': 'fail', | |
139 'message': startsWith(r'''Expected future to complete successfully, but it
failed with Expected: contains 'Goodbye' | |
140 Actual: '' | |
141 ''') | |
142 } | |
143 ]); | |
144 } | |
OLD | NEW |