| OLD | NEW |
| 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:scheduled_test/descriptor.dart' as d; | 9 import 'package:scheduled_test/descriptor.dart' as d; |
| 10 import 'package:scheduled_test/scheduled_stream.dart'; | 10 import 'package:scheduled_test/scheduled_stream.dart'; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 void main() { | 24 void main() { |
| 25 useSandbox(); | 25 useSandbox(); |
| 26 | 26 |
| 27 test("runs several successful tests and reports when each completes", () { | 27 test("runs several successful tests and reports when each completes", () { |
| 28 _expectReport(""" | 28 _expectReport(""" |
| 29 test('success 1', () {}); | 29 test('success 1', () {}); |
| 30 test('success 2', () {}); | 30 test('success 2', () {}); |
| 31 test('success 3', () {}); | 31 test('success 3', () {}); |
| 32 """, [ | 32 """, [ |
| 33 _start, | 33 _start, |
| 34 _testStart(0, "loading test.dart", groupIDs: []), | 34 _suite(0), |
| 35 _testDone(0, hidden: true), | 35 _testStart(1, "loading test.dart", groupIDs: []), |
| 36 _group(1), | 36 _testDone(1, hidden: true), |
| 37 _testStart(2, "success 1"), | 37 _group(2), |
| 38 _testDone(2), | 38 _testStart(3, "success 1"), |
| 39 _testStart(3, "success 2"), | |
| 40 _testDone(3), | 39 _testDone(3), |
| 41 _testStart(4, "success 3"), | 40 _testStart(4, "success 2"), |
| 42 _testDone(4), | 41 _testDone(4), |
| 42 _testStart(5, "success 3"), |
| 43 _testDone(5), |
| 43 _done() | 44 _done() |
| 44 ]); | 45 ]); |
| 45 }); | 46 }); |
| 46 | 47 |
| 47 test("runs several failing tests and reports when each fails", () { | 48 test("runs several failing tests and reports when each fails", () { |
| 48 _expectReport(""" | 49 _expectReport(""" |
| 49 test('failure 1', () => throw new TestFailure('oh no')); | 50 test('failure 1', () => throw new TestFailure('oh no')); |
| 50 test('failure 2', () => throw new TestFailure('oh no')); | 51 test('failure 2', () => throw new TestFailure('oh no')); |
| 51 test('failure 3', () => throw new TestFailure('oh no')); | 52 test('failure 3', () => throw new TestFailure('oh no')); |
| 52 """, [ | 53 """, [ |
| 53 _start, | 54 _start, |
| 54 _testStart(0, "loading test.dart", groupIDs: []), | 55 _suite(0), |
| 55 _testDone(0, hidden: true), | 56 _testStart(1, "loading test.dart", groupIDs: []), |
| 56 _group(1), | 57 _testDone(1, hidden: true), |
| 57 _testStart(2, "failure 1"), | 58 _group(2), |
| 58 _error(2, "oh no", isFailure: true), | 59 _testStart(3, "failure 1"), |
| 59 _testDone(2, result: "failure"), | |
| 60 _testStart(3, "failure 2"), | |
| 61 _error(3, "oh no", isFailure: true), | 60 _error(3, "oh no", isFailure: true), |
| 62 _testDone(3, result: "failure"), | 61 _testDone(3, result: "failure"), |
| 63 _testStart(4, "failure 3"), | 62 _testStart(4, "failure 2"), |
| 64 _error(4, "oh no", isFailure: true), | 63 _error(4, "oh no", isFailure: true), |
| 65 _testDone(4, result: "failure"), | 64 _testDone(4, result: "failure"), |
| 65 _testStart(5, "failure 3"), |
| 66 _error(5, "oh no", isFailure: true), |
| 67 _testDone(5, result: "failure"), |
| 66 _done(success: false) | 68 _done(success: false) |
| 67 ]); | 69 ]); |
| 68 }); | 70 }); |
| 69 | 71 |
| 70 test("includes the full stack trace with --verbose-trace", () { | 72 test("includes the full stack trace with --verbose-trace", () { |
| 71 d.file("test.dart", """ | 73 d.file("test.dart", """ |
| 72 import 'dart:async'; | 74 import 'dart:async'; |
| 73 | 75 |
| 74 import 'package:test/test.dart'; | 76 import 'package:test/test.dart'; |
| 75 | 77 |
| 76 void main() { | 78 void main() { |
| 77 test("failure", () => throw "oh no"); | 79 test("failure", () => throw "oh no"); |
| 78 } | 80 } |
| 79 """).create(); | 81 """).create(); |
| 80 | 82 |
| 81 var test = runTest(["--verbose-trace", "test.dart"], reporter: "json"); | 83 var test = runTest(["--verbose-trace", "test.dart"], reporter: "json"); |
| 82 test.stdout.expect(consumeThrough(contains("dart:isolate-patch"))); | 84 test.stdout.expect(consumeThrough(contains("dart:isolate-patch"))); |
| 83 test.shouldExit(1); | 85 test.shouldExit(1); |
| 84 }); | 86 }); |
| 85 | 87 |
| 86 test("runs failing tests along with successful tests", () { | 88 test("runs failing tests along with successful tests", () { |
| 87 _expectReport(""" | 89 _expectReport(""" |
| 88 test('failure 1', () => throw new TestFailure('oh no')); | 90 test('failure 1', () => throw new TestFailure('oh no')); |
| 89 test('success 1', () {}); | 91 test('success 1', () {}); |
| 90 test('failure 2', () => throw new TestFailure('oh no')); | 92 test('failure 2', () => throw new TestFailure('oh no')); |
| 91 test('success 2', () {}); | 93 test('success 2', () {}); |
| 92 """, [ | 94 """, [ |
| 93 _start, | 95 _start, |
| 94 _testStart(0, "loading test.dart", groupIDs: []), | 96 _suite(0), |
| 95 _testDone(0, hidden: true), | 97 _testStart(1, "loading test.dart", groupIDs: []), |
| 96 _group(1), | 98 _testDone(1, hidden: true), |
| 97 _testStart(2, "failure 1"), | 99 _group(2), |
| 98 _error(2, "oh no", isFailure: true), | 100 _testStart(3, "failure 1"), |
| 99 _testDone(2, result: "failure"), | 101 _error(3, "oh no", isFailure: true), |
| 100 _testStart(3, "success 1"), | 102 _testDone(3, result: "failure"), |
| 101 _testDone(3), | 103 _testStart(4, "success 1"), |
| 102 _testStart(4, "failure 2"), | 104 _testDone(4), |
| 103 _error(4, "oh no", isFailure: true), | 105 _testStart(5, "failure 2"), |
| 104 _testDone(4, result: "failure"), | 106 _error(5, "oh no", isFailure: true), |
| 105 _testStart(5, "success 2"), | 107 _testDone(5, result: "failure"), |
| 106 _testDone(5), | 108 _testStart(6, "success 2"), |
| 109 _testDone(6), |
| 107 _done(success: false) | 110 _done(success: false) |
| 108 ]); | 111 ]); |
| 109 }); | 112 }); |
| 110 | 113 |
| 111 test("gracefully handles multiple test failures in a row", () { | 114 test("gracefully handles multiple test failures in a row", () { |
| 112 _expectReport(""" | 115 _expectReport(""" |
| 113 // This completer ensures that the test isolate isn't killed until all | 116 // This completer ensures that the test isolate isn't killed until all |
| 114 // errors have been thrown. | 117 // errors have been thrown. |
| 115 var completer = new Completer(); | 118 var completer = new Completer(); |
| 116 test('failures', () { | 119 test('failures', () { |
| 117 new Future.microtask(() => throw 'first error'); | 120 new Future.microtask(() => throw 'first error'); |
| 118 new Future.microtask(() => throw 'second error'); | 121 new Future.microtask(() => throw 'second error'); |
| 119 new Future.microtask(() => throw 'third error'); | 122 new Future.microtask(() => throw 'third error'); |
| 120 new Future.microtask(completer.complete); | 123 new Future.microtask(completer.complete); |
| 121 }); | 124 }); |
| 122 test('wait', () => completer.future); | 125 test('wait', () => completer.future); |
| 123 """, [ | 126 """, [ |
| 124 _start, | 127 _start, |
| 125 _testStart(0, "loading test.dart", groupIDs: []), | 128 _suite(0), |
| 126 _testDone(0, hidden: true), | 129 _testStart(1, "loading test.dart", groupIDs: []), |
| 127 _group(1), | 130 _testDone(1, hidden: true), |
| 128 _testStart(2, "failures"), | 131 _group(2), |
| 129 _error(2, "first error"), | 132 _testStart(3, "failures"), |
| 130 _error(2, "second error"), | 133 _error(3, "first error"), |
| 131 _error(2, "third error"), | 134 _error(3, "second error"), |
| 132 _testDone(2, result: "error"), | 135 _error(3, "third error"), |
| 133 _testStart(3, "wait"), | 136 _testDone(3, result: "error"), |
| 134 _testDone(3), | 137 _testStart(4, "wait"), |
| 138 _testDone(4), |
| 135 _done(success: false) | 139 _done(success: false) |
| 136 ]); | 140 ]); |
| 137 }); | 141 }); |
| 138 | 142 |
| 139 test("gracefully handles a test failing after completion", () { | 143 test("gracefully handles a test failing after completion", () { |
| 140 _expectReport(""" | 144 _expectReport(""" |
| 141 // These completers ensure that the first test won't fail until the second | 145 // These completers ensure that the first test won't fail until the second |
| 142 // one is running, and that the test isolate isn't killed until all errors | 146 // one is running, and that the test isolate isn't killed until all errors |
| 143 // have been thrown. | 147 // have been thrown. |
| 144 var waitStarted = new Completer(); | 148 var waitStarted = new Completer(); |
| 145 var testDone = new Completer(); | 149 var testDone = new Completer(); |
| 146 test('failure', () { | 150 test('failure', () { |
| 147 waitStarted.future.then((_) { | 151 waitStarted.future.then((_) { |
| 148 new Future.microtask(testDone.complete); | 152 new Future.microtask(testDone.complete); |
| 149 throw 'oh no'; | 153 throw 'oh no'; |
| 150 }); | 154 }); |
| 151 }); | 155 }); |
| 152 test('wait', () { | 156 test('wait', () { |
| 153 waitStarted.complete(); | 157 waitStarted.complete(); |
| 154 return testDone.future; | 158 return testDone.future; |
| 155 }); | 159 }); |
| 156 """, [ | 160 """, [ |
| 157 _start, | 161 _start, |
| 158 _testStart(0, "loading test.dart", groupIDs: []), | 162 _suite(0), |
| 159 _testDone(0, hidden: true), | 163 _testStart(1, "loading test.dart", groupIDs: []), |
| 160 _group(1), | 164 _testDone(1, hidden: true), |
| 161 _testStart(2, "failure"), | 165 _group(2), |
| 162 _testDone(2), | 166 _testStart(3, "failure"), |
| 163 _testStart(3, "wait"), | 167 _testDone(3), |
| 164 _error(2, "oh no"), | 168 _testStart(4, "wait"), |
| 165 _error(2, | 169 _error(3, "oh no"), |
| 170 _error(3, |
| 166 "This test failed after it had already completed. Make sure to " | 171 "This test failed after it had already completed. Make sure to " |
| 167 "use [expectAsync]\n" | 172 "use [expectAsync]\n" |
| 168 "or the [completes] matcher when testing async code."), | 173 "or the [completes] matcher when testing async code."), |
| 169 _testDone(3), | 174 _testDone(4), |
| 170 _done(success: false) | 175 _done(success: false) |
| 171 ]); | 176 ]); |
| 172 }); | 177 }); |
| 173 | 178 |
| 174 test("reports each test in its proper groups", () { | 179 test("reports each test in its proper groups", () { |
| 175 _expectReport(""" | 180 _expectReport(""" |
| 176 group('group 1', () { | 181 group('group 1', () { |
| 177 group('.2', () { | 182 group('.2', () { |
| 178 group('.3', () { | 183 group('.3', () { |
| 179 test('success', () {}); | 184 test('success', () {}); |
| 180 }); | 185 }); |
| 181 }); | 186 }); |
| 182 | 187 |
| 183 test('success', () {}); | 188 test('success', () {}); |
| 184 test('success', () {}); | 189 test('success', () {}); |
| 185 }); | 190 }); |
| 186 """, [ | 191 """, [ |
| 187 _start, | 192 _start, |
| 188 _testStart(0, "loading test.dart", groupIDs: []), | 193 _suite(0), |
| 189 _testDone(0, hidden: true), | 194 _testStart(1, "loading test.dart", groupIDs: []), |
| 190 _group(1), | 195 _testDone(1, hidden: true), |
| 191 _group(2, name: "group 1", parentID: 1), | 196 _group(2), |
| 192 _group(3, name: "group 1 .2", parentID: 2), | 197 _group(3, name: "group 1", parentID: 2), |
| 193 _group(4, name: "group 1 .2 .3", parentID: 3), | 198 _group(4, name: "group 1 .2", parentID: 3), |
| 194 _testStart(5, 'group 1 .2 .3 success', groupIDs: [1, 2, 3, 4]), | 199 _group(5, name: "group 1 .2 .3", parentID: 4), |
| 195 _testDone(5), | 200 _testStart(6, 'group 1 .2 .3 success', groupIDs: [2, 3, 4, 5]), |
| 196 _testStart(6, 'group 1 success', groupIDs: [1, 2]), | |
| 197 _testDone(6), | 201 _testDone(6), |
| 198 _testStart(7, 'group 1 success', groupIDs: [1, 2]), | 202 _testStart(7, 'group 1 success', groupIDs: [2, 3]), |
| 199 _testDone(7), | 203 _testDone(7), |
| 204 _testStart(8, 'group 1 success', groupIDs: [2, 3]), |
| 205 _testDone(8), |
| 200 _done() | 206 _done() |
| 201 ]); | 207 ]); |
| 202 }); | 208 }); |
| 203 | 209 |
| 204 group("print:", () { | 210 group("print:", () { |
| 205 test("handles multiple prints", () { | 211 test("handles multiple prints", () { |
| 206 _expectReport(""" | 212 _expectReport(""" |
| 207 test('test', () { | 213 test('test', () { |
| 208 print("one"); | 214 print("one"); |
| 209 print("two"); | 215 print("two"); |
| 210 print("three"); | 216 print("three"); |
| 211 print("four"); | 217 print("four"); |
| 212 }); | 218 }); |
| 213 """, [ | 219 """, [ |
| 214 _start, | 220 _start, |
| 215 _testStart(0, "loading test.dart", groupIDs: []), | 221 _suite(0), |
| 216 _testDone(0, hidden: true), | 222 _testStart(1, "loading test.dart", groupIDs: []), |
| 217 _group(1), | 223 _testDone(1, hidden: true), |
| 218 _testStart(2, 'test'), | 224 _group(2), |
| 219 _print(2, "one"), | 225 _testStart(3, 'test'), |
| 220 _print(2, "two"), | 226 _print(3, "one"), |
| 221 _print(2, "three"), | 227 _print(3, "two"), |
| 222 _print(2, "four"), | 228 _print(3, "three"), |
| 223 _testDone(2), | 229 _print(3, "four"), |
| 230 _testDone(3), |
| 224 _done() | 231 _done() |
| 225 ]); | 232 ]); |
| 226 }); | 233 }); |
| 227 | 234 |
| 228 test("handles a print after the test completes", () { | 235 test("handles a print after the test completes", () { |
| 229 _expectReport(""" | 236 _expectReport(""" |
| 230 // This completer ensures that the test isolate isn't killed until all | 237 // This completer ensures that the test isolate isn't killed until all |
| 231 // prints have happened. | 238 // prints have happened. |
| 232 var testDone = new Completer(); | 239 var testDone = new Completer(); |
| 233 var waitStarted = new Completer(); | 240 var waitStarted = new Completer(); |
| 234 test('test', () async { | 241 test('test', () async { |
| 235 waitStarted.future.then((_) { | 242 waitStarted.future.then((_) { |
| 236 new Future(() => print("one")); | 243 new Future(() => print("one")); |
| 237 new Future(() => print("two")); | 244 new Future(() => print("two")); |
| 238 new Future(() => print("three")); | 245 new Future(() => print("three")); |
| 239 new Future(() => print("four")); | 246 new Future(() => print("four")); |
| 240 new Future(testDone.complete); | 247 new Future(testDone.complete); |
| 241 }); | 248 }); |
| 242 }); | 249 }); |
| 243 | 250 |
| 244 test('wait', () { | 251 test('wait', () { |
| 245 waitStarted.complete(); | 252 waitStarted.complete(); |
| 246 return testDone.future; | 253 return testDone.future; |
| 247 }); | 254 }); |
| 248 """, [ | 255 """, [ |
| 249 _start, | 256 _start, |
| 250 _testStart(0, "loading test.dart", groupIDs: []), | 257 _suite(0), |
| 251 _testDone(0, hidden: true), | 258 _testStart(1, "loading test.dart", groupIDs: []), |
| 252 _group(1), | 259 _testDone(1, hidden: true), |
| 253 _testStart(2, 'test'), | 260 _group(2), |
| 254 _testDone(2), | 261 _testStart(3, 'test'), |
| 255 _testStart(3, 'wait'), | |
| 256 _print(2, "one"), | |
| 257 _print(2, "two"), | |
| 258 _print(2, "three"), | |
| 259 _print(2, "four"), | |
| 260 _testDone(3), | 262 _testDone(3), |
| 263 _testStart(4, 'wait'), |
| 264 _print(3, "one"), |
| 265 _print(3, "two"), |
| 266 _print(3, "three"), |
| 267 _print(3, "four"), |
| 268 _testDone(4), |
| 261 _done() | 269 _done() |
| 262 ]); | 270 ]); |
| 263 }); | 271 }); |
| 264 | 272 |
| 265 test("interleaves prints and errors", () { | 273 test("interleaves prints and errors", () { |
| 266 _expectReport(""" | 274 _expectReport(""" |
| 267 // This completer ensures that the test isolate isn't killed until all | 275 // This completer ensures that the test isolate isn't killed until all |
| 268 // prints have happened. | 276 // prints have happened. |
| 269 var completer = new Completer(); | 277 var completer = new Completer(); |
| 270 test('test', () { | 278 test('test', () { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 281 }); | 289 }); |
| 282 | 290 |
| 283 print("one"); | 291 print("one"); |
| 284 print("two"); | 292 print("two"); |
| 285 throw "first error"; | 293 throw "first error"; |
| 286 }); | 294 }); |
| 287 | 295 |
| 288 test('wait', () => completer.future); | 296 test('wait', () => completer.future); |
| 289 """, [ | 297 """, [ |
| 290 _start, | 298 _start, |
| 291 _testStart(0, "loading test.dart", groupIDs: []), | 299 _suite(0), |
| 292 _testDone(0, hidden: true), | 300 _testStart(1, "loading test.dart", groupIDs: []), |
| 293 _group(1), | 301 _testDone(1, hidden: true), |
| 294 _testStart(2, 'test'), | 302 _group(2), |
| 295 _print(2, "one"), | 303 _testStart(3, 'test'), |
| 296 _print(2, "two"), | 304 _print(3, "one"), |
| 297 _error(2, "first error"), | 305 _print(3, "two"), |
| 298 _print(2, "three"), | 306 _error(3, "first error"), |
| 299 _print(2, "four"), | 307 _print(3, "three"), |
| 300 _error(2, "second error"), | 308 _print(3, "four"), |
| 301 _print(2, "five"), | 309 _error(3, "second error"), |
| 302 _print(2, "six"), | 310 _print(3, "five"), |
| 303 _testDone(2, result: "error"), | 311 _print(3, "six"), |
| 304 _testStart(3, 'wait'), | 312 _testDone(3, result: "error"), |
| 305 _testDone(3), | 313 _testStart(4, 'wait'), |
| 314 _testDone(4), |
| 306 _done(success: false) | 315 _done(success: false) |
| 307 ]); | 316 ]); |
| 308 }); | 317 }); |
| 309 }); | 318 }); |
| 310 | 319 |
| 311 group("skip:", () { | 320 group("skip:", () { |
| 312 test("reports skipped tests", () { | 321 test("reports skipped tests", () { |
| 313 _expectReport(""" | 322 _expectReport(""" |
| 314 test('skip 1', () {}, skip: true); | 323 test('skip 1', () {}, skip: true); |
| 315 test('skip 2', () {}, skip: true); | 324 test('skip 2', () {}, skip: true); |
| 316 test('skip 3', () {}, skip: true); | 325 test('skip 3', () {}, skip: true); |
| 317 """, [ | 326 """, [ |
| 318 _start, | 327 _start, |
| 319 _testStart(0, "loading test.dart", groupIDs: []), | 328 _suite(0), |
| 320 _testDone(0, hidden: true), | 329 _testStart(1, "loading test.dart", groupIDs: []), |
| 321 _group(1), | 330 _testDone(1, hidden: true), |
| 322 _testStart(2, "skip 1", skip: true), | 331 _group(2), |
| 323 _testDone(2), | 332 _testStart(3, "skip 1", skip: true), |
| 324 _testStart(3, "skip 2", skip: true), | |
| 325 _testDone(3), | 333 _testDone(3), |
| 326 _testStart(4, "skip 3", skip: true), | 334 _testStart(4, "skip 2", skip: true), |
| 327 _testDone(4), | 335 _testDone(4), |
| 336 _testStart(5, "skip 3", skip: true), |
| 337 _testDone(5), |
| 328 _done() | 338 _done() |
| 329 ]); | 339 ]); |
| 330 }); | 340 }); |
| 331 | 341 |
| 332 test("reports skipped groups", () { | 342 test("reports skipped groups", () { |
| 333 _expectReport(""" | 343 _expectReport(""" |
| 334 group('skip', () { | 344 group('skip', () { |
| 335 test('success 1', () {}); | 345 test('success 1', () {}); |
| 336 test('success 2', () {}); | 346 test('success 2', () {}); |
| 337 test('success 3', () {}); | 347 test('success 3', () {}); |
| 338 }, skip: true); | 348 }, skip: true); |
| 339 """, [ | 349 """, [ |
| 340 _start, | 350 _start, |
| 341 _testStart(0, "loading test.dart", groupIDs: []), | 351 _suite(0), |
| 342 _testDone(0, hidden: true), | 352 _testStart(1, "loading test.dart", groupIDs: []), |
| 343 _group(1), | 353 _testDone(1, hidden: true), |
| 344 _group(2, name: "skip", parentID: 1, skip: true), | 354 _group(2), |
| 345 _testStart(3, "skip", groupIDs: [1, 2], skip: true), | 355 _group(3, name: "skip", parentID: 2, skip: true), |
| 346 _testDone(3), | 356 _testStart(4, "skip", groupIDs: [2, 3], skip: true), |
| 357 _testDone(4), |
| 347 _done() | 358 _done() |
| 348 ]); | 359 ]); |
| 349 }); | 360 }); |
| 350 | 361 |
| 351 test("reports the skip reason if available", () { | 362 test("reports the skip reason if available", () { |
| 352 _expectReport(""" | 363 _expectReport(""" |
| 353 test('skip 1', () {}, skip: 'some reason'); | 364 test('skip 1', () {}, skip: 'some reason'); |
| 354 test('skip 2', () {}, skip: 'or another'); | 365 test('skip 2', () {}, skip: 'or another'); |
| 355 """, [ | 366 """, [ |
| 356 _start, | 367 _start, |
| 357 _testStart(0, "loading test.dart", groupIDs: []), | 368 _suite(0), |
| 358 _testDone(0, hidden: true), | 369 _testStart(1, "loading test.dart", groupIDs: []), |
| 359 _group(1), | 370 _testDone(1, hidden: true), |
| 360 _testStart(2, "skip 1", skip: "some reason"), | 371 _group(2), |
| 361 _testDone(2), | 372 _testStart(3, "skip 1", skip: "some reason"), |
| 362 _testStart(3, "skip 2", skip: "or another"), | |
| 363 _testDone(3), | 373 _testDone(3), |
| 374 _testStart(4, "skip 2", skip: "or another"), |
| 375 _testDone(4), |
| 364 _done() | 376 _done() |
| 365 ]); | 377 ]); |
| 366 }); | 378 }); |
| 367 }); | 379 }); |
| 368 } | 380 } |
| 369 | 381 |
| 370 /// Asserts that the tests defined by [tests] produce the JSON events in | 382 /// Asserts that the tests defined by [tests] produce the JSON events in |
| 371 /// [expected]. | 383 /// [expected]. |
| 372 void _expectReport(String tests, List<Map> expected) { | 384 void _expectReport(String tests, List<Map> expected) { |
| 373 var dart = """ | 385 var dart = """ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 397 // Remove excess trailing whitespace. | 409 // Remove excess trailing whitespace. |
| 398 for (var i = 0; i < stdoutLines.length; i++) { | 410 for (var i = 0; i < stdoutLines.length; i++) { |
| 399 var event = JSON.decode(stdoutLines[i]); | 411 var event = JSON.decode(stdoutLines[i]); |
| 400 expect(event.remove("time"), new isInstanceOf<int>()); | 412 expect(event.remove("time"), new isInstanceOf<int>()); |
| 401 event.remove("stackTrace"); | 413 event.remove("stackTrace"); |
| 402 expect(event, equals(expected[i])); | 414 expect(event, equals(expected[i])); |
| 403 } | 415 } |
| 404 }); | 416 }); |
| 405 } | 417 } |
| 406 | 418 |
| 419 /// Returns the event emitted by the JSON reporter indicating that a suite has |
| 420 /// begun running. |
| 421 /// |
| 422 /// The [platform] defaults to `"vm"`, the [path] defaults to `"test.dart"`. |
| 423 Map _suite(int id, {String platform, String path}) { |
| 424 return { |
| 425 "type": "suite", |
| 426 "suite": { |
| 427 "id": id, |
| 428 "platform": platform ?? "vm", |
| 429 "path": path ?? "test.dart" |
| 430 } |
| 431 }; |
| 432 } |
| 433 |
| 407 /// Returns the event emitted by the JSON reporter indicating that a group has | 434 /// Returns the event emitted by the JSON reporter indicating that a group has |
| 408 /// begun running. | 435 /// begun running. |
| 409 /// | 436 /// |
| 410 /// If [skip] is `true`, the group is expected to be marked as skipped without a | 437 /// If [skip] is `true`, the group is expected to be marked as skipped without a |
| 411 /// reason. If it's a [String], the group is expected to be marked as skipped | 438 /// reason. If it's a [String], the group is expected to be marked as skipped |
| 412 /// with that reason. | 439 /// with that reason. |
| 413 Map _group(int id, {String name, int parentID, skip}) { | 440 Map _group(int id, {String name, int suiteID, int parentID, skip}) { |
| 414 return { | 441 return { |
| 415 "type": "group", | 442 "type": "group", |
| 416 "group": { | 443 "group": { |
| 417 "id": id, | 444 "id": id, |
| 418 "name": name, | 445 "name": name, |
| 446 "suiteID": suiteID ?? 0, |
| 419 "parentID": parentID, | 447 "parentID": parentID, |
| 420 "metadata": _metadata(skip: skip) | 448 "metadata": _metadata(skip: skip) |
| 421 } | 449 } |
| 422 }; | 450 }; |
| 423 } | 451 } |
| 424 | 452 |
| 425 /// Returns the event emitted by the JSON reporter indicating that a test has | 453 /// Returns the event emitted by the JSON reporter indicating that a test has |
| 426 /// begun running. | 454 /// begun running. |
| 427 /// | 455 /// |
| 428 /// If [parentIDs] is passed, it's the IDs of groups containing this test. If | 456 /// If [parentIDs] is passed, it's the IDs of groups containing this test. If |
| 429 /// [skip] is `true`, the test is expected to be marked as skipped without a | 457 /// [skip] is `true`, the test is expected to be marked as skipped without a |
| 430 /// reason. If it's a [String], the test is expected to be marked as skipped | 458 /// reason. If it's a [String], the test is expected to be marked as skipped |
| 431 /// with that reason. | 459 /// with that reason. |
| 432 Map _testStart(int id, String name, {Iterable<int> groupIDs, skip}) { | 460 Map _testStart(int id, String name, {int suiteID, Iterable<int> groupIDs, |
| 461 skip}) { |
| 433 return { | 462 return { |
| 434 "type": "testStart", | 463 "type": "testStart", |
| 435 "test": { | 464 "test": { |
| 436 "id": id, | 465 "id": id, |
| 437 "name": name, | 466 "name": name, |
| 438 "groupIDs": groupIDs ?? [1], | 467 "suiteID": suiteID ?? 0, |
| 468 "groupIDs": groupIDs ?? [2], |
| 439 "metadata": _metadata(skip: skip) | 469 "metadata": _metadata(skip: skip) |
| 440 } | 470 } |
| 441 }; | 471 }; |
| 442 } | 472 } |
| 443 | 473 |
| 444 /// Returns the event emitted by the JSON reporter indicating that a test | 474 /// Returns the event emitted by the JSON reporter indicating that a test |
| 445 /// printed [message]. | 475 /// printed [message]. |
| 446 Map _print(int id, String message) { | 476 Map _print(int id, String message) { |
| 447 return { | 477 return { |
| 448 "type": "print", | 478 "type": "print", |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 /// Returns the serialized metadata corresponding to [skip]. | 515 /// Returns the serialized metadata corresponding to [skip]. |
| 486 Map _metadata({skip}) { | 516 Map _metadata({skip}) { |
| 487 if (skip == true) { | 517 if (skip == true) { |
| 488 return {"skip": true, "skipReason": null}; | 518 return {"skip": true, "skipReason": null}; |
| 489 } else if (skip is String) { | 519 } else if (skip is String) { |
| 490 return {"skip": true, "skipReason": skip}; | 520 return {"skip": true, "skipReason": skip}; |
| 491 } else { | 521 } else { |
| 492 return {"skip": false, "skipReason": null}; | 522 return {"skip": false, "skipReason": null}; |
| 493 } | 523 } |
| 494 } | 524 } |
| OLD | NEW |