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'; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 var result = _runUnittest(["-p", "chrome", "test.dart"]); | 108 var result = _runUnittest(["-p", "chrome", "test.dart"]); |
109 expect(result.stdout, allOf([ | 109 expect(result.stdout, allOf([ |
110 contains('-1: load error'), | 110 contains('-1: load error'), |
111 contains( | 111 contains( |
112 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' | 112 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' |
113 'Top-level main() function takes arguments.\n') | 113 'Top-level main() function takes arguments.\n') |
114 ])); | 114 ])); |
115 expect(result.exitCode, equals(1)); | 115 expect(result.exitCode, equals(1)); |
116 }); | 116 }); |
117 | 117 |
| 118 test("a custom HTML file has no script tag", () { |
| 119 var testPath = p.join(_sandbox, "test.dart"); |
| 120 new File(testPath).writeAsStringSync("void main(arg) {}"); |
| 121 |
| 122 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" |
| 123 <html> |
| 124 <head> |
| 125 <link rel="x-dart-test" href="test.dart"> |
| 126 </head> |
| 127 </html> |
| 128 """); |
| 129 |
| 130 var relativePath = p.relative(testPath, from: _sandbox); |
| 131 var result = _runUnittest(["-p", "dartium", "test.dart"]); |
| 132 expect(result.stdout, allOf([ |
| 133 contains('-1: load error'), |
| 134 contains( |
| 135 'Failed to load "$relativePath": ' |
| 136 '"${p.withoutExtension(relativePath)}.html" must contain ' |
| 137 '<script src="packages/test/dart.js"></script>.\n') |
| 138 ])); |
| 139 expect(result.exitCode, equals(1)); |
| 140 }); |
| 141 |
| 142 test("a custom HTML file has no link", () { |
| 143 var testPath = p.join(_sandbox, "test.dart"); |
| 144 new File(testPath).writeAsStringSync("void main(arg) {}"); |
| 145 |
| 146 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" |
| 147 <html> |
| 148 <head> |
| 149 <script src="packages/test/dart.js"></script> |
| 150 </head> |
| 151 </html> |
| 152 """); |
| 153 |
| 154 var result = _runUnittest(["-p", "dartium", "test.dart"]); |
| 155 expect(result.stdout, allOf([ |
| 156 contains('-1: load error'), |
| 157 contains( |
| 158 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' |
| 159 'Expected exactly 1 <link rel="x-dart-test"> in test.html, ' |
| 160 'found 0.\n') |
| 161 ])); |
| 162 expect(result.exitCode, equals(1)); |
| 163 }); |
| 164 |
| 165 test("a custom HTML file has too many links", () { |
| 166 var testPath = p.join(_sandbox, "test.dart"); |
| 167 new File(testPath).writeAsStringSync("void main(arg) {}"); |
| 168 |
| 169 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" |
| 170 <html> |
| 171 <head> |
| 172 <link rel='x-dart-test' href='test.dart'> |
| 173 <link rel='x-dart-test' href='test.dart'> |
| 174 <script src="packages/test/dart.js"></script> |
| 175 </head> |
| 176 </html> |
| 177 """); |
| 178 |
| 179 var result = _runUnittest(["-p", "dartium", "test.dart"]); |
| 180 expect(result.stdout, allOf([ |
| 181 contains('-1: load error'), |
| 182 contains( |
| 183 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' |
| 184 'Expected exactly 1 <link rel="x-dart-test"> in test.html, ' |
| 185 'found 2.\n') |
| 186 ])); |
| 187 expect(result.exitCode, equals(1)); |
| 188 }); |
| 189 |
| 190 test("a custom HTML file has no href in the link", () { |
| 191 var testPath = p.join(_sandbox, "test.dart"); |
| 192 new File(testPath).writeAsStringSync("void main(arg) {}"); |
| 193 |
| 194 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" |
| 195 <html> |
| 196 <head> |
| 197 <link rel='x-dart-test'> |
| 198 <script src="packages/test/dart.js"></script> |
| 199 </head> |
| 200 </html> |
| 201 """); |
| 202 |
| 203 var result = _runUnittest(["-p", "dartium", "test.dart"]); |
| 204 expect(result.stdout, allOf([ |
| 205 contains('-1: load error'), |
| 206 contains( |
| 207 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' |
| 208 'Expected <link rel="x-dart-test"> in test.html to have an ' |
| 209 '"href" attribute.\n') |
| 210 ])); |
| 211 expect(result.exitCode, equals(1)); |
| 212 }); |
| 213 |
| 214 test("a custom HTML file has an invalid test URL", () { |
| 215 var testPath = p.join(_sandbox, "test.dart"); |
| 216 new File(testPath).writeAsStringSync("void main(arg) {}"); |
| 217 |
| 218 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" |
| 219 <html> |
| 220 <head> |
| 221 <link rel='x-dart-test' href='wrong.dart'> |
| 222 <script src="packages/test/dart.js"></script> |
| 223 </head> |
| 224 </html> |
| 225 """); |
| 226 |
| 227 var result = _runUnittest(["-p", "dartium", "test.dart"]); |
| 228 expect(result.stdout, allOf([ |
| 229 contains('-1: load error'), |
| 230 contains( |
| 231 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' |
| 232 'Failed to load script at ') |
| 233 ])); |
| 234 expect(result.exitCode, equals(1)); |
| 235 }); |
| 236 |
118 // TODO(nweiz): test what happens when a test file is unreadable once issue | 237 // TODO(nweiz): test what happens when a test file is unreadable once issue |
119 // 15078 is fixed. | 238 // 15078 is fixed. |
120 }); | 239 }); |
121 | 240 |
122 group("runs successful tests", () { | 241 group("runs successful tests", () { |
123 test("on Chrome", () { | 242 test("on Chrome", () { |
124 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 243 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
125 var result = _runUnittest(["-p", "chrome", "test.dart"]); | 244 var result = _runUnittest(["-p", "chrome", "test.dart"]); |
126 expect(result.exitCode, equals(0)); | 245 expect(result.exitCode, equals(0)); |
127 }); | 246 }); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 ["-p", "content-shell", "-p", "chrome", "test.dart"]); | 290 ["-p", "content-shell", "-p", "chrome", "test.dart"]); |
172 expect("Compiling".allMatches(result.stdout), hasLength(1)); | 291 expect("Compiling".allMatches(result.stdout), hasLength(1)); |
173 expect(result.exitCode, equals(0)); | 292 expect(result.exitCode, equals(0)); |
174 }); | 293 }); |
175 | 294 |
176 test("on the browser and the VM", () { | 295 test("on the browser and the VM", () { |
177 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); | 296 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); |
178 var result = _runUnittest(["-p", "chrome", "-p", "vm", "test.dart"]); | 297 var result = _runUnittest(["-p", "chrome", "-p", "vm", "test.dart"]); |
179 expect(result.exitCode, equals(0)); | 298 expect(result.exitCode, equals(0)); |
180 }); | 299 }); |
| 300 |
| 301 group("with a custom HTML file", () { |
| 302 setUp(() { |
| 303 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
| 304 import 'dart:html'; |
| 305 |
| 306 import 'package:test/test.dart'; |
| 307 |
| 308 void main() { |
| 309 test("success", () { |
| 310 expect(document.query('#foo'), isNotNull); |
| 311 }); |
| 312 } |
| 313 """); |
| 314 |
| 315 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" |
| 316 <html> |
| 317 <head> |
| 318 <link rel='x-dart-test' href='test.dart'> |
| 319 <script src="packages/test/dart.js"></script> |
| 320 </head> |
| 321 <body> |
| 322 <div id="foo"></div> |
| 323 </body> |
| 324 </html> |
| 325 """); |
| 326 }); |
| 327 |
| 328 test("on content shell", () { |
| 329 var result = _runUnittest(["-p", "content-shell", "test.dart"]); |
| 330 expect(result.exitCode, equals(0)); |
| 331 }); |
| 332 |
| 333 test("on Chrome", () { |
| 334 var result = _runUnittest(["-p", "chrome", "test.dart"]); |
| 335 expect(result.exitCode, equals(0)); |
| 336 }); |
| 337 }); |
181 }); | 338 }); |
182 | 339 |
183 group("runs failing tests", () { | 340 group("runs failing tests", () { |
184 test("on Chrome", () { | 341 test("on Chrome", () { |
185 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); | 342 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_failure); |
186 var result = _runUnittest(["-p", "chrome", "test.dart"]); | 343 var result = _runUnittest(["-p", "chrome", "test.dart"]); |
187 expect(result.exitCode, equals(1)); | 344 expect(result.exitCode, equals(1)); |
188 }); | 345 }); |
189 | 346 |
190 test("on PhantomJS", () { | 347 test("on PhantomJS", () { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 400 |
244 void main() { | 401 void main() { |
245 test("test", () { | 402 test("test", () { |
246 if (p.style != p.Style.url) throw new TestFailure("oh no"); | 403 if (p.style != p.Style.url) throw new TestFailure("oh no"); |
247 }); | 404 }); |
248 } | 405 } |
249 """); | 406 """); |
250 var result = _runUnittest(["-p", "chrome", "-p", "vm", "test.dart"]); | 407 var result = _runUnittest(["-p", "chrome", "-p", "vm", "test.dart"]); |
251 expect(result.exitCode, equals(1)); | 408 expect(result.exitCode, equals(1)); |
252 }); | 409 }); |
| 410 |
| 411 |
| 412 group("with a custom HTML file", () { |
| 413 setUp(() { |
| 414 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
| 415 import 'dart:html'; |
| 416 |
| 417 import 'package:test/test.dart'; |
| 418 |
| 419 void main() { |
| 420 test("failure", () { |
| 421 expect(document.query('#foo'), isNull); |
| 422 }); |
| 423 } |
| 424 """); |
| 425 |
| 426 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" |
| 427 <html> |
| 428 <head> |
| 429 <link rel='x-dart-test' href='test.dart'> |
| 430 <script src="packages/test/dart.js"></script> |
| 431 </head> |
| 432 <body> |
| 433 <div id="foo"></div> |
| 434 </body> |
| 435 </html> |
| 436 """); |
| 437 }); |
| 438 |
| 439 test("on content shell", () { |
| 440 var result = _runUnittest(["-p", "content-shell", "test.dart"]); |
| 441 expect(result.exitCode, equals(1)); |
| 442 }); |
| 443 |
| 444 test("on Chrome", () { |
| 445 var result = _runUnittest(["-p", "chrome", "test.dart"]); |
| 446 expect(result.exitCode, equals(1)); |
| 447 }); |
| 448 }); |
253 }); | 449 }); |
254 | 450 |
255 test("forwards prints from the browser test", () { | 451 test("forwards prints from the browser test", () { |
256 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 452 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
257 import 'dart:async'; | 453 import 'dart:async'; |
258 | 454 |
259 import 'package:test/test.dart'; | 455 import 'package:test/test.dart'; |
260 | 456 |
261 void main() { | 457 void main() { |
262 test("test", () { | 458 test("test", () { |
(...skipping 22 matching lines...) Expand all Loading... |
285 '''); | 481 '''); |
286 | 482 |
287 var result = _runUnittest(["-p", "chrome", "test.dart"]); | 483 var result = _runUnittest(["-p", "chrome", "test.dart"]); |
288 expect(result.stdout, contains("Test timed out after 0 seconds.")); | 484 expect(result.stdout, contains("Test timed out after 0 seconds.")); |
289 expect(result.stdout, contains("-1: Some tests failed.")); | 485 expect(result.stdout, contains("-1: Some tests failed.")); |
290 }); | 486 }); |
291 } | 487 } |
292 | 488 |
293 ProcessResult _runUnittest(List<String> args) => | 489 ProcessResult _runUnittest(List<String> args) => |
294 runUnittest(args, workingDirectory: _sandbox); | 490 runUnittest(args, workingDirectory: _sandbox); |
OLD | NEW |