| 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:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:path/path.dart' as p; | 9 import 'package:path/path.dart' as p; |
| 10 import 'package:test/src/util/io.dart'; | 10 import 'package:test/src/util/io.dart'; |
| 11 import 'package:test/test.dart'; | 11 import 'package:test/test.dart'; |
| 12 | 12 |
| 13 import '../../io.dart'; | 13 import '../../io.dart'; |
| 14 | 14 |
| 15 String _sandbox; | 15 String _sandbox; |
| 16 | 16 |
| 17 final _success = """ | 17 final _success = """ |
| 18 import 'dart:async'; | |
| 19 | |
| 20 import 'package:test/test.dart'; | 18 import 'package:test/test.dart'; |
| 21 | 19 |
| 22 void main() { | 20 void main() { |
| 23 test("success", () {}); | 21 test("success", () {}); |
| 24 } | 22 } |
| 25 """; | 23 """; |
| 26 | 24 |
| 27 final _failure = """ | 25 final _failure = """ |
| 28 import 'dart:async'; | |
| 29 | |
| 30 import 'package:test/test.dart'; | 26 import 'package:test/test.dart'; |
| 31 | 27 |
| 32 void main() { | 28 void main() { |
| 33 test("failure", () => throw new TestFailure("oh no")); | 29 test("failure", () => throw new TestFailure("oh no")); |
| 34 } | 30 } |
| 35 """; | 31 """; |
| 36 | 32 |
| 37 void main() { | 33 void main() { |
| 38 setUp(() { | 34 setUp(() { |
| 39 _sandbox = createTempDir(); | 35 _sandbox = createTempDir(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 | 117 |
| 122 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" | 118 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" |
| 123 <html> | 119 <html> |
| 124 <head> | 120 <head> |
| 125 <link rel="x-dart-test" href="test.dart"> | 121 <link rel="x-dart-test" href="test.dart"> |
| 126 </head> | 122 </head> |
| 127 </html> | 123 </html> |
| 128 """); | 124 """); |
| 129 | 125 |
| 130 var relativePath = p.relative(testPath, from: _sandbox); | 126 var relativePath = p.relative(testPath, from: _sandbox); |
| 131 var result = _runTest(["-p", "dartium", "test.dart"]); | 127 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 132 expect(result.stdout, allOf([ | 128 expect(result.stdout, allOf([ |
| 133 contains('-1: load error'), | 129 contains('-1: load error'), |
| 134 contains( | 130 contains( |
| 135 'Failed to load "$relativePath": ' | 131 'Failed to load "$relativePath": ' |
| 136 '"${p.withoutExtension(relativePath)}.html" must contain ' | 132 '"${p.withoutExtension(relativePath)}.html" must contain ' |
| 137 '<script src="packages/test/dart.js"></script>.\n') | 133 '<script src="packages/test/dart.js"></script>.\n') |
| 138 ])); | 134 ])); |
| 139 expect(result.exitCode, equals(1)); | 135 expect(result.exitCode, equals(1)); |
| 140 }); | 136 }); |
| 141 | 137 |
| 142 test("a custom HTML file has no link", () { | 138 test("a custom HTML file has no link", () { |
| 143 var testPath = p.join(_sandbox, "test.dart"); | 139 var testPath = p.join(_sandbox, "test.dart"); |
| 144 new File(testPath).writeAsStringSync("void main(arg) {}"); | 140 new File(testPath).writeAsStringSync("void main(arg) {}"); |
| 145 | 141 |
| 146 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" | 142 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" |
| 147 <html> | 143 <html> |
| 148 <head> | 144 <head> |
| 149 <script src="packages/test/dart.js"></script> | 145 <script src="packages/test/dart.js"></script> |
| 150 </head> | 146 </head> |
| 151 </html> | 147 </html> |
| 152 """); | 148 """); |
| 153 | 149 |
| 154 var result = _runTest(["-p", "dartium", "test.dart"]); | 150 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 155 expect(result.stdout, allOf([ | 151 expect(result.stdout, allOf([ |
| 156 contains('-1: load error'), | 152 contains('-1: load error'), |
| 157 contains( | 153 contains( |
| 158 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' | 154 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' |
| 159 'Expected exactly 1 <link rel="x-dart-test"> in test.html, ' | 155 'Expected exactly 1 <link rel="x-dart-test"> in test.html, ' |
| 160 'found 0.\n') | 156 'found 0.\n') |
| 161 ])); | 157 ])); |
| 162 expect(result.exitCode, equals(1)); | 158 expect(result.exitCode, equals(1)); |
| 163 }); | 159 }); |
| 164 | 160 |
| 165 test("a custom HTML file has too many links", () { | 161 test("a custom HTML file has too many links", () { |
| 166 var testPath = p.join(_sandbox, "test.dart"); | 162 var testPath = p.join(_sandbox, "test.dart"); |
| 167 new File(testPath).writeAsStringSync("void main(arg) {}"); | 163 new File(testPath).writeAsStringSync("void main(arg) {}"); |
| 168 | 164 |
| 169 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" | 165 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" |
| 170 <html> | 166 <html> |
| 171 <head> | 167 <head> |
| 172 <link rel='x-dart-test' href='test.dart'> | 168 <link rel='x-dart-test' href='test.dart'> |
| 173 <link rel='x-dart-test' href='test.dart'> | 169 <link rel='x-dart-test' href='test.dart'> |
| 174 <script src="packages/test/dart.js"></script> | 170 <script src="packages/test/dart.js"></script> |
| 175 </head> | 171 </head> |
| 176 </html> | 172 </html> |
| 177 """); | 173 """); |
| 178 | 174 |
| 179 var result = _runTest(["-p", "dartium", "test.dart"]); | 175 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 180 expect(result.stdout, allOf([ | 176 expect(result.stdout, allOf([ |
| 181 contains('-1: load error'), | 177 contains('-1: load error'), |
| 182 contains( | 178 contains( |
| 183 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' | 179 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' |
| 184 'Expected exactly 1 <link rel="x-dart-test"> in test.html, ' | 180 'Expected exactly 1 <link rel="x-dart-test"> in test.html, ' |
| 185 'found 2.\n') | 181 'found 2.\n') |
| 186 ])); | 182 ])); |
| 187 expect(result.exitCode, equals(1)); | 183 expect(result.exitCode, equals(1)); |
| 188 }); | 184 }); |
| 189 | 185 |
| 190 test("a custom HTML file has no href in the link", () { | 186 test("a custom HTML file has no href in the link", () { |
| 191 var testPath = p.join(_sandbox, "test.dart"); | 187 var testPath = p.join(_sandbox, "test.dart"); |
| 192 new File(testPath).writeAsStringSync("void main(arg) {}"); | 188 new File(testPath).writeAsStringSync("void main(arg) {}"); |
| 193 | 189 |
| 194 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" | 190 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" |
| 195 <html> | 191 <html> |
| 196 <head> | 192 <head> |
| 197 <link rel='x-dart-test'> | 193 <link rel='x-dart-test'> |
| 198 <script src="packages/test/dart.js"></script> | 194 <script src="packages/test/dart.js"></script> |
| 199 </head> | 195 </head> |
| 200 </html> | 196 </html> |
| 201 """); | 197 """); |
| 202 | 198 |
| 203 var result = _runTest(["-p", "dartium", "test.dart"]); | 199 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 204 expect(result.stdout, allOf([ | 200 expect(result.stdout, allOf([ |
| 205 contains('-1: load error'), | 201 contains('-1: load error'), |
| 206 contains( | 202 contains( |
| 207 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' | 203 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' |
| 208 'Expected <link rel="x-dart-test"> in test.html to have an ' | 204 'Expected <link rel="x-dart-test"> in test.html to have an ' |
| 209 '"href" attribute.\n') | 205 '"href" attribute.\n') |
| 210 ])); | 206 ])); |
| 211 expect(result.exitCode, equals(1)); | 207 expect(result.exitCode, equals(1)); |
| 212 }); | 208 }); |
| 213 | 209 |
| 214 test("a custom HTML file has an invalid test URL", () { | 210 test("a custom HTML file has an invalid test URL", () { |
| 215 var testPath = p.join(_sandbox, "test.dart"); | 211 var testPath = p.join(_sandbox, "test.dart"); |
| 216 new File(testPath).writeAsStringSync("void main(arg) {}"); | 212 new File(testPath).writeAsStringSync("void main(arg) {}"); |
| 217 | 213 |
| 218 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" | 214 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" |
| 219 <html> | 215 <html> |
| 220 <head> | 216 <head> |
| 221 <link rel='x-dart-test' href='wrong.dart'> | 217 <link rel='x-dart-test' href='wrong.dart'> |
| 222 <script src="packages/test/dart.js"></script> | 218 <script src="packages/test/dart.js"></script> |
| 223 </head> | 219 </head> |
| 224 </html> | 220 </html> |
| 225 """); | 221 """); |
| 226 | 222 |
| 227 var result = _runTest(["-p", "dartium", "test.dart"]); | 223 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 228 expect(result.stdout, allOf([ | 224 expect(result.stdout, allOf([ |
| 229 contains('-1: load error'), | 225 contains('-1: load error'), |
| 230 contains( | 226 contains( |
| 231 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' | 227 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' |
| 232 'Failed to load script at ') | 228 'Failed to load script at ') |
| 233 ])); | 229 ])); |
| 234 expect(result.exitCode, equals(1)); | 230 expect(result.exitCode, equals(1)); |
| 235 }); | 231 }); |
| 236 | 232 |
| 237 // TODO(nweiz): test what happens when a test file is unreadable once issue | 233 // TODO(nweiz): test what happens when a test file is unreadable once issue |
| 238 // 15078 is fixed. | 234 // 15078 is fixed. |
| 239 }); | 235 }); |
| 240 | 236 |
| 241 group("runs successful tests", () { | 237 group("runs successful tests", () { |
| 242 test("on Chrome", () { | 238 test("on Chrome", () { |
| 243 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 239 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 244 var result = _runTest(["-p", "chrome", "test.dart"]); | 240 var result = _runTest(["-p", "chrome", "test.dart"]); |
| 245 expect(result.exitCode, equals(0)); | 241 expect(result.exitCode, equals(0)); |
| 246 }); | 242 }); |
| 247 | 243 |
| 248 test("on PhantomJS", () { | |
| 249 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | |
| 250 var result = _runTest(["-p", "phantomjs", "test.dart"]); | |
| 251 expect(result.exitCode, equals(0)); | |
| 252 }); | |
| 253 | |
| 254 test("on Firefox", () { | |
| 255 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | |
| 256 var result = _runTest(["-p", "firefox", "test.dart"]); | |
| 257 expect(result.exitCode, equals(0)); | |
| 258 }); | |
| 259 | |
| 260 test("on Safari", () { | 244 test("on Safari", () { |
| 261 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 245 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 262 var result = _runTest(["-p", "safari", "test.dart"]); | 246 var result = _runTest(["-p", "safari", "test.dart"]); |
| 263 expect(result.exitCode, equals(0)); | 247 expect(result.exitCode, equals(0)); |
| 264 }, testOn: "mac-os"); | 248 }, testOn: "mac-os"); |
| 265 | 249 |
| 266 test("on Dartium", () { | |
| 267 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | |
| 268 var result = _runTest(["-p", "dartium", "test.dart"]); | |
| 269 expect(result.stdout, isNot(contains("Compiling"))); | |
| 270 expect(result.exitCode, equals(0)); | |
| 271 }); | |
| 272 | |
| 273 test("on content shell", () { | 250 test("on content shell", () { |
| 274 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 251 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 275 var result = _runTest(["-p", "content-shell", "test.dart"]); | 252 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 276 expect(result.stdout, isNot(contains("Compiling"))); | 253 expect(result.stdout, isNot(contains("Compiling"))); |
| 277 expect(result.exitCode, equals(0)); | 254 expect(result.exitCode, equals(0)); |
| 278 }); | 255 }); |
| 279 | 256 |
| 280 test("on multiple browsers", () { | |
| 281 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | |
| 282 var result = _runTest(["-p", "firefox", "-p", "chrome", "test.dart"]); | |
| 283 expect("Compiling".allMatches(result.stdout), hasLength(1)); | |
| 284 expect(result.exitCode, equals(0)); | |
| 285 }); | |
| 286 | |
| 287 test("on a JS and non-JS browser", () { | 257 test("on a JS and non-JS browser", () { |
| 288 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 258 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 289 var result = _runTest( | 259 var result = _runTest( |
| 290 ["-p", "content-shell", "-p", "chrome", "test.dart"]); | 260 ["-p", "content-shell", "-p", "chrome", "test.dart"]); |
| 291 expect("Compiling".allMatches(result.stdout), hasLength(1)); | 261 expect("Compiling".allMatches(result.stdout), hasLength(1)); |
| 292 expect(result.exitCode, equals(0)); | 262 expect(result.exitCode, equals(0)); |
| 293 }); | 263 }); |
| 294 | 264 |
| 295 test("on the browser and the VM", () { | 265 test("on a browser and the VM", () { |
| 296 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 266 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 297 var result = _runTest(["-p", "chrome", "-p", "vm", "test.dart"]); | 267 var result = _runTest(["-p", "content-shell", "-p", "vm", "test.dart"]); |
| 298 expect(result.exitCode, equals(0)); | 268 expect(result.exitCode, equals(0)); |
| 299 }); | 269 }); |
| 300 | 270 |
| 301 // Regression test; this broke in 0.12.0-beta.9. | 271 // Regression test; this broke in 0.12.0-beta.9. |
| 302 test("on a file in a subdirectory", () { | 272 test("on a file in a subdirectory", () { |
| 303 new Directory(p.join(_sandbox, "dir")).createSync(); | 273 new Directory(p.join(_sandbox, "dir")).createSync(); |
| 304 new File(p.join(_sandbox, "dir", "test.dart")) | 274 new File(p.join(_sandbox, "dir", "test.dart")) |
| 305 .writeAsStringSync(_success); | 275 .writeAsStringSync(_success); |
| 306 var result = _runTest(["-p", "chrome", "dir/test.dart"]); | 276 var result = _runTest(["-p", "chrome", "dir/test.dart"]); |
| 307 expect(result.exitCode, equals(0)); | 277 expect(result.exitCode, equals(0)); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 }); | 336 }); |
| 367 }); | 337 }); |
| 368 | 338 |
| 369 group("runs failing tests", () { | 339 group("runs failing tests", () { |
| 370 test("on Chrome", () { | 340 test("on Chrome", () { |
| 371 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); | 341 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); |
| 372 var result = _runTest(["-p", "chrome", "test.dart"]); | 342 var result = _runTest(["-p", "chrome", "test.dart"]); |
| 373 expect(result.exitCode, equals(1)); | 343 expect(result.exitCode, equals(1)); |
| 374 }); | 344 }); |
| 375 | 345 |
| 376 test("on PhantomJS", () { | |
| 377 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); | |
| 378 var result = _runTest(["-p", "phantomjs", "test.dart"]); | |
| 379 expect(result.exitCode, equals(1)); | |
| 380 }); | |
| 381 | |
| 382 test("on Firefox", () { | |
| 383 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); | |
| 384 var result = _runTest(["-p", "firefox", "test.dart"]); | |
| 385 expect(result.exitCode, equals(1)); | |
| 386 }); | |
| 387 | |
| 388 test("on Safari", () { | 346 test("on Safari", () { |
| 389 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); | 347 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); |
| 390 var result = _runTest(["-p", "safari", "test.dart"]); | 348 var result = _runTest(["-p", "safari", "test.dart"]); |
| 391 expect(result.exitCode, equals(1)); | 349 expect(result.exitCode, equals(1)); |
| 392 }, testOn: "mac-os"); | 350 }, testOn: "mac-os"); |
| 393 | 351 |
| 394 test("on Dartium", () { | |
| 395 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); | |
| 396 var result = _runTest(["-p", "dartium", "test.dart"]); | |
| 397 expect(result.exitCode, equals(1)); | |
| 398 }); | |
| 399 | |
| 400 test("on content-shell", () { | 352 test("on content-shell", () { |
| 401 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); | 353 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); |
| 402 var result = _runTest(["-p", "content-shell", "test.dart"]); | 354 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 403 expect(result.exitCode, equals(1)); | 355 expect(result.exitCode, equals(1)); |
| 404 }); | 356 }); |
| 405 | 357 |
| 406 test("that fail only on the browser", () { | 358 test("that fail only on the browser", () { |
| 407 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 359 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
| 408 import 'dart:async'; | 360 import 'dart:async'; |
| 409 | 361 |
| 410 import 'package:path/path.dart' as p; | 362 import 'package:path/path.dart' as p; |
| 411 import 'package:test/test.dart'; | 363 import 'package:test/test.dart'; |
| 412 | 364 |
| 413 void main() { | 365 void main() { |
| 414 test("test", () { | 366 test("test", () { |
| 415 if (p.style == p.Style.url) throw new TestFailure("oh no"); | 367 if (p.style == p.Style.url) throw new TestFailure("oh no"); |
| 416 }); | 368 }); |
| 417 } | 369 } |
| 418 """); | 370 """); |
| 419 var result = _runTest(["-p", "chrome", "-p", "vm", "test.dart"]); | 371 var result = _runTest(["-p", "content-shell", "-p", "vm", "test.dart"]); |
| 420 expect(result.exitCode, equals(1)); | 372 expect(result.exitCode, equals(1)); |
| 421 }); | 373 }); |
| 422 | 374 |
| 423 test("that fail only on the VM", () { | 375 test("that fail only on the VM", () { |
| 424 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 376 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
| 425 import 'dart:async'; | 377 import 'dart:async'; |
| 426 | 378 |
| 427 import 'package:path/path.dart' as p; | 379 import 'package:path/path.dart' as p; |
| 428 import 'package:test/test.dart'; | 380 import 'package:test/test.dart'; |
| 429 | 381 |
| 430 void main() { | 382 void main() { |
| 431 test("test", () { | 383 test("test", () { |
| 432 if (p.style != p.Style.url) throw new TestFailure("oh no"); | 384 if (p.style != p.Style.url) throw new TestFailure("oh no"); |
| 433 }); | 385 }); |
| 434 } | 386 } |
| 435 """); | 387 """); |
| 436 var result = _runTest(["-p", "chrome", "-p", "vm", "test.dart"]); | 388 var result = _runTest(["-p", "content-shell", "-p", "vm", "test.dart"]); |
| 437 expect(result.exitCode, equals(1)); | 389 expect(result.exitCode, equals(1)); |
| 438 }); | 390 }); |
| 439 | 391 |
| 440 | 392 |
| 441 group("with a custom HTML file", () { | 393 group("with a custom HTML file", () { |
| 442 setUp(() { | 394 setUp(() { |
| 443 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 395 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
| 444 import 'dart:html'; | 396 import 'dart:html'; |
| 445 | 397 |
| 446 import 'package:test/test.dart'; | 398 import 'package:test/test.dart'; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 import 'package:test/test.dart'; | 436 import 'package:test/test.dart'; |
| 485 | 437 |
| 486 void main() { | 438 void main() { |
| 487 test("test", () { | 439 test("test", () { |
| 488 print("Hello,"); | 440 print("Hello,"); |
| 489 return new Future(() => print("world!")); | 441 return new Future(() => print("world!")); |
| 490 }); | 442 }); |
| 491 } | 443 } |
| 492 """); | 444 """); |
| 493 | 445 |
| 494 var result = _runTest(["-p", "chrome", "test.dart"]); | 446 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 495 expect(result.stdout, contains("Hello,\nworld!\n")); | 447 expect(result.stdout, contains("Hello,\nworld!\n")); |
| 496 expect(result.exitCode, equals(0)); | 448 expect(result.exitCode, equals(0)); |
| 497 }); | 449 }); |
| 498 | 450 |
| 499 test("respects top-level @Timeout declarations", () { | 451 test("respects top-level @Timeout declarations", () { |
| 500 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 452 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 501 @Timeout(const Duration(seconds: 0)) | 453 @Timeout(const Duration(seconds: 0)) |
| 502 | 454 |
| 503 import 'dart:async'; | 455 import 'dart:async'; |
| 504 | 456 |
| 505 import 'package:test/test.dart'; | 457 import 'package:test/test.dart'; |
| 506 | 458 |
| 507 void main() { | 459 void main() { |
| 508 test("timeout", () {}); | 460 test("timeout", () {}); |
| 509 } | 461 } |
| 510 '''); | 462 '''); |
| 511 | 463 |
| 512 var result = _runTest(["-p", "chrome", "test.dart"]); | 464 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 513 expect(result.stdout, contains("Test timed out after 0 seconds.")); | 465 expect(result.stdout, contains("Test timed out after 0 seconds.")); |
| 514 expect(result.stdout, contains("-1: Some tests failed.")); | 466 expect(result.stdout, contains("-1: Some tests failed.")); |
| 515 }); | 467 }); |
| 516 | 468 |
| 517 group("with onPlatform", () { | 469 group("with onPlatform", () { |
| 518 test("respects matching Skips", () { | 470 test("respects matching Skips", () { |
| 519 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 471 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 520 import 'dart:async'; | 472 import 'dart:async'; |
| 521 | 473 |
| 522 import 'package:test/test.dart'; | 474 import 'package:test/test.dart'; |
| 523 | 475 |
| 524 void main() { | 476 void main() { |
| 525 test("fail", () => throw 'oh no', onPlatform: {"chrome": new Skip()}); | 477 test("fail", () => throw 'oh no', onPlatform: {"browser": new Skip()}); |
| 526 } | 478 } |
| 527 '''); | 479 '''); |
| 528 | 480 |
| 529 var result = _runTest(["-p", "chrome", "test.dart"]); | 481 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 530 expect(result.stdout, contains("+0 ~1: All tests skipped.")); | 482 expect(result.stdout, contains("+0 ~1: All tests skipped.")); |
| 531 }); | 483 }); |
| 532 | 484 |
| 533 test("ignores non-matching Skips", () { | 485 test("ignores non-matching Skips", () { |
| 534 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 486 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 535 import 'dart:async'; | 487 import 'dart:async'; |
| 536 | 488 |
| 537 import 'package:test/test.dart'; | 489 import 'package:test/test.dart'; |
| 538 | 490 |
| 539 void main() { | 491 void main() { |
| 540 test("success", () {}, onPlatform: {"vm": new Skip()}); | 492 test("success", () {}, onPlatform: {"vm": new Skip()}); |
| 541 } | 493 } |
| 542 '''); | 494 '''); |
| 543 | 495 |
| 544 var result = _runTest(["-p", "chrome", "test.dart"]); | 496 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 545 expect(result.stdout, contains("+1: All tests passed!")); | 497 expect(result.stdout, contains("+1: All tests passed!")); |
| 546 }); | 498 }); |
| 547 | 499 |
| 548 test("respects matching Timeouts", () { | 500 test("respects matching Timeouts", () { |
| 549 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 501 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 550 import 'dart:async'; | 502 import 'dart:async'; |
| 551 | 503 |
| 552 import 'package:test/test.dart'; | 504 import 'package:test/test.dart'; |
| 553 | 505 |
| 554 void main() { | 506 void main() { |
| 555 test("fail", () => throw 'oh no', onPlatform: { | 507 test("fail", () => throw 'oh no', onPlatform: { |
| 556 "chrome": new Timeout(new Duration(seconds: 0)) | 508 "browser": new Timeout(new Duration(seconds: 0)) |
| 557 }); | 509 }); |
| 558 } | 510 } |
| 559 '''); | 511 '''); |
| 560 | 512 |
| 561 var result = _runTest(["-p", "chrome", "test.dart"]); | 513 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 562 expect(result.stdout, contains("Test timed out after 0 seconds.")); | 514 expect(result.stdout, contains("Test timed out after 0 seconds.")); |
| 563 expect(result.stdout, contains("-1: Some tests failed.")); | 515 expect(result.stdout, contains("-1: Some tests failed.")); |
| 564 }); | 516 }); |
| 565 | 517 |
| 566 test("ignores non-matching Timeouts", () { | 518 test("ignores non-matching Timeouts", () { |
| 567 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 519 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 568 import 'dart:async'; | 520 import 'dart:async'; |
| 569 | 521 |
| 570 import 'package:test/test.dart'; | 522 import 'package:test/test.dart'; |
| 571 | 523 |
| 572 void main() { | 524 void main() { |
| 573 test("success", () {}, onPlatform: { | 525 test("success", () {}, onPlatform: { |
| 574 "vm": new Timeout(new Duration(seconds: 0)) | 526 "vm": new Timeout(new Duration(seconds: 0)) |
| 575 }); | 527 }); |
| 576 } | 528 } |
| 577 '''); | 529 '''); |
| 578 | 530 |
| 579 var result = _runTest(["-p", "chrome", "test.dart"]); | 531 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 580 expect(result.stdout, contains("+1: All tests passed!")); | 532 expect(result.stdout, contains("+1: All tests passed!")); |
| 581 }); | 533 }); |
| 582 | 534 |
| 583 test("applies matching platforms in order", () { | 535 test("applies matching platforms in order", () { |
| 584 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 536 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 585 import 'dart:async'; | 537 import 'dart:async'; |
| 586 | 538 |
| 587 import 'package:test/test.dart'; | 539 import 'package:test/test.dart'; |
| 588 | 540 |
| 589 void main() { | 541 void main() { |
| 590 test("success", () {}, onPlatform: { | 542 test("success", () {}, onPlatform: { |
| 591 "chrome": new Skip("first"), | 543 "browser": new Skip("first"), |
| 592 "chrome || windows": new Skip("second"), | 544 "browser || windows": new Skip("second"), |
| 593 "chrome || linux": new Skip("third"), | 545 "browser || linux": new Skip("third"), |
| 594 "chrome || mac-os": new Skip("fourth"), | 546 "browser || mac-os": new Skip("fourth"), |
| 595 "chrome || android": new Skip("fifth") | 547 "browser || android": new Skip("fifth") |
| 596 }); | 548 }); |
| 597 } | 549 } |
| 598 '''); | 550 '''); |
| 599 | 551 |
| 600 var result = _runTest(["-p", "chrome", "test.dart"]); | 552 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 601 expect(result.stdout, contains("Skip: fifth")); | 553 expect(result.stdout, contains("Skip: fifth")); |
| 602 expect(result.stdout, isNot(anyOf([ | 554 expect(result.stdout, isNot(anyOf([ |
| 603 contains("Skip: first"), | 555 contains("Skip: first"), |
| 604 contains("Skip: second"), | 556 contains("Skip: second"), |
| 605 contains("Skip: third"), | 557 contains("Skip: third"), |
| 606 contains("Skip: fourth") | 558 contains("Skip: fourth") |
| 607 ]))); | 559 ]))); |
| 608 }); | 560 }); |
| 609 }); | 561 }); |
| 610 | 562 |
| 611 group("with an @OnPlatform annotation", () { | 563 group("with an @OnPlatform annotation", () { |
| 612 test("respects matching Skips", () { | 564 test("respects matching Skips", () { |
| 613 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 565 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 614 @OnPlatform(const {"chrome": const Skip()}) | 566 @OnPlatform(const {"browser": const Skip()}) |
| 615 | 567 |
| 616 import 'dart:async'; | 568 import 'dart:async'; |
| 617 | 569 |
| 618 import 'package:test/test.dart'; | 570 import 'package:test/test.dart'; |
| 619 | 571 |
| 620 void main() { | 572 void main() { |
| 621 test("fail", () => throw 'oh no'); | 573 test("fail", () => throw 'oh no'); |
| 622 } | 574 } |
| 623 '''); | 575 '''); |
| 624 | 576 |
| 625 var result = _runTest(["-p", "chrome", "test.dart"]); | 577 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 626 expect(result.stdout, contains("+0 ~1: All tests skipped.")); | 578 expect(result.stdout, contains("+0 ~1: All tests skipped.")); |
| 627 }); | 579 }); |
| 628 | 580 |
| 629 test("ignores non-matching Skips", () { | 581 test("ignores non-matching Skips", () { |
| 630 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 582 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 631 @OnPlatform(const {"vm": const Skip()}) | 583 @OnPlatform(const {"vm": const Skip()}) |
| 632 | 584 |
| 633 import 'dart:async'; | 585 import 'dart:async'; |
| 634 | 586 |
| 635 import 'package:test/test.dart'; | 587 import 'package:test/test.dart'; |
| 636 | 588 |
| 637 void main() { | 589 void main() { |
| 638 test("success", () {}); | 590 test("success", () {}); |
| 639 } | 591 } |
| 640 '''); | 592 '''); |
| 641 | 593 |
| 642 var result = _runTest(["-p", "chrome", "test.dart"]); | 594 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 643 expect(result.stdout, contains("+1: All tests passed!")); | 595 expect(result.stdout, contains("+1: All tests passed!")); |
| 644 }); | 596 }); |
| 645 | 597 |
| 646 test("respects matching Timeouts", () { | 598 test("respects matching Timeouts", () { |
| 647 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 599 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 648 @OnPlatform(const { | 600 @OnPlatform(const { |
| 649 "chrome": const Timeout(const Duration(seconds: 0)) | 601 "browser": const Timeout(const Duration(seconds: 0)) |
| 650 }) | 602 }) |
| 651 | 603 |
| 652 import 'dart:async'; | 604 import 'dart:async'; |
| 653 | 605 |
| 654 import 'package:test/test.dart'; | 606 import 'package:test/test.dart'; |
| 655 | 607 |
| 656 void main() { | 608 void main() { |
| 657 test("fail", () => throw 'oh no'); | 609 test("fail", () => throw 'oh no'); |
| 658 } | 610 } |
| 659 '''); | 611 '''); |
| 660 | 612 |
| 661 var result = _runTest(["-p", "chrome", "test.dart"]); | 613 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 662 expect(result.stdout, contains("Test timed out after 0 seconds.")); | 614 expect(result.stdout, contains("Test timed out after 0 seconds.")); |
| 663 expect(result.stdout, contains("-1: Some tests failed.")); | 615 expect(result.stdout, contains("-1: Some tests failed.")); |
| 664 }); | 616 }); |
| 665 | 617 |
| 666 test("ignores non-matching Timeouts", () { | 618 test("ignores non-matching Timeouts", () { |
| 667 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 619 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 668 @OnPlatform(const { | 620 @OnPlatform(const { |
| 669 "vm": const Timeout(const Duration(seconds: 0)) | 621 "vm": const Timeout(const Duration(seconds: 0)) |
| 670 }) | 622 }) |
| 671 | 623 |
| 672 import 'dart:async'; | 624 import 'dart:async'; |
| 673 | 625 |
| 674 import 'package:test/test.dart'; | 626 import 'package:test/test.dart'; |
| 675 | 627 |
| 676 void main() { | 628 void main() { |
| 677 test("success", () {}); | 629 test("success", () {}); |
| 678 } | 630 } |
| 679 '''); | 631 '''); |
| 680 | 632 |
| 681 var result = _runTest(["-p", "chrome", "test.dart"]); | 633 var result = _runTest(["-p", "content-shell", "test.dart"]); |
| 682 expect(result.stdout, contains("+1: All tests passed!")); | 634 expect(result.stdout, contains("+1: All tests passed!")); |
| 683 }); | 635 }); |
| 684 }); | 636 }); |
| 685 } | 637 } |
| 686 | 638 |
| 687 ProcessResult _runTest(List<String> args) => | 639 ProcessResult _runTest(List<String> args) => |
| 688 runTest(args, workingDirectory: _sandbox); | 640 runTest(args, workingDirectory: _sandbox); |
| OLD | NEW |