OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 @TestOn("vm") |
| 6 |
| 7 import 'dart:convert'; |
| 8 |
| 9 import 'package:scheduled_test/descriptor.dart' as d; |
| 10 import 'package:scheduled_test/scheduled_stream.dart'; |
| 11 import 'package:scheduled_test/scheduled_test.dart'; |
| 12 |
| 13 import 'package:test/src/util/exit_codes.dart' as exit_codes; |
| 14 import 'package:test/src/util/io.dart'; |
| 15 |
| 16 import '../../io.dart'; |
| 17 |
| 18 void main() { |
| 19 useSandbox(); |
| 20 |
| 21 group("presets", () { |
| 22 test("don't do anything by default", () { |
| 23 d.file("dart_test.yaml", JSON.encode({ |
| 24 "presets": { |
| 25 "foo": {"timeout": "0s"} |
| 26 } |
| 27 })).create(); |
| 28 |
| 29 d.file("test.dart", """ |
| 30 import 'dart:async'; |
| 31 |
| 32 import 'package:test/test.dart'; |
| 33 |
| 34 void main() { |
| 35 test("test", () => new Future.delayed(Duration.ZERO)); |
| 36 } |
| 37 """).create(); |
| 38 |
| 39 runTest(["test.dart"]).shouldExit(0); |
| 40 }); |
| 41 |
| 42 test("can be selected on the command line", () { |
| 43 d.file("dart_test.yaml", JSON.encode({ |
| 44 "presets": { |
| 45 "foo": {"timeout": "0s"} |
| 46 } |
| 47 })).create(); |
| 48 |
| 49 d.file("test.dart", """ |
| 50 import 'dart:async'; |
| 51 |
| 52 import 'package:test/test.dart'; |
| 53 |
| 54 void main() { |
| 55 test("test", () => new Future.delayed(Duration.ZERO)); |
| 56 } |
| 57 """).create(); |
| 58 |
| 59 var test = runTest(["-P", "foo", "test.dart"]); |
| 60 test.stdout.expect(containsInOrder([ |
| 61 "-1: test", |
| 62 "-1: Some tests failed." |
| 63 ])); |
| 64 test.shouldExit(1); |
| 65 }); |
| 66 |
| 67 test("multiple presets can be selected", () { |
| 68 d.file("dart_test.yaml", JSON.encode({ |
| 69 "presets": { |
| 70 "foo": {"timeout": "0s"}, |
| 71 "bar": {"paths": ["test.dart"]} |
| 72 } |
| 73 })).create(); |
| 74 |
| 75 d.file("test.dart", """ |
| 76 import 'dart:async'; |
| 77 |
| 78 import 'package:test/test.dart'; |
| 79 |
| 80 void main() { |
| 81 test("test", () => new Future.delayed(Duration.ZERO)); |
| 82 } |
| 83 """).create(); |
| 84 |
| 85 var test = runTest(["-P", "foo,bar"]); |
| 86 test.stdout.expect(containsInOrder([ |
| 87 "-1: test", |
| 88 "-1: Some tests failed." |
| 89 ])); |
| 90 test.shouldExit(1); |
| 91 }); |
| 92 |
| 93 test("the latter preset takes precedence", () { |
| 94 d.file("dart_test.yaml", JSON.encode({ |
| 95 "presets": { |
| 96 "foo": {"timeout": "0s"}, |
| 97 "bar": {"timeout": "30s"} |
| 98 } |
| 99 })).create(); |
| 100 |
| 101 d.file("test.dart", """ |
| 102 import 'dart:async'; |
| 103 |
| 104 import 'package:test/test.dart'; |
| 105 |
| 106 void main() { |
| 107 test("test", () => new Future.delayed(Duration.ZERO)); |
| 108 } |
| 109 """).create(); |
| 110 |
| 111 runTest(["-P", "foo,bar", "test.dart"]).shouldExit(0); |
| 112 |
| 113 var test = runTest(["-P", "bar,foo", "test.dart"]); |
| 114 test.stdout.expect(containsInOrder([ |
| 115 "-1: test", |
| 116 "-1: Some tests failed." |
| 117 ])); |
| 118 test.shouldExit(1); |
| 119 }); |
| 120 |
| 121 test("a preset takes precedence over the base configuration", () { |
| 122 d.file("dart_test.yaml", JSON.encode({ |
| 123 "presets": { |
| 124 "foo": {"timeout": "0s"} |
| 125 }, |
| 126 "timeout": "30s" |
| 127 })).create(); |
| 128 |
| 129 d.file("test.dart", """ |
| 130 import 'dart:async'; |
| 131 |
| 132 import 'package:test/test.dart'; |
| 133 |
| 134 void main() { |
| 135 test("test", () => new Future.delayed(Duration.ZERO)); |
| 136 } |
| 137 """).create(); |
| 138 |
| 139 var test = runTest(["-P", "foo", "test.dart"]); |
| 140 test.stdout.expect(containsInOrder([ |
| 141 "-1: test", |
| 142 "-1: Some tests failed." |
| 143 ])); |
| 144 test.shouldExit(1); |
| 145 |
| 146 d.file("dart_test.yaml", JSON.encode({ |
| 147 "presets": { |
| 148 "foo": {"timeout": "30s"} |
| 149 }, |
| 150 "timeout": "00s" |
| 151 })).create(); |
| 152 |
| 153 runTest(["-P", "foo", "test.dart"]).shouldExit(0); |
| 154 }); |
| 155 |
| 156 test("a nested preset is activated", () { |
| 157 d.file("dart_test.yaml", JSON.encode({ |
| 158 "tags": { |
| 159 "foo": { |
| 160 "presets": { |
| 161 "bar": {"timeout": "0s"} |
| 162 }, |
| 163 }, |
| 164 } |
| 165 })).create(); |
| 166 |
| 167 d.file("test.dart", """ |
| 168 import 'dart:async'; |
| 169 |
| 170 import 'package:test/test.dart'; |
| 171 |
| 172 void main() { |
| 173 test("test 1", () => new Future.delayed(Duration.ZERO), tags: "foo"); |
| 174 test("test 2", () => new Future.delayed(Duration.ZERO)); |
| 175 } |
| 176 """).create(); |
| 177 |
| 178 var test = runTest(["-P", "bar", "test.dart"]); |
| 179 test.stdout.expect(containsInOrder([ |
| 180 "-1: test", |
| 181 "+1 -1: Some tests failed." |
| 182 ])); |
| 183 test.shouldExit(1); |
| 184 |
| 185 d.file("dart_test.yaml", JSON.encode({ |
| 186 "presets": { |
| 187 "foo": {"timeout": "30s"} |
| 188 }, |
| 189 "timeout": "00s" |
| 190 })).create(); |
| 191 |
| 192 runTest(["-P", "foo", "test.dart"]).shouldExit(0); |
| 193 }); |
| 194 }); |
| 195 |
| 196 group("add_presets", () { |
| 197 test("selects a preset", () { |
| 198 d.file("dart_test.yaml", JSON.encode({ |
| 199 "presets": { |
| 200 "foo": {"timeout": "0s"} |
| 201 }, |
| 202 "add_presets": ["foo"] |
| 203 })).create(); |
| 204 |
| 205 d.file("test.dart", """ |
| 206 import 'dart:async'; |
| 207 |
| 208 import 'package:test/test.dart'; |
| 209 |
| 210 void main() { |
| 211 test("test", () => new Future.delayed(Duration.ZERO)); |
| 212 } |
| 213 """).create(); |
| 214 |
| 215 var test = runTest(["test.dart"]); |
| 216 test.stdout.expect(containsInOrder([ |
| 217 "-1: test", |
| 218 "-1: Some tests failed." |
| 219 ])); |
| 220 test.shouldExit(1); |
| 221 }); |
| 222 |
| 223 test("applies presets in selection order", () { |
| 224 d.file("dart_test.yaml", JSON.encode({ |
| 225 "presets": { |
| 226 "foo": {"timeout": "0s"}, |
| 227 "bar": {"timeout": "30s"} |
| 228 }, |
| 229 "add_presets": ["foo", "bar"] |
| 230 })).create(); |
| 231 |
| 232 d.file("test.dart", """ |
| 233 import 'dart:async'; |
| 234 |
| 235 import 'package:test/test.dart'; |
| 236 |
| 237 void main() { |
| 238 test("test", () => new Future.delayed(Duration.ZERO)); |
| 239 } |
| 240 """).create(); |
| 241 |
| 242 runTest(["test.dart"]).shouldExit(0); |
| 243 |
| 244 d.file("dart_test.yaml", JSON.encode({ |
| 245 "presets": { |
| 246 "foo": {"timeout": "0s"}, |
| 247 "bar": {"timeout": "30s"} |
| 248 }, |
| 249 "add_presets": ["bar", "foo"] |
| 250 })).create(); |
| 251 |
| 252 var test = runTest(["test.dart"]); |
| 253 test.stdout.expect(containsInOrder([ |
| 254 "-1: test", |
| 255 "-1: Some tests failed." |
| 256 ])); |
| 257 test.shouldExit(1); |
| 258 }); |
| 259 |
| 260 test("allows preset inheritance via add_presets", () { |
| 261 d.file("dart_test.yaml", JSON.encode({ |
| 262 "presets": { |
| 263 "foo": {"add_presets": ["bar"]}, |
| 264 "bar": {"timeout": "0s"} |
| 265 } |
| 266 })).create(); |
| 267 |
| 268 d.file("test.dart", """ |
| 269 import 'dart:async'; |
| 270 |
| 271 import 'package:test/test.dart'; |
| 272 |
| 273 void main() { |
| 274 test("test", () => new Future.delayed(Duration.ZERO)); |
| 275 } |
| 276 """).create(); |
| 277 |
| 278 var test = runTest(["-P", "foo", "test.dart"]); |
| 279 test.stdout.expect(containsInOrder([ |
| 280 "-1: test", |
| 281 "-1: Some tests failed." |
| 282 ])); |
| 283 test.shouldExit(1); |
| 284 }); |
| 285 |
| 286 test("allows circular preset inheritance via add_presets", () { |
| 287 d.file("dart_test.yaml", JSON.encode({ |
| 288 "presets": { |
| 289 "foo": {"add_presets": ["bar"]}, |
| 290 "bar": {"add_presets": ["foo"]} |
| 291 } |
| 292 })).create(); |
| 293 |
| 294 d.file("test.dart", """ |
| 295 import 'dart:async'; |
| 296 |
| 297 import 'package:test/test.dart'; |
| 298 |
| 299 void main() { |
| 300 test("test", () {}); |
| 301 } |
| 302 """).create(); |
| 303 |
| 304 runTest(["-P", "foo", "test.dart"]).shouldExit(0); |
| 305 }); |
| 306 }); |
| 307 |
| 308 group("errors", () { |
| 309 group("presets", () { |
| 310 test("rejects an invalid preset type", () { |
| 311 d.file("dart_test.yaml", '{"presets": {12: null}}').create(); |
| 312 |
| 313 var test = runTest([]); |
| 314 test.stderr.expect(containsInOrder([ |
| 315 "presets key must be a string", |
| 316 "^^" |
| 317 ])); |
| 318 test.shouldExit(exit_codes.data); |
| 319 }); |
| 320 |
| 321 test("rejects an invalid preset name", () { |
| 322 d.file("dart_test.yaml", JSON.encode({ |
| 323 "presets": {"foo bar": null} |
| 324 })).create(); |
| 325 |
| 326 var test = runTest([]); |
| 327 test.stderr.expect(containsInOrder([ |
| 328 "presets key must be an (optionally hyphenated) Dart identifier.", |
| 329 "^^^^^^^^^" |
| 330 ])); |
| 331 test.shouldExit(exit_codes.data); |
| 332 }); |
| 333 |
| 334 test("rejects an invalid preset map", () { |
| 335 d.file("dart_test.yaml", JSON.encode({ |
| 336 "presets": 12 |
| 337 })).create(); |
| 338 |
| 339 var test = runTest([]); |
| 340 test.stderr.expect(containsInOrder([ |
| 341 "presets must be a map", |
| 342 "^^" |
| 343 ])); |
| 344 test.shouldExit(exit_codes.data); |
| 345 }); |
| 346 |
| 347 test("rejects an invalid preset configuration", () { |
| 348 d.file("dart_test.yaml", JSON.encode({ |
| 349 "presets": {"foo": {"timeout": "12p"}} |
| 350 })).create(); |
| 351 |
| 352 var test = runTest([]); |
| 353 test.stderr.expect(containsInOrder([ |
| 354 "Invalid timeout: expected unit", |
| 355 "^^^^" |
| 356 ])); |
| 357 test.shouldExit(exit_codes.data); |
| 358 }); |
| 359 |
| 360 test("rejects runner configuration in a non-runner context", () { |
| 361 d.file("dart_test.yaml", JSON.encode({ |
| 362 "tags": { |
| 363 "foo": { |
| 364 "presets": {"bar": {"filename": "*_blorp.dart"}} |
| 365 } |
| 366 } |
| 367 })).create(); |
| 368 |
| 369 var test = runTest([]); |
| 370 test.stderr.expect(containsInOrder([ |
| 371 "filename isn't supported here.", |
| 372 "^^^^^^^^^^" |
| 373 ])); |
| 374 test.shouldExit(exit_codes.data); |
| 375 }); |
| 376 |
| 377 test("fails if an undefined preset is passed", () { |
| 378 var test = runTest(["-P", "foo"]); |
| 379 test.stderr.expect(consumeThrough(contains('Undefined preset "foo".'))); |
| 380 test.shouldExit(exit_codes.usage); |
| 381 }); |
| 382 |
| 383 test("fails if an undefined preset is added", () { |
| 384 d.file("dart_test.yaml", JSON.encode({ |
| 385 "add_presets": ["foo", "bar"] |
| 386 })).create(); |
| 387 |
| 388 var test = runTest([]); |
| 389 test.stderr.expect(consumeThrough(contains( |
| 390 'Undefined presets "foo" and "bar".'))); |
| 391 test.shouldExit(exit_codes.usage); |
| 392 }); |
| 393 |
| 394 test("fails if an undefined preset is added in a nested context", () { |
| 395 d.file("dart_test.yaml", JSON.encode({ |
| 396 "on_os": { |
| 397 currentOS.identifier: { |
| 398 "add_presets": ["bar"] |
| 399 } |
| 400 } |
| 401 })).create(); |
| 402 |
| 403 var test = runTest([]); |
| 404 test.stderr.expect(consumeThrough(contains('Undefined preset "bar".'))); |
| 405 test.shouldExit(exit_codes.usage); |
| 406 }); |
| 407 }); |
| 408 |
| 409 group("add_presets", () { |
| 410 test("rejects an invalid list type", () { |
| 411 d.file("dart_test.yaml", JSON.encode({ |
| 412 "add_presets": "foo" |
| 413 })).create(); |
| 414 |
| 415 var test = runTest(["test.dart"]); |
| 416 test.stderr.expect(containsInOrder([ |
| 417 "add_presets must be a list", |
| 418 "^^^^" |
| 419 ])); |
| 420 test.shouldExit(exit_codes.data); |
| 421 }); |
| 422 |
| 423 test("rejects an invalid preset type", () { |
| 424 d.file("dart_test.yaml", JSON.encode({ |
| 425 "add_presets": [12] |
| 426 })).create(); |
| 427 |
| 428 var test = runTest(["test.dart"]); |
| 429 test.stderr.expect(containsInOrder([ |
| 430 "Preset name must be a string", |
| 431 "^^" |
| 432 ])); |
| 433 test.shouldExit(exit_codes.data); |
| 434 }); |
| 435 |
| 436 test("rejects an invalid preset name", () { |
| 437 d.file("dart_test.yaml", JSON.encode({ |
| 438 "add_presets": ["foo bar"] |
| 439 })).create(); |
| 440 |
| 441 var test = runTest(["test.dart"]); |
| 442 test.stderr.expect(containsInOrder([ |
| 443 "Preset name must be an (optionally hyphenated) Dart identifier.", |
| 444 "^^^^^^^^^" |
| 445 ])); |
| 446 test.shouldExit(exit_codes.data); |
| 447 }); |
| 448 }); |
| 449 }); |
| 450 } |
OLD | NEW |