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

Side by Side Diff: test/prints_matcher_test.dart

Issue 869053002: unittest: refactor ahead of matcher changes (Closed) Base URL: https://github.com/dart-lang/unittest.git@master
Patch Set: no longer requires matcher 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
OLDNEW
(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 matcher.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(
120 r'''Expected future to complete successfully, but it failed with Expec ted: 'Goodbye, world!\n'
nweiz 2015/01/26 22:44:10 Long lines.
kevmoo 2015/01/27 00:11:30 These are long string literals. To make it easy to
121 ''
122 Actual: 'Hello, world!\n'
123 ''
124 Which: is different.
125 Expected: Goodbye, w ...
126 Actual: Hello, wor ...
127 ^
128 Differ at offset 0
129 ''')
130 },
131 {
132 'result': 'fail',
133 'message': startsWith(
134 r'''Expected future to complete successfully, but it failed with Expec ted: contains 'Goodbye'
135 Actual: 'Hello, world!\n'
136 ''
137 ''')
138 },
139 {
140 'result': 'fail',
141 'message': startsWith(
142 r'''Expected future to complete successfully, but it failed with Expec ted: contains 'Goodbye'
143 Actual: ''
144 ''')
145 }
146 ]);
147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698