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

Side by Side Diff: test/runner/browser/runner_test.dart

Issue 1243293002: Convert a bunch of tests to use scheduled_test's infrastructure. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 5 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/runner/browser/phantom_js_test.dart ('k') | test/runner/browser/safari_test.dart » ('j') | 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 @TestOn("vm") 5 @TestOn("vm")
6 6
7 import 'dart:io'; 7 import 'package:scheduled_test/descriptor.dart' as d;
8 8 import 'package:scheduled_test/scheduled_stream.dart';
9 import 'package:path/path.dart' as p; 9 import 'package:scheduled_test/scheduled_test.dart';
10 import 'package:test/src/util/io.dart';
11 import 'package:test/test.dart';
12 10
13 import '../../io.dart'; 11 import '../../io.dart';
14 12
15 String _sandbox;
16
17 final _success = """ 13 final _success = """
18 import 'package:test/test.dart'; 14 import 'package:test/test.dart';
19 15
20 void main() { 16 void main() {
21 test("success", () {}); 17 test("success", () {});
22 } 18 }
23 """; 19 """;
24 20
25 final _failure = """ 21 final _failure = """
26 import 'package:test/test.dart'; 22 import 'package:test/test.dart';
27 23
28 void main() { 24 void main() {
29 test("failure", () => throw new TestFailure("oh no")); 25 test("failure", () => throw new TestFailure("oh no"));
30 } 26 }
31 """; 27 """;
32 28
33 void main() { 29 void main() {
34 setUp(() { 30 useSandbox();
35 _sandbox = createTempDir();
36 });
37
38 tearDown(() {
39 new Directory(_sandbox).deleteSync(recursive: true);
40 });
41 31
42 group("fails gracefully if", () { 32 group("fails gracefully if", () {
43 test("a test file fails to compile", () { 33 test("a test file fails to compile", () {
44 var testPath = p.join(_sandbox, "test.dart"); 34 d.file("test.dart", "invalid Dart file").create();
45 new File(testPath).writeAsStringSync("invalid Dart file"); 35 var test = runTest(["-p", "chrome", "test.dart"]);
46 var result = _runTest(["-p", "chrome", "test.dart"]);
47 36
48 var relativePath = p.relative(testPath, from: _sandbox); 37 test.stdout.expect(containsInOrder([
49 expect(result.stdout, allOf([ 38 "Expected a declaration, but got 'invalid'",
50 contains("Expected a declaration, but got 'invalid'"), 39 '-1: compiling test.dart',
51 contains('-1: compiling $relativePath'), 40 'Failed to load "test.dart": dart2js failed.'
52 contains('Failed to load "$relativePath": dart2js failed.')
53 ])); 41 ]));
54 expect(result.exitCode, equals(1)); 42 test.shouldExit(1);
55 }); 43 });
56 44
57 test("a test file throws", () { 45 test("a test file throws", () {
58 var testPath = p.join(_sandbox, "test.dart"); 46 d.file("test.dart", "void main() => throw 'oh no';").create();
59 new File(testPath).writeAsStringSync("void main() => throw 'oh no';");
60 47
61 var relativePath = p.relative(testPath, from: _sandbox); 48 var test = runTest(["-p", "chrome", "test.dart"]);
62 var result = _runTest(["-p", "chrome", "test.dart"]); 49 test.stdout.expect(containsInOrder([
63 expect(result.stdout, allOf([ 50 '-1: compiling test.dart',
64 contains('-1: compiling $relativePath'), 51 'Failed to load "test.dart": oh no'
65 contains('Failed to load "$relativePath": oh no')
66 ])); 52 ]));
67 expect(result.exitCode, equals(1)); 53 test.shouldExit(1);
68 }); 54 });
69 55
70 test("a test file doesn't have a main defined", () { 56 test("a test file doesn't have a main defined", () {
71 var testPath = p.join(_sandbox, "test.dart"); 57 d.file("test.dart", "void foo() {}").create();
72 new File(testPath).writeAsStringSync("void foo() {}");
73 58
74 var relativePath = p.relative(testPath, from: _sandbox); 59 var test = runTest(["-p", "chrome", "test.dart"]);
75 var result = _runTest(["-p", "chrome", "test.dart"]); 60 test.stdout.expect(containsInOrder([
76 expect(result.stdout, allOf([ 61 '-1: compiling test.dart',
77 contains('-1: compiling $relativePath'), 62 'Failed to load "test.dart": No top-level main() function defined.'
78 contains('Failed to load "$relativePath": No top-level main() function '
79 'defined.')
80 ])); 63 ]));
81 expect(result.exitCode, equals(1)); 64 test.shouldExit(1);
82 }); 65 });
83 66
84 test("a test file has a non-function main", () { 67 test("a test file has a non-function main", () {
85 var testPath = p.join(_sandbox, "test.dart"); 68 d.file("test.dart", "int main;").create();
86 new File(testPath).writeAsStringSync("int main;");
87 69
88 var relativePath = p.relative(testPath, from: _sandbox); 70 var test = runTest(["-p", "chrome", "test.dart"]);
89 var result = _runTest(["-p", "chrome", "test.dart"]); 71 test.stdout.expect(containsInOrder([
90 expect(result.stdout, allOf([ 72 '-1: compiling test.dart',
91 contains('-1: compiling $relativePath'), 73 'Failed to load "test.dart": Top-level main getter is not a function.'
92 contains('Failed to load "$relativePath": Top-level main getter is not '
93 'a function.\n')
94 ])); 74 ]));
95 expect(result.exitCode, equals(1)); 75 test.shouldExit(1);
96 }); 76 });
97 77
98 test("a test file has a main with arguments", () { 78 test("a test file has a main with arguments", () {
99 var testPath = p.join(_sandbox, "test.dart"); 79 d.file("test.dart", "void main(arg) {}").create();
100 new File(testPath).writeAsStringSync("void main(arg) {}");
101 80
102 var relativePath = p.relative(testPath, from: _sandbox); 81 var test = runTest(["-p", "chrome", "test.dart"]);
103 var result = _runTest(["-p", "chrome", "test.dart"]); 82 test.stdout.expect(containsInOrder([
104 expect(result.stdout, allOf([ 83 '-1: compiling test.dart',
105 contains('-1: compiling $relativePath'), 84 'Failed to load "test.dart": Top-level main() function takes arguments.'
106 contains('Failed to load "$relativePath": Top-level main() function '
107 'takes arguments.\n')
108 ])); 85 ]));
109 expect(result.exitCode, equals(1)); 86 test.shouldExit(1);
110 }); 87 });
111 88
112 test("a custom HTML file has no script tag", () { 89 test("a custom HTML file has no script tag", () {
113 var testPath = p.join(_sandbox, "test.dart"); 90 d.file("test.dart", "void main() {}").create();
114 new File(testPath).writeAsStringSync("void main(arg) {}");
115 91
116 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" 92 d.file("test.html", """
117 <html> 93 <html>
118 <head> 94 <head>
119 <link rel="x-dart-test" href="test.dart"> 95 <link rel="x-dart-test" href="test.dart">
120 </head> 96 </head>
121 </html> 97 </html>
122 """); 98 """).create();
123 99
124 var relativePath = p.relative(testPath, from: _sandbox); 100 var test = runTest(["-p", "content-shell", "test.dart"]);
125 var result = _runTest(["-p", "content-shell", "test.dart"]); 101 test.stdout.expect(containsInOrder([
126 expect(result.stdout, allOf([ 102 '-1: loading test.dart',
127 contains('-1: loading $relativePath'), 103 'Failed to load "test.dart": "test.html" must contain '
128 contains( 104 '<script src="packages/test/dart.js"></script>.'
129 'Failed to load "$relativePath": '
130 '"${p.withoutExtension(relativePath)}.html" must contain '
131 '<script src="packages/test/dart.js"></script>.\n')
132 ])); 105 ]));
133 expect(result.exitCode, equals(1)); 106 test.shouldExit(1);
134 }); 107 });
135 108
136 test("a custom HTML file has no link", () { 109 test("a custom HTML file has no link", () {
137 var testPath = p.join(_sandbox, "test.dart"); 110 d.file("test.dart", "void main() {}").create();
138 new File(testPath).writeAsStringSync("void main(arg) {}");
139 111
140 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" 112 d.file("test.html", """
141 <html> 113 <html>
142 <head> 114 <head>
143 <script src="packages/test/dart.js"></script> 115 <script src="packages/test/dart.js"></script>
144 </head> 116 </head>
145 </html> 117 </html>
146 """); 118 """).create();
147 119
148 var relativePath = p.relative(testPath, from: _sandbox); 120 var test = runTest(["-p", "content-shell", "test.dart"]);
149 var result = _runTest(["-p", "content-shell", "test.dart"]); 121 test.stdout.expect(containsInOrder([
150 expect(result.stdout, allOf([ 122 '-1: loading test.dart',
151 contains('-1: loading $relativePath'), 123 'Failed to load "test.dart": Expected exactly 1 '
152 contains( 124 '<link rel="x-dart-test"> in test.html, found 0.'
153 'Failed to load "$relativePath": '
154 'Expected exactly 1 <link rel="x-dart-test"> in test.html, '
155 'found 0.\n')
156 ])); 125 ]));
157 expect(result.exitCode, equals(1)); 126 test.shouldExit(1);
158 }); 127 });
159 128
160 test("a custom HTML file has too many links", () { 129 test("a custom HTML file has too many links", () {
161 var testPath = p.join(_sandbox, "test.dart"); 130 d.file("test.dart", "void main() {}").create();
162 new File(testPath).writeAsStringSync("void main(arg) {}");
163 131
164 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" 132 d.file("test.html", """
165 <html> 133 <html>
166 <head> 134 <head>
167 <link rel='x-dart-test' href='test.dart'> 135 <link rel='x-dart-test' href='test.dart'>
168 <link rel='x-dart-test' href='test.dart'> 136 <link rel='x-dart-test' href='test.dart'>
169 <script src="packages/test/dart.js"></script> 137 <script src="packages/test/dart.js"></script>
170 </head> 138 </head>
171 </html> 139 </html>
172 """); 140 """).create();
173 141
174 var relativePath = p.relative(testPath, from: _sandbox); 142 var test = runTest(["-p", "content-shell", "test.dart"]);
175 var result = _runTest(["-p", "content-shell", "test.dart"]); 143 test.stdout.expect(containsInOrder([
176 expect(result.stdout, allOf([ 144 '-1: loading test.dart',
177 contains('-1: loading $relativePath'), 145 'Failed to load "test.dart": Expected exactly 1 '
178 contains( 146 '<link rel="x-dart-test"> in test.html, found 2.'
179 'Failed to load "$relativePath": '
180 'Expected exactly 1 <link rel="x-dart-test"> in test.html, '
181 'found 2.\n')
182 ])); 147 ]));
183 expect(result.exitCode, equals(1)); 148 test.shouldExit(1);
184 }); 149 });
185 150
186 test("a custom HTML file has no href in the link", () { 151 test("a custom HTML file has no href in the link", () {
187 var testPath = p.join(_sandbox, "test.dart"); 152 d.file("test.dart", "void main() {}").create();
188 new File(testPath).writeAsStringSync("void main(arg) {}");
189 153
190 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" 154 d.file("test.html", """
191 <html> 155 <html>
192 <head> 156 <head>
193 <link rel='x-dart-test'> 157 <link rel='x-dart-test'>
194 <script src="packages/test/dart.js"></script> 158 <script src="packages/test/dart.js"></script>
195 </head> 159 </head>
196 </html> 160 </html>
197 """); 161 """).create();
198 162
199 var relativePath = p.relative(testPath, from: _sandbox); 163 var test = runTest(["-p", "content-shell", "test.dart"]);
200 var result = _runTest(["-p", "content-shell", "test.dart"]); 164 test.stdout.expect(containsInOrder([
201 expect(result.stdout, allOf([ 165 '-1: loading test.dart',
202 contains('-1: loading $relativePath'), 166 'Failed to load "test.dart": Expected <link rel="x-dart-test"> in '
203 contains( 167 'test.html to have an "href" attribute.'
204 'Failed to load "$relativePath": '
205 'Expected <link rel="x-dart-test"> in test.html to have an '
206 '"href" attribute.\n')
207 ])); 168 ]));
208 expect(result.exitCode, equals(1)); 169 test.shouldExit(1);
209 }); 170 });
210 171
211 test("a custom HTML file has an invalid test URL", () { 172 test("a custom HTML file has an invalid test URL", () {
212 var testPath = p.join(_sandbox, "test.dart"); 173 d.file("test.dart", "void main() {}").create();
213 new File(testPath).writeAsStringSync("void main(arg) {}");
214 174
215 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" 175 d.file("test.html", """
216 <html> 176 <html>
217 <head> 177 <head>
218 <link rel='x-dart-test' href='wrong.dart'> 178 <link rel='x-dart-test' href='wrong.dart'>
219 <script src="packages/test/dart.js"></script> 179 <script src="packages/test/dart.js"></script>
220 </head> 180 </head>
221 </html> 181 </html>
222 """); 182 """).create();
223 183
224 var relativePath = p.relative(testPath, from: _sandbox); 184 var test = runTest(["-p", "content-shell", "test.dart"]);
225 var result = _runTest(["-p", "content-shell", "test.dart"]); 185 test.stdout.expect(containsInOrder([
226 expect(result.stdout, allOf([ 186 '-1: loading test.dart',
227 contains('-1: loading $relativePath'), 187 'Failed to load "test.dart": Failed to load script at '
228 contains(
229 'Failed to load "$relativePath": '
230 'Failed to load script at ')
231 ])); 188 ]));
232 expect(result.exitCode, equals(1)); 189 test.shouldExit(1);
233 }); 190 });
234 191
235 // TODO(nweiz): test what happens when a test file is unreadable once issue 192 // TODO(nweiz): test what happens when a test file is unreadable once issue
236 // 15078 is fixed. 193 // 15078 is fixed.
237 }); 194 });
238 195
239 group("runs successful tests", () { 196 group("runs successful tests", () {
240 test("on Chrome", () { 197 test("on a JS and non-JS browser", () {
241 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); 198 d.file("test.dart", _success).create();
242 var result = _runTest(["-p", "chrome", "test.dart"]); 199 var test = runTest(["-p", "content-shell", "-p", "chrome", "test.dart"]);
243 expect(result.exitCode, equals(0));
244 });
245 200
246 test("on Safari", () { 201 test.stdout.fork().expect(consumeThrough(contains("[Chrome] compiling")));
247 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); 202 test.stdout.expect(never(contains("[Dartium Content Shell] compiling")));
248 var result = _runTest(["-p", "safari", "test.dart"]); 203 test.shouldExit(0);
249 expect(result.exitCode, equals(0));
250 }, testOn: "mac-os");
251
252 test("on content shell", () {
253 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
254 var result = _runTest(["-p", "content-shell", "test.dart"]);
255 expect(result.stdout, isNot(contains("Compiling")));
256 expect(result.exitCode, equals(0));
257 });
258
259 test("on a JS and non-JS browser", () {
260 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
261 var result = _runTest(
262 ["-p", "content-shell", "-p", "chrome", "test.dart"]);
263 expect(result.stdout, contains("[Chrome] compiling"));
264 expect(result.stdout,
265 isNot(contains("[Dartium Content Shell] compiling")));
266 expect(result.exitCode, equals(0));
267 }); 204 });
268 205
269 test("on a browser and the VM", () { 206 test("on a browser and the VM", () {
270 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); 207 d.file("test.dart", _success).create();
271 var result = _runTest(["-p", "content-shell", "-p", "vm", "test.dart"]); 208 var test = runTest(["-p", "content-shell", "-p", "vm", "test.dart"]);
272 expect(result.exitCode, equals(0)); 209
210 test.stdout.expect(consumeThrough(contains("+2: All tests passed!")));
211 test.shouldExit(0);
273 }); 212 });
274 213
275 // Regression test; this broke in 0.12.0-beta.9. 214 // Regression test; this broke in 0.12.0-beta.9.
276 test("on a file in a subdirectory", () { 215 test("on a file in a subdirectory", () {
277 new Directory(p.join(_sandbox, "dir")).createSync(); 216 d.dir("dir", [d.file("test.dart", _success)]).create();
278 new File(p.join(_sandbox, "dir", "test.dart")) 217
279 .writeAsStringSync(_success); 218 var test = runTest(["-p", "chrome", "dir/test.dart"]);
280 var result = _runTest(["-p", "chrome", "dir/test.dart"]); 219 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
281 expect(result.exitCode, equals(0)); 220 test.shouldExit(0);
282 }); 221 });
283 222
284 group("with a custom HTML file", () { 223 group("with a custom HTML file", () {
285 setUp(() { 224 setUp(() {
286 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" 225 d.file("test.dart", """
287 import 'dart:html'; 226 import 'dart:html';
288 227
289 import 'package:test/test.dart'; 228 import 'package:test/test.dart';
290 229
291 void main() { 230 void main() {
292 test("success", () { 231 test("success", () {
293 expect(document.query('#foo'), isNotNull); 232 expect(document.query('#foo'), isNotNull);
294 }); 233 });
295 } 234 }
296 """); 235 """).create();
297 236
298 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" 237 d.file("test.html", """
299 <html> 238 <html>
300 <head> 239 <head>
301 <link rel='x-dart-test' href='test.dart'> 240 <link rel='x-dart-test' href='test.dart'>
302 <script src="packages/test/dart.js"></script> 241 <script src="packages/test/dart.js"></script>
303 </head> 242 </head>
304 <body> 243 <body>
305 <div id="foo"></div> 244 <div id="foo"></div>
306 </body> 245 </body>
307 </html> 246 </html>
308 """); 247 """).create();
309 }); 248 });
310 249
311 test("on content shell", () { 250 test("on content shell", () {
312 var result = _runTest(["-p", "content-shell", "test.dart"]); 251 var test = runTest(["-p", "content-shell", "test.dart"]);
313 expect(result.exitCode, equals(0)); 252 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
253 test.shouldExit(0);
314 }); 254 });
315 255
316 test("on Chrome", () { 256 test("on Chrome", () {
317 var result = _runTest(["-p", "chrome", "test.dart"]); 257 var test = runTest(["-p", "chrome", "test.dart"]);
318 expect(result.exitCode, equals(0)); 258 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
259 test.shouldExit(0);
319 }); 260 });
320 261
321 // Regression test for https://github.com/dart-lang/test/issues/82. 262 // Regression test for https://github.com/dart-lang/test/issues/82.
322 test("ignores irrelevant link tags", () { 263 test("ignores irrelevant link tags", () {
323 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" 264 d.file("test.html", """
324 <html> 265 <html>
325 <head> 266 <head>
326 <link rel='x-dart-test-not'> 267 <link rel='x-dart-test-not'>
327 <link rel='other' href='test.dart'> 268 <link rel='other' href='test.dart'>
328 <link rel='x-dart-test' href='test.dart'> 269 <link rel='x-dart-test' href='test.dart'>
329 <script src="packages/test/dart.js"></script> 270 <script src="packages/test/dart.js"></script>
330 </head> 271 </head>
331 <body> 272 <body>
332 <div id="foo"></div> 273 <div id="foo"></div>
333 </body> 274 </body>
334 </html> 275 </html>
335 """); 276 """).create();
336 277
337 var result = _runTest(["-p", "content-shell", "test.dart"]); 278 var test = runTest(["-p", "content-shell", "test.dart"]);
338 expect(result.exitCode, equals(0)); 279 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
280 test.shouldExit(0);
339 }); 281 });
340 }); 282 });
341 }); 283 });
342 284
343 group("runs failing tests", () { 285 group("runs failing tests", () {
344 test("on Chrome", () {
345 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
346 var result = _runTest(["-p", "chrome", "test.dart"]);
347 expect(result.exitCode, equals(1));
348 });
349
350 test("on Safari", () {
351 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
352 var result = _runTest(["-p", "safari", "test.dart"]);
353 expect(result.exitCode, equals(1));
354 }, testOn: "mac-os");
355
356 test("on content-shell", () {
357 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure);
358 var result = _runTest(["-p", "content-shell", "test.dart"]);
359 expect(result.exitCode, equals(1));
360 });
361
362 test("that fail only on the browser", () { 286 test("that fail only on the browser", () {
363 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" 287 d.file("test.dart", """
364 import 'dart:async'; 288 import 'dart:async';
365 289
366 import 'package:path/path.dart' as p; 290 import 'package:path/path.dart' as p;
367 import 'package:test/test.dart'; 291 import 'package:test/test.dart';
368 292
369 void main() { 293 void main() {
370 test("test", () { 294 test("test", () {
371 if (p.style == p.Style.url) throw new TestFailure("oh no"); 295 if (p.style == p.Style.url) throw new TestFailure("oh no");
372 }); 296 });
373 } 297 }
374 """); 298 """).create();
375 var result = _runTest(["-p", "content-shell", "-p", "vm", "test.dart"]); 299
376 expect(result.exitCode, equals(1)); 300 var test = runTest(["-p", "content-shell", "-p", "vm", "test.dart"]);
301 test.stdout.expect(consumeThrough(contains("+1 -1: Some tests failed.")));
302 test.shouldExit(1);
377 }); 303 });
378 304
379 test("that fail only on the VM", () { 305 test("that fail only on the VM", () {
380 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" 306 d.file("test.dart", """
381 import 'dart:async'; 307 import 'dart:async';
382 308
383 import 'package:path/path.dart' as p; 309 import 'package:path/path.dart' as p;
384 import 'package:test/test.dart'; 310 import 'package:test/test.dart';
385 311
386 void main() { 312 void main() {
387 test("test", () { 313 test("test", () {
388 if (p.style != p.Style.url) throw new TestFailure("oh no"); 314 if (p.style != p.Style.url) throw new TestFailure("oh no");
389 }); 315 });
390 } 316 }
391 """); 317 """).create();
392 var result = _runTest(["-p", "content-shell", "-p", "vm", "test.dart"]); 318
393 expect(result.exitCode, equals(1)); 319 var test = runTest(["-p", "content-shell", "-p", "vm", "test.dart"]);
320 test.stdout.expect(consumeThrough(contains("+1 -1: Some tests failed.")));
321 test.shouldExit(1);
394 }); 322 });
395 323
396
397 group("with a custom HTML file", () { 324 group("with a custom HTML file", () {
398 setUp(() { 325 setUp(() {
399 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" 326 d.file("test.dart", """
400 import 'dart:html'; 327 import 'dart:html';
401 328
402 import 'package:test/test.dart'; 329 import 'package:test/test.dart';
403 330
404 void main() { 331 void main() {
405 test("failure", () { 332 test("failure", () {
406 expect(document.query('#foo'), isNull); 333 expect(document.query('#foo'), isNull);
407 }); 334 });
408 } 335 }
409 """); 336 """).create();
410 337
411 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" 338 d.file("test.html", """
412 <html> 339 <html>
413 <head> 340 <head>
414 <link rel='x-dart-test' href='test.dart'> 341 <link rel='x-dart-test' href='test.dart'>
415 <script src="packages/test/dart.js"></script> 342 <script src="packages/test/dart.js"></script>
416 </head> 343 </head>
417 <body> 344 <body>
418 <div id="foo"></div> 345 <div id="foo"></div>
419 </body> 346 </body>
420 </html> 347 </html>
421 """); 348 """).create();
422 }); 349 });
423 350
424 test("on content shell", () { 351 test("on content shell", () {
425 var result = _runTest(["-p", "content-shell", "test.dart"]); 352 var test = runTest(["-p", "content-shell", "test.dart"]);
426 expect(result.exitCode, equals(1)); 353 test.stdout.expect(consumeThrough(contains("-1: Some tests failed.")));
354 test.shouldExit(1);
427 }); 355 });
428 356
429 test("on Chrome", () { 357 test("on Chrome", () {
430 var result = _runTest(["-p", "chrome", "test.dart"]); 358 var test = runTest(["-p", "chrome", "test.dart"]);
431 expect(result.exitCode, equals(1)); 359 test.stdout.expect(consumeThrough(contains("-1: Some tests failed.")));
360 test.shouldExit(1);
432 }); 361 });
433 }); 362 });
434 }); 363 });
435 364
436 test("the compiler uses colors if the test runner uses colors", () { 365 test("the compiler uses colors if the test runner uses colors", () {
437 var testPath = p.join(_sandbox, "test.dart"); 366 d.file("test.dart", "String main() => 12;\n").create();
438 new File(testPath).writeAsStringSync("String main() => 12;\n");
439 367
440 var result = _runTest(["--color", "-p", "chrome", "test.dart"]); 368 var test = runTest(["--color", "-p", "chrome", "test.dart"]);
441 expect(result.stdout, contains('\u001b[35m')); 369 test.stdout.expect(consumeThrough(contains('\u001b[35m')));
442 expect(result.exitCode, equals(1)); 370 test.shouldExit(1);
443 }); 371 });
444 372
445 test("forwards prints from the browser test", () { 373 test("forwards prints from the browser test", () {
446 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" 374 d.file("test.dart", """
447 import 'dart:async'; 375 import 'dart:async';
448 376
449 import 'package:test/test.dart'; 377 import 'package:test/test.dart';
450 378
451 void main() { 379 void main() {
452 test("test", () { 380 test("test", () {
453 print("Hello,"); 381 print("Hello,");
454 return new Future(() => print("world!")); 382 return new Future(() => print("world!"));
455 }); 383 });
456 } 384 }
457 """); 385 """).create();
458 386
459 var result = _runTest(["-p", "content-shell", "test.dart"]); 387 var test = runTest(["-p", "content-shell", "test.dart"]);
460 expect(result.stdout, contains("Hello,\nworld!\n")); 388 test.stdout.expect(inOrder([
461 expect(result.exitCode, equals(0)); 389 consumeThrough("Hello,"),
390 "world!"
391 ]));
392 test.shouldExit(0);
462 }); 393 });
463 394
464 test("dartifies stack traces for JS-compiled tests by default", () { 395 test("dartifies stack traces for JS-compiled tests by default", () {
465 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); 396 d.file("test.dart", _failure).create();
466 var result = _runTest(["-p", "chrome", "--verbose-trace", "test.dart"]); 397
467 expect(result.stdout, contains(" main.<fn>\n")); 398 var test = runTest(["-p", "chrome", "--verbose-trace", "test.dart"]);
468 expect(result.stdout, contains("package:test")); 399 test.stdout.expect(containsInOrder([
469 expect(result.stdout, contains("dart:async/zone.dart")); 400 " main.<fn>",
470 expect(result.exitCode, equals(1)); 401 "package:test",
402 "dart:async/zone.dart"
403 ]));
404 test.shouldExit(1);
471 }); 405 });
472 406
473 test("doesn't dartify stack traces for JS-compiled tests with --js-trace", () { 407 test("doesn't dartify stack traces for JS-compiled tests with --js-trace", () {
474 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); 408 d.file("test.dart", _failure).create();
475 var result = _runTest( 409
410 var test = runTest(
476 ["-p", "chrome", "--verbose-trace", "--js-trace", "test.dart"]); 411 ["-p", "chrome", "--verbose-trace", "--js-trace", "test.dart"]);
477 expect(result.stdout, isNot(contains(" main.<fn>\n"))); 412 test.stdout.fork().expect(never(endsWith(" main.<fn>")));
478 expect(result.stdout, isNot(contains("package:test"))); 413 test.stdout.fork().expect(never(contains("package:test")));
479 expect(result.stdout, isNot(contains("dart:async/zone.dart"))); 414 test.stdout.fork().expect(never(contains("dart:async/zone.dart")));
480 expect(result.exitCode, equals(1)); 415 test.stdout.expect(consumeThrough(contains("-1: Some tests failed.")));
416 test.shouldExit(1);
481 }); 417 });
482 418
483 test("respects top-level @Timeout declarations", () { 419 test("respects top-level @Timeout declarations", () {
484 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 420 d.file("test.dart", '''
485 @Timeout(const Duration(seconds: 0)) 421 @Timeout(const Duration(seconds: 0))
486 422
487 import 'dart:async'; 423 import 'dart:async';
488 424
489 import 'package:test/test.dart'; 425 import 'package:test/test.dart';
490 426
491 void main() { 427 void main() {
492 test("timeout", () {}); 428 test("timeout", () {});
493 } 429 }
494 '''); 430 ''').create();
495 431
496 var result = _runTest(["-p", "content-shell", "test.dart"]); 432 var test = runTest(["-p", "content-shell", "test.dart"]);
497 expect(result.stdout, contains("Test timed out after 0 seconds.")); 433 test.stdout.expect(containsInOrder([
498 expect(result.stdout, contains("-1: Some tests failed.")); 434 "Test timed out after 0 seconds.",
435 "-1: Some tests failed."
436 ]));
437 test.shouldExit(1);
499 }); 438 });
500 439
501 group("with onPlatform", () { 440 group("with onPlatform", () {
502 test("respects matching Skips", () { 441 test("respects matching Skips", () {
503 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 442 d.file("test.dart", '''
504 import 'dart:async'; 443 import 'dart:async';
505 444
506 import 'package:test/test.dart'; 445 import 'package:test/test.dart';
507 446
508 void main() { 447 void main() {
509 test("fail", () => throw 'oh no', onPlatform: {"browser": new Skip()}); 448 test("fail", () => throw 'oh no', onPlatform: {"browser": new Skip()});
510 } 449 }
511 '''); 450 ''').create();
512 451
513 var result = _runTest(["-p", "content-shell", "test.dart"]); 452 var test = runTest(["-p", "content-shell", "test.dart"]);
514 expect(result.stdout, contains("+0 ~1: All tests skipped.")); 453 test.stdout.expect(consumeThrough(contains("+0 ~1: All tests skipped.")));
454 test.shouldExit(0);
515 }); 455 });
516 456
517 test("ignores non-matching Skips", () { 457 test("ignores non-matching Skips", () {
518 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 458 d.file("test.dart", '''
519 import 'dart:async'; 459 import 'dart:async';
520 460
521 import 'package:test/test.dart'; 461 import 'package:test/test.dart';
522 462
523 void main() { 463 void main() {
524 test("success", () {}, onPlatform: {"vm": new Skip()}); 464 test("success", () {}, onPlatform: {"vm": new Skip()});
525 } 465 }
526 '''); 466 ''').create();
527 467
528 var result = _runTest(["-p", "content-shell", "test.dart"]); 468 var test = runTest(["-p", "content-shell", "test.dart"]);
529 expect(result.stdout, contains("+1: All tests passed!")); 469 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
470 test.shouldExit(0);
530 }); 471 });
531 472
532 test("respects matching Timeouts", () { 473 test("respects matching Timeouts", () {
533 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 474 d.file("test.dart", '''
534 import 'dart:async'; 475 import 'dart:async';
535 476
536 import 'package:test/test.dart'; 477 import 'package:test/test.dart';
537 478
538 void main() { 479 void main() {
539 test("fail", () => throw 'oh no', onPlatform: { 480 test("fail", () => throw 'oh no', onPlatform: {
540 "browser": new Timeout(new Duration(seconds: 0)) 481 "browser": new Timeout(new Duration(seconds: 0))
541 }); 482 });
542 } 483 }
543 '''); 484 ''').create();
544 485
545 var result = _runTest(["-p", "content-shell", "test.dart"]); 486 var test = runTest(["-p", "content-shell", "test.dart"]);
546 expect(result.stdout, contains("Test timed out after 0 seconds.")); 487 test.stdout.expect(containsInOrder([
547 expect(result.stdout, contains("-1: Some tests failed.")); 488 "Test timed out after 0 seconds.",
489 "-1: Some tests failed."
490 ]));
491 test.shouldExit(1);
548 }); 492 });
549 493
550 test("ignores non-matching Timeouts", () { 494 test("ignores non-matching Timeouts", () {
551 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 495 d.file("test.dart", '''
552 import 'dart:async'; 496 import 'dart:async';
553 497
554 import 'package:test/test.dart'; 498 import 'package:test/test.dart';
555 499
556 void main() { 500 void main() {
557 test("success", () {}, onPlatform: { 501 test("success", () {}, onPlatform: {
558 "vm": new Timeout(new Duration(seconds: 0)) 502 "vm": new Timeout(new Duration(seconds: 0))
559 }); 503 });
560 } 504 }
561 '''); 505 ''').create();
562 506
563 var result = _runTest(["-p", "content-shell", "test.dart"]); 507 var test = runTest(["-p", "content-shell", "test.dart"]);
564 expect(result.stdout, contains("+1: All tests passed!")); 508 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
509 test.shouldExit(0);
565 }); 510 });
566 511
567 test("applies matching platforms in order", () { 512 test("applies matching platforms in order", () {
568 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 513 d.file("test.dart", '''
569 import 'dart:async'; 514 import 'dart:async';
570 515
571 import 'package:test/test.dart'; 516 import 'package:test/test.dart';
572 517
573 void main() { 518 void main() {
574 test("success", () {}, onPlatform: { 519 test("success", () {}, onPlatform: {
575 "browser": new Skip("first"), 520 "browser": new Skip("first"),
576 "browser || windows": new Skip("second"), 521 "browser || windows": new Skip("second"),
577 "browser || linux": new Skip("third"), 522 "browser || linux": new Skip("third"),
578 "browser || mac-os": new Skip("fourth"), 523 "browser || mac-os": new Skip("fourth"),
579 "browser || android": new Skip("fifth") 524 "browser || android": new Skip("fifth")
580 }); 525 });
581 } 526 }
582 '''); 527 ''').create();
583 528
584 var result = _runTest(["-p", "content-shell", "test.dart"]); 529 var test = runTest(["-p", "content-shell", "test.dart"]);
585 expect(result.stdout, contains("Skip: fifth")); 530 test.stdout.fork().expect(never(contains("Skip: first")));
586 expect(result.stdout, isNot(anyOf([ 531 test.stdout.fork().expect(never(contains("Skip: second")));
587 contains("Skip: first"), 532 test.stdout.fork().expect(never(contains("Skip: third")));
588 contains("Skip: second"), 533 test.stdout.fork().expect(never(contains("Skip: fourth")));
589 contains("Skip: third"), 534 test.stdout.expect(consumeThrough(contains("Skip: fifth")));
590 contains("Skip: fourth") 535 test.shouldExit(0);
591 ])));
592 }); 536 });
593 }); 537 });
594 538
595 group("with an @OnPlatform annotation", () { 539 group("with an @OnPlatform annotation", () {
596 test("respects matching Skips", () { 540 test("respects matching Skips", () {
597 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 541 d.file("test.dart", '''
598 @OnPlatform(const {"browser": const Skip()}) 542 @OnPlatform(const {"browser": const Skip()})
599 543
600 import 'dart:async'; 544 import 'dart:async';
601 545
602 import 'package:test/test.dart'; 546 import 'package:test/test.dart';
603 547
604 void main() { 548 void main() {
605 test("fail", () => throw 'oh no'); 549 test("fail", () => throw 'oh no');
606 } 550 }
607 '''); 551 ''').create();
608 552
609 var result = _runTest(["-p", "content-shell", "test.dart"]); 553 var test = runTest(["-p", "content-shell", "test.dart"]);
610 expect(result.stdout, contains("+0 ~1: All tests skipped.")); 554 test.stdout.expect(consumeThrough(contains("~1: All tests skipped.")));
555 test.shouldExit(0);
611 }); 556 });
612 557
613 test("ignores non-matching Skips", () { 558 test("ignores non-matching Skips", () {
614 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 559 d.file("test.dart", '''
615 @OnPlatform(const {"vm": const Skip()}) 560 @OnPlatform(const {"vm": const Skip()})
616 561
617 import 'dart:async'; 562 import 'dart:async';
618 563
619 import 'package:test/test.dart'; 564 import 'package:test/test.dart';
620 565
621 void main() { 566 void main() {
622 test("success", () {}); 567 test("success", () {});
623 } 568 }
624 '''); 569 ''').create();
625 570
626 var result = _runTest(["-p", "content-shell", "test.dart"]); 571 var test = runTest(["-p", "content-shell", "test.dart"]);
627 expect(result.stdout, contains("+1: All tests passed!")); 572 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
573 test.shouldExit(0);
628 }); 574 });
629 575
630 test("respects matching Timeouts", () { 576 test("respects matching Timeouts", () {
631 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 577 d.file("test.dart", '''
632 @OnPlatform(const { 578 @OnPlatform(const {
633 "browser": const Timeout(const Duration(seconds: 0)) 579 "browser": const Timeout(const Duration(seconds: 0))
634 }) 580 })
635 581
636 import 'dart:async'; 582 import 'dart:async';
637 583
638 import 'package:test/test.dart'; 584 import 'package:test/test.dart';
639 585
640 void main() { 586 void main() {
641 test("fail", () => throw 'oh no'); 587 test("fail", () => throw 'oh no');
642 } 588 }
643 '''); 589 ''').create();
644 590
645 var result = _runTest(["-p", "content-shell", "test.dart"]); 591 var test = runTest(["-p", "content-shell", "test.dart"]);
646 expect(result.stdout, contains("Test timed out after 0 seconds.")); 592 test.stdout.expect(containsInOrder([
647 expect(result.stdout, contains("-1: Some tests failed.")); 593 "Test timed out after 0 seconds.",
594 "-1: Some tests failed."
595 ]));
596 test.shouldExit(1);
648 }); 597 });
649 598
650 test("ignores non-matching Timeouts", () { 599 test("ignores non-matching Timeouts", () {
651 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' 600 d.file("test.dart", '''
652 @OnPlatform(const { 601 @OnPlatform(const {
653 "vm": const Timeout(const Duration(seconds: 0)) 602 "vm": const Timeout(const Duration(seconds: 0))
654 }) 603 })
655 604
656 import 'dart:async'; 605 import 'dart:async';
657 606
658 import 'package:test/test.dart'; 607 import 'package:test/test.dart';
659 608
660 void main() { 609 void main() {
661 test("success", () {}); 610 test("success", () {});
662 } 611 }
663 '''); 612 ''').create();
664 613
665 var result = _runTest(["-p", "content-shell", "test.dart"]); 614 var test = runTest(["-p", "content-shell", "test.dart"]);
666 expect(result.stdout, contains("+1: All tests passed!")); 615 test.stdout.expect(consumeThrough(contains("+1: All tests passed!")));
616 test.shouldExit(0);
667 }); 617 });
668 }); 618 });
669 } 619 }
670
671 ProcessResult _runTest(List<String> args) =>
672 runTest(args, workingDirectory: _sandbox);
OLDNEW
« no previous file with comments | « test/runner/browser/phantom_js_test.dart ('k') | test/runner/browser/safari_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698