| 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 import 'dart:math' as math; | 8 import 'dart:math' as math; |
| 9 | 9 |
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 void main() { | 65 void main() { |
| 66 setUp(() { | 66 setUp(() { |
| 67 _sandbox = createTempDir(); | 67 _sandbox = createTempDir(); |
| 68 }); | 68 }); |
| 69 | 69 |
| 70 tearDown(() { | 70 tearDown(() { |
| 71 new Directory(_sandbox).deleteSync(recursive: true); | 71 new Directory(_sandbox).deleteSync(recursive: true); |
| 72 }); | 72 }); |
| 73 | 73 |
| 74 test("prints help information", () { | 74 test("prints help information", () { |
| 75 var result = _runUnittest(["--help"]); | 75 var result = _runTest(["--help"]); |
| 76 expect(result.stdout, equals(""" | 76 expect(result.stdout, equals(""" |
| 77 Runs tests in this package. | 77 Runs tests in this package. |
| 78 | 78 |
| 79 $_usage""")); | 79 $_usage""")); |
| 80 expect(result.exitCode, equals(exit_codes.success)); | 80 expect(result.exitCode, equals(exit_codes.success)); |
| 81 }); | 81 }); |
| 82 | 82 |
| 83 group("fails gracefully if", () { | 83 group("fails gracefully if", () { |
| 84 test("an invalid option is passed", () { | 84 test("an invalid option is passed", () { |
| 85 var result = _runUnittest(["--asdf"]); | 85 var result = _runTest(["--asdf"]); |
| 86 expect(result.stderr, equals(""" | 86 expect(result.stderr, equals(""" |
| 87 Could not find an option named "asdf". | 87 Could not find an option named "asdf". |
| 88 | 88 |
| 89 $_usage""")); | 89 $_usage""")); |
| 90 expect(result.exitCode, equals(exit_codes.usage)); | 90 expect(result.exitCode, equals(exit_codes.usage)); |
| 91 }); | 91 }); |
| 92 | 92 |
| 93 test("a non-existent file is passed", () { | 93 test("a non-existent file is passed", () { |
| 94 var result = _runUnittest(["file"]); | 94 var result = _runTest(["file"]); |
| 95 expect(result.stdout, allOf([ | 95 expect(result.stdout, allOf([ |
| 96 contains('-1: load error'), | 96 contains('-1: load error'), |
| 97 contains('Failed to load "file": Does not exist.') | 97 contains('Failed to load "file": Does not exist.') |
| 98 ])); | 98 ])); |
| 99 expect(result.exitCode, equals(1)); | 99 expect(result.exitCode, equals(1)); |
| 100 }); | 100 }); |
| 101 | 101 |
| 102 test("the default directory doesn't exist", () { | 102 test("the default directory doesn't exist", () { |
| 103 var result = _runUnittest([]); | 103 var result = _runTest([]); |
| 104 expect(result.stderr, equals(""" | 104 expect(result.stderr, equals(""" |
| 105 No test files were passed and the default "test/" directory doesn't exist. | 105 No test files were passed and the default "test/" directory doesn't exist. |
| 106 | 106 |
| 107 $_usage""")); | 107 $_usage""")); |
| 108 expect(result.exitCode, equals(exit_codes.data)); | 108 expect(result.exitCode, equals(exit_codes.data)); |
| 109 }); | 109 }); |
| 110 | 110 |
| 111 test("a test file fails to load", () { | 111 test("a test file fails to load", () { |
| 112 var testPath = p.join(_sandbox, "test.dart"); | 112 var testPath = p.join(_sandbox, "test.dart"); |
| 113 new File(testPath).writeAsStringSync("invalid Dart file"); | 113 new File(testPath).writeAsStringSync("invalid Dart file"); |
| 114 var result = _runUnittest(["test.dart"]); | 114 var result = _runTest(["test.dart"]); |
| 115 | 115 |
| 116 expect(result.stdout, allOf([ | 116 expect(result.stdout, allOf([ |
| 117 contains('-1: load error'), | 117 contains('-1: load error'), |
| 118 contains( | 118 contains( |
| 119 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' | 119 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' |
| 120 " line 1 pos 1: unexpected token 'invalid'\n" | 120 " line 1 pos 1: unexpected token 'invalid'\n" |
| 121 " invalid Dart file\n" | 121 " invalid Dart file\n" |
| 122 " ^\n") | 122 " ^\n") |
| 123 ])); | 123 ])); |
| 124 expect(result.exitCode, equals(1)); | 124 expect(result.exitCode, equals(1)); |
| 125 }); | 125 }); |
| 126 | 126 |
| 127 // This is slightly different from the above test because it's an error | 127 // This is slightly different from the above test because it's an error |
| 128 // that's caught first by the analyzer when it's used to parse the file. | 128 // that's caught first by the analyzer when it's used to parse the file. |
| 129 test("a test file fails to parse", () { | 129 test("a test file fails to parse", () { |
| 130 var testPath = p.join(_sandbox, "test.dart"); | 130 var testPath = p.join(_sandbox, "test.dart"); |
| 131 new File(testPath).writeAsStringSync("@TestOn)"); | 131 new File(testPath).writeAsStringSync("@TestOn)"); |
| 132 var result = _runUnittest(["test.dart"]); | 132 var result = _runTest(["test.dart"]); |
| 133 | 133 |
| 134 expect(result.stdout, allOf([ | 134 expect(result.stdout, allOf([ |
| 135 contains('-1: load error'), | 135 contains('-1: load error'), |
| 136 contains( | 136 contains( |
| 137 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' | 137 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' |
| 138 " line 1 pos 8: unexpected token ')'\n" | 138 " line 1 pos 8: unexpected token ')'\n" |
| 139 " @TestOn)\n" | 139 " @TestOn)\n" |
| 140 " ^\n") | 140 " ^\n") |
| 141 ])); | 141 ])); |
| 142 expect(result.exitCode, equals(1)); | 142 expect(result.exitCode, equals(1)); |
| 143 }); | 143 }); |
| 144 | 144 |
| 145 test("an annotation's structure is invalid", () { | 145 test("an annotation's structure is invalid", () { |
| 146 var testPath = p.join(_sandbox, "test.dart"); | 146 var testPath = p.join(_sandbox, "test.dart"); |
| 147 new File(testPath).writeAsStringSync("@TestOn()\nlibrary foo;"); | 147 new File(testPath).writeAsStringSync("@TestOn()\nlibrary foo;"); |
| 148 var result = _runUnittest(["test.dart"]); | 148 var result = _runTest(["test.dart"]); |
| 149 | 149 |
| 150 expect(result.stdout, allOf([ | 150 expect(result.stdout, allOf([ |
| 151 contains('-1: load error'), | 151 contains('-1: load error'), |
| 152 contains( | 152 contains( |
| 153 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' | 153 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' |
| 154 " Error on line 1, column 8: TestOn takes 1 argument.\n" | 154 " Error on line 1, column 8: TestOn takes 1 argument.\n" |
| 155 " @TestOn()\n" | 155 " @TestOn()\n" |
| 156 " ^^\n") | 156 " ^^\n") |
| 157 ])); | 157 ])); |
| 158 expect(result.exitCode, equals(1)); | 158 expect(result.exitCode, equals(1)); |
| 159 }); | 159 }); |
| 160 | 160 |
| 161 test("an annotation's contents are invalid", () { | 161 test("an annotation's contents are invalid", () { |
| 162 var testPath = p.join(_sandbox, "test.dart"); | 162 var testPath = p.join(_sandbox, "test.dart"); |
| 163 new File(testPath).writeAsStringSync("@TestOn('zim')\nlibrary foo;"); | 163 new File(testPath).writeAsStringSync("@TestOn('zim')\nlibrary foo;"); |
| 164 var result = _runUnittest(["test.dart"]); | 164 var result = _runTest(["test.dart"]); |
| 165 | 165 |
| 166 expect(result.stdout, allOf([ | 166 expect(result.stdout, allOf([ |
| 167 contains('-1: load error'), | 167 contains('-1: load error'), |
| 168 contains( | 168 contains( |
| 169 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' | 169 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' |
| 170 " Error on line 1, column 10: Undefined variable.\n" | 170 " Error on line 1, column 10: Undefined variable.\n" |
| 171 " @TestOn('zim')\n" | 171 " @TestOn('zim')\n" |
| 172 " ^^^\n") | 172 " ^^^\n") |
| 173 ])); | 173 ])); |
| 174 expect(result.exitCode, equals(1)); | 174 expect(result.exitCode, equals(1)); |
| 175 }); | 175 }); |
| 176 | 176 |
| 177 test("a test file throws", () { | 177 test("a test file throws", () { |
| 178 var testPath = p.join(_sandbox, "test.dart"); | 178 var testPath = p.join(_sandbox, "test.dart"); |
| 179 new File(testPath).writeAsStringSync("void main() => throw 'oh no';"); | 179 new File(testPath).writeAsStringSync("void main() => throw 'oh no';"); |
| 180 | 180 |
| 181 var result = _runUnittest(["test.dart"]); | 181 var result = _runTest(["test.dart"]); |
| 182 expect(result.stdout, allOf([ | 182 expect(result.stdout, allOf([ |
| 183 contains('-1: load error'), | 183 contains('-1: load error'), |
| 184 contains( | 184 contains( |
| 185 'Failed to load "${p.relative(testPath, from: _sandbox)}": oh no') | 185 'Failed to load "${p.relative(testPath, from: _sandbox)}": oh no') |
| 186 ])); | 186 ])); |
| 187 expect(result.exitCode, equals(1)); | 187 expect(result.exitCode, equals(1)); |
| 188 }); | 188 }); |
| 189 | 189 |
| 190 test("a test file doesn't have a main defined", () { | 190 test("a test file doesn't have a main defined", () { |
| 191 var testPath = p.join(_sandbox, "test.dart"); | 191 var testPath = p.join(_sandbox, "test.dart"); |
| 192 new File(testPath).writeAsStringSync("void foo() {}"); | 192 new File(testPath).writeAsStringSync("void foo() {}"); |
| 193 | 193 |
| 194 var result = _runUnittest(["test.dart"]); | 194 var result = _runTest(["test.dart"]); |
| 195 expect(result.stdout, allOf([ | 195 expect(result.stdout, allOf([ |
| 196 contains('-1: load error'), | 196 contains('-1: load error'), |
| 197 contains( | 197 contains( |
| 198 'Failed to load "${p.relative(testPath, from: _sandbox)}": No ' | 198 'Failed to load "${p.relative(testPath, from: _sandbox)}": No ' |
| 199 'top-level main() function defined.') | 199 'top-level main() function defined.') |
| 200 ])); | 200 ])); |
| 201 expect(result.exitCode, equals(1)); | 201 expect(result.exitCode, equals(1)); |
| 202 }); | 202 }); |
| 203 | 203 |
| 204 test("a test file has a non-function main", () { | 204 test("a test file has a non-function main", () { |
| 205 var testPath = p.join(_sandbox, "test.dart"); | 205 var testPath = p.join(_sandbox, "test.dart"); |
| 206 new File(testPath).writeAsStringSync("int main;"); | 206 new File(testPath).writeAsStringSync("int main;"); |
| 207 | 207 |
| 208 var result = _runUnittest(["test.dart"]); | 208 var result = _runTest(["test.dart"]); |
| 209 expect(result.stdout, allOf([ | 209 expect(result.stdout, allOf([ |
| 210 contains('-1: load error'), | 210 contains('-1: load error'), |
| 211 contains( | 211 contains( |
| 212 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' | 212 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' |
| 213 'Top-level main getter is not a function.') | 213 'Top-level main getter is not a function.') |
| 214 ])); | 214 ])); |
| 215 expect(result.exitCode, equals(1)); | 215 expect(result.exitCode, equals(1)); |
| 216 }); | 216 }); |
| 217 | 217 |
| 218 test("a test file has a main with arguments", () { | 218 test("a test file has a main with arguments", () { |
| 219 var testPath = p.join(_sandbox, "test.dart"); | 219 var testPath = p.join(_sandbox, "test.dart"); |
| 220 new File(testPath).writeAsStringSync("void main(arg) {}"); | 220 new File(testPath).writeAsStringSync("void main(arg) {}"); |
| 221 | 221 |
| 222 var result = _runUnittest(["test.dart"]); | 222 var result = _runTest(["test.dart"]); |
| 223 expect(result.stdout, allOf([ | 223 expect(result.stdout, allOf([ |
| 224 contains('-1: load error'), | 224 contains('-1: load error'), |
| 225 contains( | 225 contains( |
| 226 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' | 226 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' |
| 227 'Top-level main() function takes arguments.') | 227 'Top-level main() function takes arguments.') |
| 228 ])); | 228 ])); |
| 229 expect(result.exitCode, equals(1)); | 229 expect(result.exitCode, equals(1)); |
| 230 }); | 230 }); |
| 231 | 231 |
| 232 test("multiple load errors occur", () { | 232 test("multiple load errors occur", () { |
| 233 var testPath = p.join(_sandbox, "test.dart"); | 233 var testPath = p.join(_sandbox, "test.dart"); |
| 234 new File(testPath).writeAsStringSync("invalid Dart file"); | 234 new File(testPath).writeAsStringSync("invalid Dart file"); |
| 235 var result = _runUnittest(["test.dart", "nonexistent.dart"]); | 235 var result = _runTest(["test.dart", "nonexistent.dart"]); |
| 236 | 236 |
| 237 expect(result.stdout, allOf([ | 237 expect(result.stdout, allOf([ |
| 238 contains('test.dart: load error'), | 238 contains('test.dart: load error'), |
| 239 contains( | 239 contains( |
| 240 ' Failed to load "test.dart":\n' | 240 ' Failed to load "test.dart":\n' |
| 241 " line 1 pos 1: unexpected token 'invalid'\n" | 241 " line 1 pos 1: unexpected token 'invalid'\n" |
| 242 " invalid Dart file\n" | 242 " invalid Dart file\n" |
| 243 " ^\n"), | 243 " ^\n"), |
| 244 contains('nonexistent.dart: load error'), | 244 contains('nonexistent.dart: load error'), |
| 245 contains('Failed to load "nonexistent.dart": Does not exist.') | 245 contains('Failed to load "nonexistent.dart": Does not exist.') |
| 246 ])); | 246 ])); |
| 247 }); | 247 }); |
| 248 | 248 |
| 249 // TODO(nweiz): test what happens when a test file is unreadable once issue | 249 // TODO(nweiz): test what happens when a test file is unreadable once issue |
| 250 // 15078 is fixed. | 250 // 15078 is fixed. |
| 251 }); | 251 }); |
| 252 | 252 |
| 253 group("runs successful tests", () { | 253 group("runs successful tests", () { |
| 254 test("defined in a single file", () { | 254 test("defined in a single file", () { |
| 255 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 255 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 256 var result = _runUnittest(["test.dart"]); | 256 var result = _runTest(["test.dart"]); |
| 257 expect(result.exitCode, equals(0)); | 257 expect(result.exitCode, equals(0)); |
| 258 }); | 258 }); |
| 259 | 259 |
| 260 test("defined in a directory", () { | 260 test("defined in a directory", () { |
| 261 for (var i = 0; i < 3; i++) { | 261 for (var i = 0; i < 3; i++) { |
| 262 new File(p.join(_sandbox, "${i}_test.dart")) | 262 new File(p.join(_sandbox, "${i}_test.dart")) |
| 263 .writeAsStringSync(_success); | 263 .writeAsStringSync(_success); |
| 264 } | 264 } |
| 265 | 265 |
| 266 var result = _runUnittest(["."]); | 266 var result = _runTest(["."]); |
| 267 expect(result.exitCode, equals(0)); | 267 expect(result.exitCode, equals(0)); |
| 268 }); | 268 }); |
| 269 | 269 |
| 270 test("defaulting to the test directory", () { | 270 test("defaulting to the test directory", () { |
| 271 new Directory(p.join(_sandbox, "test")).createSync(); | 271 new Directory(p.join(_sandbox, "test")).createSync(); |
| 272 for (var i = 0; i < 3; i++) { | 272 for (var i = 0; i < 3; i++) { |
| 273 new File(p.join(_sandbox, "test", "${i}_test.dart")) | 273 new File(p.join(_sandbox, "test", "${i}_test.dart")) |
| 274 .writeAsStringSync(_success); | 274 .writeAsStringSync(_success); |
| 275 } | 275 } |
| 276 | 276 |
| 277 var result = _runUnittest([]); | 277 var result = _runTest([]); |
| 278 expect(result.exitCode, equals(0)); | 278 expect(result.exitCode, equals(0)); |
| 279 }); | 279 }); |
| 280 | 280 |
| 281 test("directly", () { | 281 test("directly", () { |
| 282 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 282 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 283 var result = _runDart([ | 283 var result = _runDart([ |
| 284 "--package-root=${p.join(packageDir, 'packages')}", | 284 "--package-root=${p.join(packageDir, 'packages')}", |
| 285 "test.dart" | 285 "test.dart" |
| 286 ]); | 286 ]); |
| 287 expect(result.stdout, contains("All tests passed!")); | 287 expect(result.stdout, contains("All tests passed!")); |
| 288 expect(result.exitCode, equals(0)); | 288 expect(result.exitCode, equals(0)); |
| 289 }); | 289 }); |
| 290 | 290 |
| 291 // Regression test; this broke in 0.12.0-beta.9. | 291 // Regression test; this broke in 0.12.0-beta.9. |
| 292 test("on a file in a subdirectory", () { | 292 test("on a file in a subdirectory", () { |
| 293 new Directory(p.join(_sandbox, "dir")).createSync(); | 293 new Directory(p.join(_sandbox, "dir")).createSync(); |
| 294 new File(p.join(_sandbox, "dir", "test.dart")) | 294 new File(p.join(_sandbox, "dir", "test.dart")) |
| 295 .writeAsStringSync(_success); | 295 .writeAsStringSync(_success); |
| 296 var result = _runUnittest(["dir/test.dart"]); | 296 var result = _runTest(["dir/test.dart"]); |
| 297 expect(result.exitCode, equals(0)); | 297 expect(result.exitCode, equals(0)); |
| 298 }); | 298 }); |
| 299 }); | 299 }); |
| 300 | 300 |
| 301 group("runs failing tests", () { | 301 group("runs failing tests", () { |
| 302 test("defined in a single file", () { | 302 test("defined in a single file", () { |
| 303 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); | 303 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); |
| 304 var result = _runUnittest(["test.dart"]); | 304 var result = _runTest(["test.dart"]); |
| 305 expect(result.exitCode, equals(1)); | 305 expect(result.exitCode, equals(1)); |
| 306 }); | 306 }); |
| 307 | 307 |
| 308 test("defined in a directory", () { | 308 test("defined in a directory", () { |
| 309 for (var i = 0; i < 3; i++) { | 309 for (var i = 0; i < 3; i++) { |
| 310 new File(p.join(_sandbox, "${i}_test.dart")) | 310 new File(p.join(_sandbox, "${i}_test.dart")) |
| 311 .writeAsStringSync(_failure); | 311 .writeAsStringSync(_failure); |
| 312 } | 312 } |
| 313 | 313 |
| 314 var result = _runUnittest(["."]); | 314 var result = _runTest(["."]); |
| 315 expect(result.exitCode, equals(1)); | 315 expect(result.exitCode, equals(1)); |
| 316 }); | 316 }); |
| 317 | 317 |
| 318 test("defaulting to the test directory", () { | 318 test("defaulting to the test directory", () { |
| 319 new Directory(p.join(_sandbox, "test")).createSync(); | 319 new Directory(p.join(_sandbox, "test")).createSync(); |
| 320 for (var i = 0; i < 3; i++) { | 320 for (var i = 0; i < 3; i++) { |
| 321 new File(p.join(_sandbox, "test", "${i}_test.dart")) | 321 new File(p.join(_sandbox, "test", "${i}_test.dart")) |
| 322 .writeAsStringSync(_failure); | 322 .writeAsStringSync(_failure); |
| 323 } | 323 } |
| 324 | 324 |
| 325 var result = _runUnittest([]); | 325 var result = _runTest([]); |
| 326 expect(result.exitCode, equals(1)); | 326 expect(result.exitCode, equals(1)); |
| 327 }); | 327 }); |
| 328 | 328 |
| 329 test("directly", () { | 329 test("directly", () { |
| 330 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); | 330 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); |
| 331 var result = _runDart([ | 331 var result = _runDart([ |
| 332 "--package-root=${p.join(packageDir, 'packages')}", | 332 "--package-root=${p.join(packageDir, 'packages')}", |
| 333 "test.dart" | 333 "test.dart" |
| 334 ]); | 334 ]); |
| 335 expect(result.stdout, contains("Some tests failed.")); | 335 expect(result.stdout, contains("Some tests failed.")); |
| 336 expect(result.exitCode, isNot(equals(0))); | 336 expect(result.exitCode, isNot(equals(0))); |
| 337 }); | 337 }); |
| 338 }); | 338 }); |
| 339 | 339 |
| 340 test("runs tests even when a file fails to load", () { | 340 test("runs tests even when a file fails to load", () { |
| 341 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 341 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 342 var result = _runUnittest(["test.dart", "nonexistent.dart"]); | 342 var result = _runTest(["test.dart", "nonexistent.dart"]); |
| 343 expect(result.stdout, contains("+1 -1: Some tests failed.")); | 343 expect(result.stdout, contains("+1 -1: Some tests failed.")); |
| 344 expect(result.exitCode, equals(1)); | 344 expect(result.exitCode, equals(1)); |
| 345 }); | 345 }); |
| 346 | 346 |
| 347 test("respects top-level @Timeout declarations", () { | 347 test("respects top-level @Timeout declarations", () { |
| 348 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 348 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 349 @Timeout(const Duration(seconds: 0)) | 349 @Timeout(const Duration(seconds: 0)) |
| 350 | 350 |
| 351 import 'dart:async'; | 351 import 'dart:async'; |
| 352 | 352 |
| 353 import 'package:test/test.dart'; | 353 import 'package:test/test.dart'; |
| 354 | 354 |
| 355 void main() { | 355 void main() { |
| 356 test("timeout", () {}); | 356 test("timeout", () {}); |
| 357 } | 357 } |
| 358 '''); | 358 '''); |
| 359 | 359 |
| 360 var result = _runUnittest(["test.dart"]); | 360 var result = _runTest(["test.dart"]); |
| 361 expect(result.stdout, contains("Test timed out after 0 seconds.")); | 361 expect(result.stdout, contains("Test timed out after 0 seconds.")); |
| 362 expect(result.stdout, contains("-1: Some tests failed.")); | 362 expect(result.stdout, contains("-1: Some tests failed.")); |
| 363 }); | 363 }); |
| 364 | 364 |
| 365 test("respects top-level @Skip declarations", () { | 365 test("respects top-level @Skip declarations", () { |
| 366 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 366 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 367 @Skip() | 367 @Skip() |
| 368 | 368 |
| 369 import 'dart:async'; | 369 import 'dart:async'; |
| 370 | 370 |
| 371 import 'package:test/test.dart'; | 371 import 'package:test/test.dart'; |
| 372 | 372 |
| 373 void main() { | 373 void main() { |
| 374 test("fail", () => throw 'oh no'); | 374 test("fail", () => throw 'oh no'); |
| 375 } | 375 } |
| 376 '''); | 376 '''); |
| 377 | 377 |
| 378 var result = _runUnittest(["test.dart"]); | 378 var result = _runTest(["test.dart"]); |
| 379 expect(result.stdout, contains("+0 ~1: All tests skipped.")); | 379 expect(result.stdout, contains("+0 ~1: All tests skipped.")); |
| 380 }); | 380 }); |
| 381 | 381 |
| 382 group("with onPlatform", () { | 382 group("with onPlatform", () { |
| 383 test("respects matching Skips", () { | 383 test("respects matching Skips", () { |
| 384 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 384 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 385 import 'dart:async'; | 385 import 'dart:async'; |
| 386 | 386 |
| 387 import 'package:test/test.dart'; | 387 import 'package:test/test.dart'; |
| 388 | 388 |
| 389 void main() { | 389 void main() { |
| 390 test("fail", () => throw 'oh no', onPlatform: {"vm": new Skip()}); | 390 test("fail", () => throw 'oh no', onPlatform: {"vm": new Skip()}); |
| 391 } | 391 } |
| 392 '''); | 392 '''); |
| 393 | 393 |
| 394 var result = _runUnittest(["test.dart"]); | 394 var result = _runTest(["test.dart"]); |
| 395 expect(result.stdout, contains("+0 ~1: All tests skipped.")); | 395 expect(result.stdout, contains("+0 ~1: All tests skipped.")); |
| 396 }); | 396 }); |
| 397 | 397 |
| 398 test("ignores non-matching Skips", () { | 398 test("ignores non-matching Skips", () { |
| 399 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 399 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 400 import 'dart:async'; | 400 import 'dart:async'; |
| 401 | 401 |
| 402 import 'package:test/test.dart'; | 402 import 'package:test/test.dart'; |
| 403 | 403 |
| 404 void main() { | 404 void main() { |
| 405 test("success", () {}, onPlatform: {"chrome": new Skip()}); | 405 test("success", () {}, onPlatform: {"chrome": new Skip()}); |
| 406 } | 406 } |
| 407 '''); | 407 '''); |
| 408 | 408 |
| 409 var result = _runUnittest(["test.dart"]); | 409 var result = _runTest(["test.dart"]); |
| 410 expect(result.stdout, contains("+1: All tests passed!")); | 410 expect(result.stdout, contains("+1: All tests passed!")); |
| 411 }); | 411 }); |
| 412 | 412 |
| 413 test("respects matching Timeouts", () { | 413 test("respects matching Timeouts", () { |
| 414 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 414 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 415 import 'dart:async'; | 415 import 'dart:async'; |
| 416 | 416 |
| 417 import 'package:test/test.dart'; | 417 import 'package:test/test.dart'; |
| 418 | 418 |
| 419 void main() { | 419 void main() { |
| 420 test("fail", () => throw 'oh no', onPlatform: { | 420 test("fail", () => throw 'oh no', onPlatform: { |
| 421 "vm": new Timeout(new Duration(seconds: 0)) | 421 "vm": new Timeout(new Duration(seconds: 0)) |
| 422 }); | 422 }); |
| 423 } | 423 } |
| 424 '''); | 424 '''); |
| 425 | 425 |
| 426 var result = _runUnittest(["test.dart"]); | 426 var result = _runTest(["test.dart"]); |
| 427 expect(result.stdout, contains("Test timed out after 0 seconds.")); | 427 expect(result.stdout, contains("Test timed out after 0 seconds.")); |
| 428 expect(result.stdout, contains("-1: Some tests failed.")); | 428 expect(result.stdout, contains("-1: Some tests failed.")); |
| 429 }); | 429 }); |
| 430 | 430 |
| 431 test("ignores non-matching Timeouts", () { | 431 test("ignores non-matching Timeouts", () { |
| 432 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 432 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 433 import 'dart:async'; | 433 import 'dart:async'; |
| 434 | 434 |
| 435 import 'package:test/test.dart'; | 435 import 'package:test/test.dart'; |
| 436 | 436 |
| 437 void main() { | 437 void main() { |
| 438 test("success", () {}, onPlatform: { | 438 test("success", () {}, onPlatform: { |
| 439 "chrome": new Timeout(new Duration(seconds: 0)) | 439 "chrome": new Timeout(new Duration(seconds: 0)) |
| 440 }); | 440 }); |
| 441 } | 441 } |
| 442 '''); | 442 '''); |
| 443 | 443 |
| 444 var result = _runUnittest(["test.dart"]); | 444 var result = _runTest(["test.dart"]); |
| 445 expect(result.stdout, contains("+1: All tests passed!")); | 445 expect(result.stdout, contains("+1: All tests passed!")); |
| 446 }); | 446 }); |
| 447 | 447 |
| 448 test("applies matching platforms in order", () { | 448 test("applies matching platforms in order", () { |
| 449 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 449 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 450 import 'dart:async'; | 450 import 'dart:async'; |
| 451 | 451 |
| 452 import 'package:test/test.dart'; | 452 import 'package:test/test.dart'; |
| 453 | 453 |
| 454 void main() { | 454 void main() { |
| 455 test("success", () {}, onPlatform: { | 455 test("success", () {}, onPlatform: { |
| 456 "vm": new Skip("first"), | 456 "vm": new Skip("first"), |
| 457 "vm || windows": new Skip("second"), | 457 "vm || windows": new Skip("second"), |
| 458 "vm || linux": new Skip("third"), | 458 "vm || linux": new Skip("third"), |
| 459 "vm || mac-os": new Skip("fourth"), | 459 "vm || mac-os": new Skip("fourth"), |
| 460 "vm || android": new Skip("fifth") | 460 "vm || android": new Skip("fifth") |
| 461 }); | 461 }); |
| 462 } | 462 } |
| 463 '''); | 463 '''); |
| 464 | 464 |
| 465 var result = _runUnittest(["test.dart"]); | 465 var result = _runTest(["test.dart"]); |
| 466 expect(result.stdout, contains("Skip: fifth")); | 466 expect(result.stdout, contains("Skip: fifth")); |
| 467 expect(result.stdout, isNot(anyOf([ | 467 expect(result.stdout, isNot(anyOf([ |
| 468 contains("Skip: first"), | 468 contains("Skip: first"), |
| 469 contains("Skip: second"), | 469 contains("Skip: second"), |
| 470 contains("Skip: third"), | 470 contains("Skip: third"), |
| 471 contains("Skip: fourth") | 471 contains("Skip: fourth") |
| 472 ]))); | 472 ]))); |
| 473 }); | 473 }); |
| 474 }); | 474 }); |
| 475 | 475 |
| 476 group("with an @OnPlatform annotation", () { | 476 group("with an @OnPlatform annotation", () { |
| 477 test("respects matching Skips", () { | 477 test("respects matching Skips", () { |
| 478 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 478 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 479 @OnPlatform(const {"vm": const Skip()}) | 479 @OnPlatform(const {"vm": const Skip()}) |
| 480 | 480 |
| 481 import 'dart:async'; | 481 import 'dart:async'; |
| 482 | 482 |
| 483 import 'package:test/test.dart'; | 483 import 'package:test/test.dart'; |
| 484 | 484 |
| 485 void main() { | 485 void main() { |
| 486 test("fail", () => throw 'oh no'); | 486 test("fail", () => throw 'oh no'); |
| 487 } | 487 } |
| 488 '''); | 488 '''); |
| 489 | 489 |
| 490 var result = _runUnittest(["test.dart"]); | 490 var result = _runTest(["test.dart"]); |
| 491 expect(result.stdout, contains("+0 ~1: All tests skipped.")); | 491 expect(result.stdout, contains("+0 ~1: All tests skipped.")); |
| 492 }); | 492 }); |
| 493 | 493 |
| 494 test("ignores non-matching Skips", () { | 494 test("ignores non-matching Skips", () { |
| 495 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 495 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 496 @OnPlatform(const {"chrome": const Skip()}) | 496 @OnPlatform(const {"chrome": const Skip()}) |
| 497 | 497 |
| 498 import 'dart:async'; | 498 import 'dart:async'; |
| 499 | 499 |
| 500 import 'package:test/test.dart'; | 500 import 'package:test/test.dart'; |
| 501 | 501 |
| 502 void main() { | 502 void main() { |
| 503 test("success", () {}); | 503 test("success", () {}); |
| 504 } | 504 } |
| 505 '''); | 505 '''); |
| 506 | 506 |
| 507 var result = _runUnittest(["test.dart"]); | 507 var result = _runTest(["test.dart"]); |
| 508 expect(result.stdout, contains("+1: All tests passed!")); | 508 expect(result.stdout, contains("+1: All tests passed!")); |
| 509 }); | 509 }); |
| 510 | 510 |
| 511 test("respects matching Timeouts", () { | 511 test("respects matching Timeouts", () { |
| 512 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 512 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 513 @OnPlatform(const { | 513 @OnPlatform(const { |
| 514 "vm": const Timeout(const Duration(seconds: 0)) | 514 "vm": const Timeout(const Duration(seconds: 0)) |
| 515 }) | 515 }) |
| 516 | 516 |
| 517 import 'dart:async'; | 517 import 'dart:async'; |
| 518 | 518 |
| 519 import 'package:test/test.dart'; | 519 import 'package:test/test.dart'; |
| 520 | 520 |
| 521 void main() { | 521 void main() { |
| 522 test("fail", () => throw 'oh no'); | 522 test("fail", () => throw 'oh no'); |
| 523 } | 523 } |
| 524 '''); | 524 '''); |
| 525 | 525 |
| 526 var result = _runUnittest(["test.dart"]); | 526 var result = _runTest(["test.dart"]); |
| 527 expect(result.stdout, contains("Test timed out after 0 seconds.")); | 527 expect(result.stdout, contains("Test timed out after 0 seconds.")); |
| 528 expect(result.stdout, contains("-1: Some tests failed.")); | 528 expect(result.stdout, contains("-1: Some tests failed.")); |
| 529 }); | 529 }); |
| 530 | 530 |
| 531 test("ignores non-matching Timeouts", () { | 531 test("ignores non-matching Timeouts", () { |
| 532 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' | 532 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(''' |
| 533 @OnPlatform(const { | 533 @OnPlatform(const { |
| 534 "chrome": const Timeout(const Duration(seconds: 0)) | 534 "chrome": const Timeout(const Duration(seconds: 0)) |
| 535 }) | 535 }) |
| 536 | 536 |
| 537 import 'dart:async'; | 537 import 'dart:async'; |
| 538 | 538 |
| 539 import 'package:test/test.dart'; | 539 import 'package:test/test.dart'; |
| 540 | 540 |
| 541 void main() { | 541 void main() { |
| 542 test("success", () {}); | 542 test("success", () {}); |
| 543 } | 543 } |
| 544 '''); | 544 '''); |
| 545 | 545 |
| 546 var result = _runUnittest(["test.dart"]); | 546 var result = _runTest(["test.dart"]); |
| 547 expect(result.stdout, contains("+1: All tests passed!")); | 547 expect(result.stdout, contains("+1: All tests passed!")); |
| 548 }); | 548 }); |
| 549 }); | 549 }); |
| 550 | 550 |
| 551 group("flags:", () { | 551 group("flags:", () { |
| 552 test("with the --color flag, uses colors", () { | 552 test("with the --color flag, uses colors", () { |
| 553 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); | 553 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); |
| 554 var result = _runUnittest(["--color", "test.dart"]); | 554 var result = _runTest(["--color", "test.dart"]); |
| 555 // This is the color code for red. | 555 // This is the color code for red. |
| 556 expect(result.stdout, contains("\u001b[31m")); | 556 expect(result.stdout, contains("\u001b[31m")); |
| 557 }); | 557 }); |
| 558 | 558 |
| 559 group("with the --name flag,", () { | 559 group("with the --name flag,", () { |
| 560 test("selects tests with matching names", () { | 560 test("selects tests with matching names", () { |
| 561 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 561 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
| 562 import 'dart:async'; | 562 import 'dart:async'; |
| 563 | 563 |
| 564 import 'package:test/test.dart'; | 564 import 'package:test/test.dart'; |
| 565 | 565 |
| 566 void main() { | 566 void main() { |
| 567 test("selected 1", () {}); | 567 test("selected 1", () {}); |
| 568 test("nope", () => throw new TestFailure("oh no")); | 568 test("nope", () => throw new TestFailure("oh no")); |
| 569 test("selected 2", () {}); | 569 test("selected 2", () {}); |
| 570 } | 570 } |
| 571 """); | 571 """); |
| 572 | 572 |
| 573 var result = _runUnittest(["--name", "selected", "test.dart"]); | 573 var result = _runTest(["--name", "selected", "test.dart"]); |
| 574 expect(result.stdout, contains("+2: All tests passed!")); | 574 expect(result.stdout, contains("+2: All tests passed!")); |
| 575 expect(result.exitCode, equals(0)); | 575 expect(result.exitCode, equals(0)); |
| 576 }); | 576 }); |
| 577 | 577 |
| 578 test("supports RegExp syntax", () { | 578 test("supports RegExp syntax", () { |
| 579 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 579 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
| 580 import 'dart:async'; | 580 import 'dart:async'; |
| 581 | 581 |
| 582 import 'package:test/test.dart'; | 582 import 'package:test/test.dart'; |
| 583 | 583 |
| 584 void main() { | 584 void main() { |
| 585 test("test 1", () {}); | 585 test("test 1", () {}); |
| 586 test("test 2", () => throw new TestFailure("oh no")); | 586 test("test 2", () => throw new TestFailure("oh no")); |
| 587 test("test 3", () {}); | 587 test("test 3", () {}); |
| 588 } | 588 } |
| 589 """); | 589 """); |
| 590 | 590 |
| 591 var result = _runUnittest(["--name", "test [13]", "test.dart"]); | 591 var result = _runTest(["--name", "test [13]", "test.dart"]); |
| 592 expect(result.stdout, contains("+2: All tests passed!")); | 592 expect(result.stdout, contains("+2: All tests passed!")); |
| 593 expect(result.exitCode, equals(0)); | 593 expect(result.exitCode, equals(0)); |
| 594 }); | 594 }); |
| 595 | 595 |
| 596 test("produces an error when no tests match", () { | 596 test("produces an error when no tests match", () { |
| 597 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 597 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 598 | 598 |
| 599 var result = _runUnittest(["--name", "no match", "test.dart"]); | 599 var result = _runTest(["--name", "no match", "test.dart"]); |
| 600 expect(result.stderr, | 600 expect(result.stderr, |
| 601 contains('No tests match regular expression "no match".')); | 601 contains('No tests match regular expression "no match".')); |
| 602 expect(result.exitCode, equals(exit_codes.data)); | 602 expect(result.exitCode, equals(exit_codes.data)); |
| 603 }); | 603 }); |
| 604 | 604 |
| 605 test("doesn't filter out load exceptions", () { | 605 test("doesn't filter out load exceptions", () { |
| 606 var result = _runUnittest(["--name", "name", "file"]); | 606 var result = _runTest(["--name", "name", "file"]); |
| 607 expect(result.stdout, allOf([ | 607 expect(result.stdout, allOf([ |
| 608 contains('-1: load error'), | 608 contains('-1: load error'), |
| 609 contains('Failed to load "file": Does not exist.') | 609 contains('Failed to load "file": Does not exist.') |
| 610 ])); | 610 ])); |
| 611 expect(result.exitCode, equals(1)); | 611 expect(result.exitCode, equals(1)); |
| 612 }); | 612 }); |
| 613 }); | 613 }); |
| 614 | 614 |
| 615 group("with the --plain-name flag,", () { | 615 group("with the --plain-name flag,", () { |
| 616 test("selects tests with matching names", () { | 616 test("selects tests with matching names", () { |
| 617 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 617 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
| 618 import 'dart:async'; | 618 import 'dart:async'; |
| 619 | 619 |
| 620 import 'package:test/test.dart'; | 620 import 'package:test/test.dart'; |
| 621 | 621 |
| 622 void main() { | 622 void main() { |
| 623 test("selected 1", () {}); | 623 test("selected 1", () {}); |
| 624 test("nope", () => throw new TestFailure("oh no")); | 624 test("nope", () => throw new TestFailure("oh no")); |
| 625 test("selected 2", () {}); | 625 test("selected 2", () {}); |
| 626 } | 626 } |
| 627 """); | 627 """); |
| 628 | 628 |
| 629 var result = _runUnittest(["--plain-name", "selected", "test.dart"]); | 629 var result = _runTest(["--plain-name", "selected", "test.dart"]); |
| 630 expect(result.stdout, contains("+2: All tests passed!")); | 630 expect(result.stdout, contains("+2: All tests passed!")); |
| 631 expect(result.exitCode, equals(0)); | 631 expect(result.exitCode, equals(0)); |
| 632 }); | 632 }); |
| 633 | 633 |
| 634 test("doesn't support RegExp syntax", () { | 634 test("doesn't support RegExp syntax", () { |
| 635 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 635 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
| 636 import 'dart:async'; | 636 import 'dart:async'; |
| 637 | 637 |
| 638 import 'package:test/test.dart'; | 638 import 'package:test/test.dart'; |
| 639 | 639 |
| 640 void main() { | 640 void main() { |
| 641 test("test 1", () => throw new TestFailure("oh no")); | 641 test("test 1", () => throw new TestFailure("oh no")); |
| 642 test("test 2", () => throw new TestFailure("oh no")); | 642 test("test 2", () => throw new TestFailure("oh no")); |
| 643 test("test [12]", () {}); | 643 test("test [12]", () {}); |
| 644 } | 644 } |
| 645 """); | 645 """); |
| 646 | 646 |
| 647 var result = _runUnittest(["--plain-name", "test [12]", "test.dart"]); | 647 var result = _runTest(["--plain-name", "test [12]", "test.dart"]); |
| 648 expect(result.stdout, contains("+1: All tests passed!")); | 648 expect(result.stdout, contains("+1: All tests passed!")); |
| 649 expect(result.exitCode, equals(0)); | 649 expect(result.exitCode, equals(0)); |
| 650 }); | 650 }); |
| 651 | 651 |
| 652 test("produces an error when no tests match", () { | 652 test("produces an error when no tests match", () { |
| 653 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 653 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
| 654 | 654 |
| 655 var result = _runUnittest(["--plain-name", "no match", "test.dart"]); | 655 var result = _runTest(["--plain-name", "no match", "test.dart"]); |
| 656 expect(result.stderr, | 656 expect(result.stderr, |
| 657 contains('No tests match "no match".')); | 657 contains('No tests match "no match".')); |
| 658 expect(result.exitCode, equals(exit_codes.data)); | 658 expect(result.exitCode, equals(exit_codes.data)); |
| 659 }); | 659 }); |
| 660 }); | 660 }); |
| 661 }); | 661 }); |
| 662 } | 662 } |
| 663 | 663 |
| 664 ProcessResult _runUnittest(List<String> args) => | 664 ProcessResult _runTest(List<String> args) => |
| 665 runUnittest(args, workingDirectory: _sandbox); | 665 runTest(args, workingDirectory: _sandbox); |
| 666 | 666 |
| 667 ProcessResult _runDart(List<String> args) => | 667 ProcessResult _runDart(List<String> args) => |
| 668 runDart(args, workingDirectory: _sandbox); | 668 runDart(args, workingDirectory: _sandbox); |
| OLD | NEW |