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

Side by Side Diff: test/runner/json_reporter_test.dart

Issue 2066113002: Add location information to the JSON reporter. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: cr Created 4 years, 6 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 | « pubspec.yaml ('k') | no next file » | 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:convert'; 7 import 'dart:convert';
8 8
9 import 'package:path/path.dart' as p;
9 import 'package:scheduled_test/descriptor.dart' as d; 10 import 'package:scheduled_test/descriptor.dart' as d;
10 import 'package:scheduled_test/scheduled_stream.dart'; 11 import 'package:scheduled_test/scheduled_stream.dart';
11 import 'package:scheduled_test/scheduled_test.dart'; 12 import 'package:scheduled_test/scheduled_test.dart';
12 13
13 import 'package:test/src/runner/version.dart'; 14 import 'package:test/src/runner/version.dart';
14 15
15 import '../io.dart'; 16 import '../io.dart';
16 17
17 /// The first event emitted by the JSON reporter. 18 /// The first event emitted by the JSON reporter.
18 final _start = { 19 final _start = {
(...skipping 10 matching lines...) Expand all
29 test('success 1', () {}); 30 test('success 1', () {});
30 test('success 2', () {}); 31 test('success 2', () {});
31 test('success 3', () {}); 32 test('success 3', () {});
32 """, [ 33 """, [
33 _start, 34 _start,
34 _allSuites(), 35 _allSuites(),
35 _suite(0), 36 _suite(0),
36 _testStart(1, "loading test.dart", groupIDs: []), 37 _testStart(1, "loading test.dart", groupIDs: []),
37 _testDone(1, hidden: true), 38 _testDone(1, hidden: true),
38 _group(2, testCount: 3), 39 _group(2, testCount: 3),
39 _testStart(3, "success 1"), 40 _testStart(3, "success 1", line: 6, column: 7),
40 _testDone(3), 41 _testDone(3),
41 _testStart(4, "success 2"), 42 _testStart(4, "success 2", line: 7, column: 7),
42 _testDone(4), 43 _testDone(4),
43 _testStart(5, "success 3"), 44 _testStart(5, "success 3", line: 8, column: 7),
44 _testDone(5), 45 _testDone(5),
45 _done() 46 _done()
46 ]); 47 ]);
47 }); 48 });
48 49
49 test("runs several failing tests and reports when each fails", () { 50 test("runs several failing tests and reports when each fails", () {
50 _expectReport(""" 51 _expectReport("""
51 test('failure 1', () => throw new TestFailure('oh no')); 52 test('failure 1', () => throw new TestFailure('oh no'));
52 test('failure 2', () => throw new TestFailure('oh no')); 53 test('failure 2', () => throw new TestFailure('oh no'));
53 test('failure 3', () => throw new TestFailure('oh no')); 54 test('failure 3', () => throw new TestFailure('oh no'));
54 """, [ 55 """, [
55 _start, 56 _start,
56 _allSuites(), 57 _allSuites(),
57 _suite(0), 58 _suite(0),
58 _testStart(1, "loading test.dart", groupIDs: []), 59 _testStart(1, "loading test.dart", groupIDs: []),
59 _testDone(1, hidden: true), 60 _testDone(1, hidden: true),
60 _group(2, testCount: 3), 61 _group(2, testCount: 3),
61 _testStart(3, "failure 1"), 62 _testStart(3, "failure 1", line: 6, column: 7),
62 _error(3, "oh no", isFailure: true), 63 _error(3, "oh no", isFailure: true),
63 _testDone(3, result: "failure"), 64 _testDone(3, result: "failure"),
64 _testStart(4, "failure 2"), 65 _testStart(4, "failure 2", line: 7, column: 7),
65 _error(4, "oh no", isFailure: true), 66 _error(4, "oh no", isFailure: true),
66 _testDone(4, result: "failure"), 67 _testDone(4, result: "failure"),
67 _testStart(5, "failure 3"), 68 _testStart(5, "failure 3", line: 8, column: 7),
68 _error(5, "oh no", isFailure: true), 69 _error(5, "oh no", isFailure: true),
69 _testDone(5, result: "failure"), 70 _testDone(5, result: "failure"),
70 _done(success: false) 71 _done(success: false)
71 ]); 72 ]);
72 }); 73 });
73 74
74 test("includes the full stack trace with --verbose-trace", () { 75 test("includes the full stack trace with --verbose-trace", () {
75 d.file("test.dart", """ 76 d.file("test.dart", """
76 import 'dart:async'; 77 import 'dart:async';
77 78
(...skipping 15 matching lines...) Expand all
93 test('success 1', () {}); 94 test('success 1', () {});
94 test('failure 2', () => throw new TestFailure('oh no')); 95 test('failure 2', () => throw new TestFailure('oh no'));
95 test('success 2', () {}); 96 test('success 2', () {});
96 """, [ 97 """, [
97 _start, 98 _start,
98 _allSuites(), 99 _allSuites(),
99 _suite(0), 100 _suite(0),
100 _testStart(1, "loading test.dart", groupIDs: []), 101 _testStart(1, "loading test.dart", groupIDs: []),
101 _testDone(1, hidden: true), 102 _testDone(1, hidden: true),
102 _group(2, testCount: 4), 103 _group(2, testCount: 4),
103 _testStart(3, "failure 1"), 104 _testStart(3, "failure 1", line: 6, column: 7),
104 _error(3, "oh no", isFailure: true), 105 _error(3, "oh no", isFailure: true),
105 _testDone(3, result: "failure"), 106 _testDone(3, result: "failure"),
106 _testStart(4, "success 1"), 107 _testStart(4, "success 1", line: 7, column: 7),
107 _testDone(4), 108 _testDone(4),
108 _testStart(5, "failure 2"), 109 _testStart(5, "failure 2", line: 8, column: 7),
109 _error(5, "oh no", isFailure: true), 110 _error(5, "oh no", isFailure: true),
110 _testDone(5, result: "failure"), 111 _testDone(5, result: "failure"),
111 _testStart(6, "success 2"), 112 _testStart(6, "success 2", line: 9, column: 7),
112 _testDone(6), 113 _testDone(6),
113 _done(success: false) 114 _done(success: false)
114 ]); 115 ]);
115 }); 116 });
116 117
117 test("gracefully handles multiple test failures in a row", () { 118 test("gracefully handles multiple test failures in a row", () {
118 _expectReport(""" 119 _expectReport("""
119 // This completer ensures that the test isolate isn't killed until all 120 // This completer ensures that the test isolate isn't killed until all
120 // errors have been thrown. 121 // errors have been thrown.
121 var completer = new Completer(); 122 var completer = new Completer();
122 test('failures', () { 123 test('failures', () {
123 new Future.microtask(() => throw 'first error'); 124 new Future.microtask(() => throw 'first error');
124 new Future.microtask(() => throw 'second error'); 125 new Future.microtask(() => throw 'second error');
125 new Future.microtask(() => throw 'third error'); 126 new Future.microtask(() => throw 'third error');
126 new Future.microtask(completer.complete); 127 new Future.microtask(completer.complete);
127 }); 128 });
128 test('wait', () => completer.future); 129 test('wait', () => completer.future);
129 """, [ 130 """, [
130 _start, 131 _start,
131 _allSuites(), 132 _allSuites(),
132 _suite(0), 133 _suite(0),
133 _testStart(1, "loading test.dart", groupIDs: []), 134 _testStart(1, "loading test.dart", groupIDs: []),
134 _testDone(1, hidden: true), 135 _testDone(1, hidden: true),
135 _group(2, testCount: 2), 136 _group(2, testCount: 2),
136 _testStart(3, "failures"), 137 _testStart(3, "failures", line: 9, column: 7),
137 _error(3, "first error"), 138 _error(3, "first error"),
138 _error(3, "second error"), 139 _error(3, "second error"),
139 _error(3, "third error"), 140 _error(3, "third error"),
140 _testDone(3, result: "error"), 141 _testDone(3, result: "error"),
141 _testStart(4, "wait"), 142 _testStart(4, "wait", line: 15, column: 7),
142 _testDone(4), 143 _testDone(4),
143 _done(success: false) 144 _done(success: false)
144 ]); 145 ]);
145 }); 146 });
146 147
147 test("gracefully handles a test failing after completion", () { 148 test("gracefully handles a test failing after completion", () {
148 _expectReport(""" 149 _expectReport("""
149 // These completers ensure that the first test won't fail until the second 150 // These completers ensure that the first test won't fail until the second
150 // one is running, and that the test isolate isn't killed until all errors 151 // one is running, and that the test isolate isn't killed until all errors
151 // have been thrown. 152 // have been thrown.
152 var waitStarted = new Completer(); 153 var waitStarted = new Completer();
153 var testDone = new Completer(); 154 var testDone = new Completer();
154 test('failure', () { 155 test('failure', () {
155 waitStarted.future.then((_) { 156 waitStarted.future.then((_) {
156 new Future.microtask(testDone.complete); 157 new Future.microtask(testDone.complete);
157 throw 'oh no'; 158 throw 'oh no';
158 }); 159 });
159 }); 160 });
160 test('wait', () { 161 test('wait', () {
161 waitStarted.complete(); 162 waitStarted.complete();
162 return testDone.future; 163 return testDone.future;
163 }); 164 });
164 """, [ 165 """, [
165 _start, 166 _start,
166 _allSuites(), 167 _allSuites(),
167 _suite(0), 168 _suite(0),
168 _testStart(1, "loading test.dart", groupIDs: []), 169 _testStart(1, "loading test.dart", groupIDs: []),
169 _testDone(1, hidden: true), 170 _testDone(1, hidden: true),
170 _group(2, testCount: 2), 171 _group(2, testCount: 2),
171 _testStart(3, "failure"), 172 _testStart(3, "failure", line: 11, column: 7),
172 _testDone(3), 173 _testDone(3),
173 _testStart(4, "wait"), 174 _testStart(4, "wait", line: 17, column: 7),
174 _error(3, "oh no"), 175 _error(3, "oh no"),
175 _error(3, 176 _error(3,
176 "This test failed after it had already completed. Make sure to " 177 "This test failed after it had already completed. Make sure to "
177 "use [expectAsync]\n" 178 "use [expectAsync]\n"
178 "or the [completes] matcher when testing async code."), 179 "or the [completes] matcher when testing async code."),
179 _testDone(4), 180 _testDone(4),
180 _done(success: false) 181 _done(success: false)
181 ]); 182 ]);
182 }); 183 });
183 184
184 test("reports each test in its proper groups", () { 185 test("reports each test in its proper groups", () {
185 _expectReport(""" 186 _expectReport("""
186 group('group 1', () { 187 group('group 1', () {
187 group('.2', () { 188 group('.2', () {
188 group('.3', () { 189 group('.3', () {
189 test('success', () {}); 190 test('success', () {});
190 }); 191 });
191 }); 192 });
192 193
193 test('success', () {}); 194 test('success', () {});
194 test('success', () {}); 195 test('success', () {});
195 }); 196 });
196 """, [ 197 """, [
197 _start, 198 _start,
198 _allSuites(), 199 _allSuites(),
199 _suite(0), 200 _suite(0),
200 _testStart(1, "loading test.dart", groupIDs: []), 201 _testStart(1, "loading test.dart", groupIDs: []),
201 _testDone(1, hidden: true), 202 _testDone(1, hidden: true),
202 _group(2, testCount: 3), 203 _group(2, testCount: 3),
203 _group(3, name: "group 1", parentID: 2, testCount: 3), 204 _group(3,
204 _group(4, name: "group 1 .2", parentID: 3), 205 name: "group 1", parentID: 2, testCount: 3, line: 6, column: 7),
205 _group(5, name: "group 1 .2 .3", parentID: 4), 206 _group(4, name: "group 1 .2", parentID: 3, line: 7, column: 9),
206 _testStart(6, 'group 1 .2 .3 success', groupIDs: [2, 3, 4, 5]), 207 _group(5, name: "group 1 .2 .3", parentID: 4, line: 8, column: 11),
208 _testStart(6, 'group 1 .2 .3 success',
209 groupIDs: [2, 3, 4, 5], line: 9, column: 13),
207 _testDone(6), 210 _testDone(6),
208 _testStart(7, 'group 1 success', groupIDs: [2, 3]), 211 _testStart(7, 'group 1 success', groupIDs: [2, 3], line: 13, column: 9),
209 _testDone(7), 212 _testDone(7),
210 _testStart(8, 'group 1 success', groupIDs: [2, 3]), 213 _testStart(8, 'group 1 success', groupIDs: [2, 3], line: 14, column: 9),
211 _testDone(8), 214 _testDone(8),
212 _done() 215 _done()
213 ]); 216 ]);
214 }); 217 });
215 218
216 group("print:", () { 219 group("print:", () {
217 test("handles multiple prints", () { 220 test("handles multiple prints", () {
218 _expectReport(""" 221 _expectReport("""
219 test('test', () { 222 test('test', () {
220 print("one"); 223 print("one");
221 print("two"); 224 print("two");
222 print("three"); 225 print("three");
223 print("four"); 226 print("four");
224 }); 227 });
225 """, [ 228 """, [
226 _start, 229 _start,
227 _allSuites(), 230 _allSuites(),
228 _suite(0), 231 _suite(0),
229 _testStart(1, "loading test.dart", groupIDs: []), 232 _testStart(1, "loading test.dart", groupIDs: []),
230 _testDone(1, hidden: true), 233 _testDone(1, hidden: true),
231 _group(2), 234 _group(2),
232 _testStart(3, 'test'), 235 _testStart(3, 'test', line: 6, column: 9),
233 _print(3, "one"), 236 _print(3, "one"),
234 _print(3, "two"), 237 _print(3, "two"),
235 _print(3, "three"), 238 _print(3, "three"),
236 _print(3, "four"), 239 _print(3, "four"),
237 _testDone(3), 240 _testDone(3),
238 _done() 241 _done()
239 ]); 242 ]);
240 }); 243 });
241 244
242 test("handles a print after the test completes", () { 245 test("handles a print after the test completes", () {
(...skipping 16 matching lines...) Expand all
259 waitStarted.complete(); 262 waitStarted.complete();
260 return testDone.future; 263 return testDone.future;
261 }); 264 });
262 """, [ 265 """, [
263 _start, 266 _start,
264 _allSuites(), 267 _allSuites(),
265 _suite(0), 268 _suite(0),
266 _testStart(1, "loading test.dart", groupIDs: []), 269 _testStart(1, "loading test.dart", groupIDs: []),
267 _testDone(1, hidden: true), 270 _testDone(1, hidden: true),
268 _group(2, testCount: 2), 271 _group(2, testCount: 2),
269 _testStart(3, 'test'), 272 _testStart(3, 'test', line: 10, column: 9),
270 _testDone(3), 273 _testDone(3),
271 _testStart(4, 'wait'), 274 _testStart(4, 'wait', line: 20, column: 9),
272 _print(3, "one"), 275 _print(3, "one"),
273 _print(3, "two"), 276 _print(3, "two"),
274 _print(3, "three"), 277 _print(3, "three"),
275 _print(3, "four"), 278 _print(3, "four"),
276 _testDone(4), 279 _testDone(4),
277 _done() 280 _done()
278 ]); 281 ]);
279 }); 282 });
280 283
281 test("interleaves prints and errors", () { 284 test("interleaves prints and errors", () {
(...skipping 20 matching lines...) Expand all
302 }); 305 });
303 306
304 test('wait', () => completer.future); 307 test('wait', () => completer.future);
305 """, [ 308 """, [
306 _start, 309 _start,
307 _allSuites(), 310 _allSuites(),
308 _suite(0), 311 _suite(0),
309 _testStart(1, "loading test.dart", groupIDs: []), 312 _testStart(1, "loading test.dart", groupIDs: []),
310 _testDone(1, hidden: true), 313 _testDone(1, hidden: true),
311 _group(2, testCount: 2), 314 _group(2, testCount: 2),
312 _testStart(3, 'test'), 315 _testStart(3, 'test', line: 9, column: 9),
313 _print(3, "one"), 316 _print(3, "one"),
314 _print(3, "two"), 317 _print(3, "two"),
315 _error(3, "first error"), 318 _error(3, "first error"),
316 _print(3, "three"), 319 _print(3, "three"),
317 _print(3, "four"), 320 _print(3, "four"),
318 _error(3, "second error"), 321 _error(3, "second error"),
319 _print(3, "five"), 322 _print(3, "five"),
320 _print(3, "six"), 323 _print(3, "six"),
321 _testDone(3, result: "error"), 324 _testDone(3, result: "error"),
322 _testStart(4, 'wait'), 325 _testStart(4, 'wait', line: 27, column: 9),
323 _testDone(4), 326 _testDone(4),
324 _done(success: false) 327 _done(success: false)
325 ]); 328 ]);
326 }); 329 });
327 }); 330 });
328 331
329 group("skip:", () { 332 group("skip:", () {
330 test("reports skipped tests", () { 333 test("reports skipped tests", () {
331 _expectReport(""" 334 _expectReport("""
332 test('skip 1', () {}, skip: true); 335 test('skip 1', () {}, skip: true);
333 test('skip 2', () {}, skip: true); 336 test('skip 2', () {}, skip: true);
334 test('skip 3', () {}, skip: true); 337 test('skip 3', () {}, skip: true);
335 """, [ 338 """, [
336 _start, 339 _start,
337 _allSuites(), 340 _allSuites(),
338 _suite(0), 341 _suite(0),
339 _testStart(1, "loading test.dart", groupIDs: []), 342 _testStart(1, "loading test.dart", groupIDs: []),
340 _testDone(1, hidden: true), 343 _testDone(1, hidden: true),
341 _group(2, testCount: 3), 344 _group(2, testCount: 3),
342 _testStart(3, "skip 1", skip: true), 345 _testStart(3, "skip 1", skip: true, line: 6, column: 9),
343 _testDone(3), 346 _testDone(3),
344 _testStart(4, "skip 2", skip: true), 347 _testStart(4, "skip 2", skip: true, line: 7, column: 9),
345 _testDone(4), 348 _testDone(4),
346 _testStart(5, "skip 3", skip: true), 349 _testStart(5, "skip 3", skip: true, line: 8, column: 9),
347 _testDone(5), 350 _testDone(5),
348 _done() 351 _done()
349 ]); 352 ]);
350 }); 353 });
351 354
352 test("reports skipped groups", () { 355 test("reports skipped groups", () {
353 _expectReport(""" 356 _expectReport("""
354 group('skip', () { 357 group('skip', () {
355 test('success 1', () {}); 358 test('success 1', () {});
356 test('success 2', () {}); 359 test('success 2', () {});
357 test('success 3', () {}); 360 test('success 3', () {});
358 }, skip: true); 361 }, skip: true);
359 """, [ 362 """, [
360 _start, 363 _start,
361 _allSuites(), 364 _allSuites(),
362 _suite(0), 365 _suite(0),
363 _testStart(1, "loading test.dart", groupIDs: []), 366 _testStart(1, "loading test.dart", groupIDs: []),
364 _testDone(1, hidden: true), 367 _testDone(1, hidden: true),
365 _group(2, testCount: 0), 368 _group(2, testCount: 0),
366 _group(3, name: "skip", parentID: 2, skip: true, testCount: 0), 369 _group(3, name: "skip", parentID: 2, skip: true, testCount: 0,
367 _testStart(4, "skip", groupIDs: [2, 3], skip: true), 370 line: 6, column: 9),
371 _testStart(4, "skip", groupIDs: [2, 3], skip: true,
372 line: 6, column: 9),
368 _testDone(4), 373 _testDone(4),
369 _done() 374 _done()
370 ]); 375 ]);
371 }); 376 });
372 377
373 test("reports the skip reason if available", () { 378 test("reports the skip reason if available", () {
374 _expectReport(""" 379 _expectReport("""
375 test('skip 1', () {}, skip: 'some reason'); 380 test('skip 1', () {}, skip: 'some reason');
376 test('skip 2', () {}, skip: 'or another'); 381 test('skip 2', () {}, skip: 'or another');
377 """, [ 382 """, [
378 _start, 383 _start,
379 _allSuites(), 384 _allSuites(),
380 _suite(0), 385 _suite(0),
381 _testStart(1, "loading test.dart", groupIDs: []), 386 _testStart(1, "loading test.dart", groupIDs: []),
382 _testDone(1, hidden: true), 387 _testDone(1, hidden: true),
383 _group(2, testCount: 2), 388 _group(2, testCount: 2),
384 _testStart(3, "skip 1", skip: "some reason"), 389 _testStart(3, "skip 1", skip: "some reason", line: 6, column: 9),
385 _testDone(3), 390 _testDone(3),
386 _testStart(4, "skip 2", skip: "or another"), 391 _testStart(4, "skip 2", skip: "or another", line: 7, column: 9),
387 _testDone(4), 392 _testDone(4),
388 _done() 393 _done()
389 ]); 394 ]);
390 }); 395 });
391 }); 396 });
397
398 group("reports line and column numbers for", () {
399 test("the first call to setUpAll()", () {
400 _expectReport("""
401 setUpAll(() {});
402 setUpAll(() {});
403 setUpAll(() {});
404 test('success', () {});
405 """, [
406 _start,
407 _allSuites(),
408 _suite(0),
409 _testStart(1, "loading test.dart", groupIDs: []),
410 _testDone(1, hidden: true),
411 _group(2, testCount: 1),
412 _testStart(3, "(setUpAll)", line: 6, column: 9),
413 _testDone(3, hidden: true),
414 _testStart(4, "success", line: 9, column: 9),
415 _testDone(4),
416 _done()
417 ]);
418 });
419
420 test("the first call to tearDownAll()", () {
421 _expectReport("""
422 tearDownAll(() {});
423 tearDownAll(() {});
424 tearDownAll(() {});
425 test('success', () {});
426 """, [
427 _start,
428 _allSuites(),
429 _suite(0),
430 _testStart(1, "loading test.dart", groupIDs: []),
431 _testDone(1, hidden: true),
432 _group(2, testCount: 1),
433 _testStart(3, "success", line: 9, column: 9),
434 _testDone(3),
435 _testStart(4, "(tearDownAll)", line: 6, column: 9),
436 _testDone(4, hidden: true),
437 _done()
438 ]);
439 });
440
441 test("a test compiled to JS", () {
442 _expectReport("""
443 test('success', () {});
444 """, [
445 _start,
446 _allSuites(),
447 _suite(0, platform: "chrome"),
448 _testStart(1, "compiling test.dart", groupIDs: []),
449 _testDone(1, hidden: true),
450 _group(2, testCount: 1),
451 _testStart(3, "success", line: 6, column: 9),
452 _testDone(3),
453 _done()
454 ], args: ["-p", "chrome"]);
455 }, tags: ["chrome"]);
456 });
457
458
459 test("doesn't report line and column information for a test compiled to JS "
460 "with --js-trace", () {
461 _expectReport("""
462 test('success', () {});
463 """, [
464 _start,
465 _allSuites(),
466 _suite(0, platform: "chrome"),
467 _testStart(1, "compiling test.dart", groupIDs: []),
468 _testDone(1, hidden: true),
469 _group(2, testCount: 1),
470 _testStart(3, "success"),
471 _testDone(3),
472 _done()
473 ], args: ["-p", "chrome", "--js-trace"]);
474 }, tags: ["chrome"]);
392 } 475 }
393 476
394 /// Asserts that the tests defined by [tests] produce the JSON events in 477 /// Asserts that the tests defined by [tests] produce the JSON events in
395 /// [expected]. 478 /// [expected].
396 void _expectReport(String tests, List<Map> expected) { 479 void _expectReport(String tests, List<Map> expected, {List<String> args}) {
397 var dart = """ 480 var dart = """
398 import 'dart:async'; 481 import 'dart:async';
399 482
400 import 'package:test/test.dart'; 483 import 'package:test/test.dart';
401 484
402 void main() { 485 void main() {
403 $tests 486 $tests
404 } 487 }
405 """; 488 """;
406 489
407 d.file("test.dart", dart).create(); 490 d.file("test.dart", dart).create();
408 491
409 var test = runTest(["test.dart"], reporter: "json"); 492 var test = runTest(["test.dart"]..addAll(args ?? []), reporter: "json");
410 test.shouldExit(); 493 test.shouldExit();
411 494
412 schedule(() async { 495 schedule(() async {
413 var stdoutLines = await test.stdoutStream().toList(); 496 var stdoutLines = await test.stdoutStream().toList();
414 497
415 expect(stdoutLines.length, equals(expected.length), 498 expect(stdoutLines.length, equals(expected.length),
416 reason: "Expected $stdoutLines to match ${JSON.encode(expected)}."); 499 reason: "Expected $stdoutLines to match ${JSON.encode(expected)}.");
417 500
418 // TODO(nweiz): validate each event against the JSON schema when 501 // TODO(nweiz): validate each event against the JSON schema when
419 // patefacio/json_schema#4 is merged. 502 // patefacio/json_schema#4 is merged.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 /// Returns the event emitted by the JSON reporter indicating that a group has 540 /// Returns the event emitted by the JSON reporter indicating that a group has
458 /// begun running. 541 /// begun running.
459 /// 542 ///
460 /// If [skip] is `true`, the group is expected to be marked as skipped without a 543 /// If [skip] is `true`, the group is expected to be marked as skipped without a
461 /// reason. If it's a [String], the group is expected to be marked as skipped 544 /// reason. If it's a [String], the group is expected to be marked as skipped
462 /// with that reason. 545 /// with that reason.
463 /// 546 ///
464 /// The [testCount] parameter indicates the number of tests in the group. It 547 /// The [testCount] parameter indicates the number of tests in the group. It
465 /// defaults to 1. 548 /// defaults to 1.
466 Map _group(int id, {String name, int suiteID, int parentID, skip, 549 Map _group(int id, {String name, int suiteID, int parentID, skip,
467 int testCount}) { 550 int testCount, int line, int column}) {
551 if ((line == null) != (column == null)) {
552 throw new ArgumentError(
553 "line and column must either both be null or both be passed");
554 }
555
468 return { 556 return {
469 "type": "group", 557 "type": "group",
470 "group": { 558 "group": {
471 "id": id, 559 "id": id,
472 "name": name, 560 "name": name,
473 "suiteID": suiteID ?? 0, 561 "suiteID": suiteID ?? 0,
474 "parentID": parentID, 562 "parentID": parentID,
475 "metadata": _metadata(skip: skip), 563 "metadata": _metadata(skip: skip),
476 "testCount": testCount ?? 1 564 "testCount": testCount ?? 1,
565 "line": line,
566 "column": column,
567 "url":
568 line == null ? null : p.toUri(p.join(sandbox, "test.dart")).toString()
477 } 569 }
478 }; 570 };
479 } 571 }
480 572
481 /// Returns the event emitted by the JSON reporter indicating that a test has 573 /// Returns the event emitted by the JSON reporter indicating that a test has
482 /// begun running. 574 /// begun running.
483 /// 575 ///
484 /// If [parentIDs] is passed, it's the IDs of groups containing this test. If 576 /// If [parentIDs] is passed, it's the IDs of groups containing this test. If
485 /// [skip] is `true`, the test is expected to be marked as skipped without a 577 /// [skip] is `true`, the test is expected to be marked as skipped without a
486 /// reason. If it's a [String], the test is expected to be marked as skipped 578 /// reason. If it's a [String], the test is expected to be marked as skipped
487 /// with that reason. 579 /// with that reason.
488 Map _testStart(int id, String name, {int suiteID, Iterable<int> groupIDs, 580 Map _testStart(int id, String name, {int suiteID, Iterable<int> groupIDs,
489 skip}) { 581 int line, int column, skip}) {
582 if ((line == null) != (column == null)) {
583 throw new ArgumentError(
584 "line and column must either both be null or both be passed");
585 }
586
490 return { 587 return {
491 "type": "testStart", 588 "type": "testStart",
492 "test": { 589 "test": {
493 "id": id, 590 "id": id,
494 "name": name, 591 "name": name,
495 "suiteID": suiteID ?? 0, 592 "suiteID": suiteID ?? 0,
496 "groupIDs": groupIDs ?? [2], 593 "groupIDs": groupIDs ?? [2],
497 "metadata": _metadata(skip: skip) 594 "metadata": _metadata(skip: skip),
595 "line": line,
596 "column": column,
597 "url":
598 line == null ? null : p.toUri(p.join(sandbox, "test.dart")).toString()
498 } 599 }
499 }; 600 };
500 } 601 }
501 602
502 /// Returns the event emitted by the JSON reporter indicating that a test 603 /// Returns the event emitted by the JSON reporter indicating that a test
503 /// printed [message]. 604 /// printed [message].
504 Map _print(int id, String message) { 605 Map _print(int id, String message) {
505 return { 606 return {
506 "type": "print", 607 "type": "print",
507 "testID": id, 608 "testID": id,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 /// Returns the serialized metadata corresponding to [skip]. 644 /// Returns the serialized metadata corresponding to [skip].
544 Map _metadata({skip}) { 645 Map _metadata({skip}) {
545 if (skip == true) { 646 if (skip == true) {
546 return {"skip": true, "skipReason": null}; 647 return {"skip": true, "skipReason": null};
547 } else if (skip is String) { 648 } else if (skip is String) {
548 return {"skip": true, "skipReason": skip}; 649 return {"skip": true, "skipReason": skip};
549 } else { 650 } else {
550 return {"skip": false, "skipReason": null}; 651 return {"skip": false, "skipReason": null};
551 } 652 }
552 } 653 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698