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