Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: test/runner/browser/runner_test.dart

Issue 1196413003: Add a LoadSuite class. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 27 matching lines...) Expand all
38 tearDown(() { 38 tearDown(() {
39 new Directory(_sandbox).deleteSync(recursive: true); 39 new Directory(_sandbox).deleteSync(recursive: true);
40 }); 40 });
41 41
42 group("fails gracefully if", () { 42 group("fails gracefully if", () {
43 test("a test file fails to compile", () { 43 test("a test file fails to compile", () {
44 var testPath = p.join(_sandbox, "test.dart"); 44 var testPath = p.join(_sandbox, "test.dart");
45 new File(testPath).writeAsStringSync("invalid Dart file"); 45 new File(testPath).writeAsStringSync("invalid Dart file");
46 var result = _runTest(["-p", "chrome", "test.dart"]); 46 var result = _runTest(["-p", "chrome", "test.dart"]);
47 47
48 expect(result.stdout, 48 var relativePath = p.relative(testPath, from: _sandbox);
49 contains("Expected a declaration, but got 'invalid'"));
50 expect(result.stdout, allOf([ 49 expect(result.stdout, allOf([
51 contains('-1: load error'), 50 contains("Expected a declaration, but got 'invalid'"),
52 contains( 51 contains('-1: compiling $relativePath'),
53 'Failed to load "${p.relative(testPath, from: _sandbox)}": dart2js ' 52 contains('Failed to load "$relativePath": dart2js failed.')
54 'failed.')
55 ])); 53 ]));
56 expect(result.exitCode, equals(1)); 54 expect(result.exitCode, equals(1));
57 }); 55 });
58 56
59 test("a test file throws", () { 57 test("a test file throws", () {
60 var testPath = p.join(_sandbox, "test.dart"); 58 var testPath = p.join(_sandbox, "test.dart");
61 new File(testPath).writeAsStringSync("void main() => throw 'oh no';"); 59 new File(testPath).writeAsStringSync("void main() => throw 'oh no';");
62 60
61 var relativePath = p.relative(testPath, from: _sandbox);
63 var result = _runTest(["-p", "chrome", "test.dart"]); 62 var result = _runTest(["-p", "chrome", "test.dart"]);
64 expect(result.stdout, allOf([ 63 expect(result.stdout, allOf([
65 contains('-1: load error'), 64 contains('-1: compiling $relativePath'),
66 contains( 65 contains('Failed to load "$relativePath": oh no')
67 'Failed to load "${p.relative(testPath, from: _sandbox)}": oh no')
68 ])); 66 ]));
69 expect(result.exitCode, equals(1)); 67 expect(result.exitCode, equals(1));
70 }); 68 });
71 69
72 test("a test file doesn't have a main defined", () { 70 test("a test file doesn't have a main defined", () {
73 var testPath = p.join(_sandbox, "test.dart"); 71 var testPath = p.join(_sandbox, "test.dart");
74 new File(testPath).writeAsStringSync("void foo() {}"); 72 new File(testPath).writeAsStringSync("void foo() {}");
75 73
74 var relativePath = p.relative(testPath, from: _sandbox);
76 var result = _runTest(["-p", "chrome", "test.dart"]); 75 var result = _runTest(["-p", "chrome", "test.dart"]);
77 expect(result.stdout, allOf([ 76 expect(result.stdout, allOf([
78 contains('-1: load error'), 77 contains('-1: compiling $relativePath'),
79 contains( 78 contains('Failed to load "$relativePath": No top-level main() function '
80 'Failed to load "${p.relative(testPath, from: _sandbox)}": No ' 79 'defined.')
81 'top-level main() function defined.')
82 ])); 80 ]));
83 expect(result.exitCode, equals(1)); 81 expect(result.exitCode, equals(1));
84 }); 82 });
85 83
86 test("a test file has a non-function main", () { 84 test("a test file has a non-function main", () {
87 var testPath = p.join(_sandbox, "test.dart"); 85 var testPath = p.join(_sandbox, "test.dart");
88 new File(testPath).writeAsStringSync("int main;"); 86 new File(testPath).writeAsStringSync("int main;");
89 87
88 var relativePath = p.relative(testPath, from: _sandbox);
90 var result = _runTest(["-p", "chrome", "test.dart"]); 89 var result = _runTest(["-p", "chrome", "test.dart"]);
91 expect(result.stdout, allOf([ 90 expect(result.stdout, allOf([
92 contains('-1: load error'), 91 contains('-1: compiling $relativePath'),
93 contains( 92 contains('Failed to load "$relativePath": Top-level main getter is not '
94 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' 93 'a function.\n')
95 'Top-level main getter is not a function.\n')
96 ])); 94 ]));
97 expect(result.exitCode, equals(1)); 95 expect(result.exitCode, equals(1));
98 }); 96 });
99 97
100 test("a test file has a main with arguments", () { 98 test("a test file has a main with arguments", () {
101 var testPath = p.join(_sandbox, "test.dart"); 99 var testPath = p.join(_sandbox, "test.dart");
102 new File(testPath).writeAsStringSync("void main(arg) {}"); 100 new File(testPath).writeAsStringSync("void main(arg) {}");
103 101
102 var relativePath = p.relative(testPath, from: _sandbox);
104 var result = _runTest(["-p", "chrome", "test.dart"]); 103 var result = _runTest(["-p", "chrome", "test.dart"]);
105 expect(result.stdout, allOf([ 104 expect(result.stdout, allOf([
106 contains('-1: load error'), 105 contains('-1: compiling $relativePath'),
107 contains( 106 contains('Failed to load "$relativePath": Top-level main() function '
108 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' 107 'takes arguments.\n')
109 'Top-level main() function takes arguments.\n')
110 ])); 108 ]));
111 expect(result.exitCode, equals(1)); 109 expect(result.exitCode, equals(1));
112 }); 110 });
113 111
114 test("a custom HTML file has no script tag", () { 112 test("a custom HTML file has no script tag", () {
115 var testPath = p.join(_sandbox, "test.dart"); 113 var testPath = p.join(_sandbox, "test.dart");
116 new File(testPath).writeAsStringSync("void main(arg) {}"); 114 new File(testPath).writeAsStringSync("void main(arg) {}");
117 115
118 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" 116 new File(p.join(_sandbox, "test.html")).writeAsStringSync("""
119 <html> 117 <html>
120 <head> 118 <head>
121 <link rel="x-dart-test" href="test.dart"> 119 <link rel="x-dart-test" href="test.dart">
122 </head> 120 </head>
123 </html> 121 </html>
124 """); 122 """);
125 123
126 var relativePath = p.relative(testPath, from: _sandbox); 124 var relativePath = p.relative(testPath, from: _sandbox);
127 var result = _runTest(["-p", "content-shell", "test.dart"]); 125 var result = _runTest(["-p", "content-shell", "test.dart"]);
128 expect(result.stdout, allOf([ 126 expect(result.stdout, allOf([
129 contains('-1: load error'), 127 contains('-1: loading $relativePath'),
130 contains( 128 contains(
131 'Failed to load "$relativePath": ' 129 'Failed to load "$relativePath": '
132 '"${p.withoutExtension(relativePath)}.html" must contain ' 130 '"${p.withoutExtension(relativePath)}.html" must contain '
133 '<script src="packages/test/dart.js"></script>.\n') 131 '<script src="packages/test/dart.js"></script>.\n')
134 ])); 132 ]));
135 expect(result.exitCode, equals(1)); 133 expect(result.exitCode, equals(1));
136 }); 134 });
137 135
138 test("a custom HTML file has no link", () { 136 test("a custom HTML file has no link", () {
139 var testPath = p.join(_sandbox, "test.dart"); 137 var testPath = p.join(_sandbox, "test.dart");
140 new File(testPath).writeAsStringSync("void main(arg) {}"); 138 new File(testPath).writeAsStringSync("void main(arg) {}");
141 139
142 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" 140 new File(p.join(_sandbox, "test.html")).writeAsStringSync("""
143 <html> 141 <html>
144 <head> 142 <head>
145 <script src="packages/test/dart.js"></script> 143 <script src="packages/test/dart.js"></script>
146 </head> 144 </head>
147 </html> 145 </html>
148 """); 146 """);
149 147
148 var relativePath = p.relative(testPath, from: _sandbox);
150 var result = _runTest(["-p", "content-shell", "test.dart"]); 149 var result = _runTest(["-p", "content-shell", "test.dart"]);
151 expect(result.stdout, allOf([ 150 expect(result.stdout, allOf([
152 contains('-1: load error'), 151 contains('-1: loading $relativePath'),
153 contains( 152 contains(
154 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' 153 'Failed to load "$relativePath": '
155 'Expected exactly 1 <link rel="x-dart-test"> in test.html, ' 154 'Expected exactly 1 <link rel="x-dart-test"> in test.html, '
156 'found 0.\n') 155 'found 0.\n')
157 ])); 156 ]));
158 expect(result.exitCode, equals(1)); 157 expect(result.exitCode, equals(1));
159 }); 158 });
160 159
161 test("a custom HTML file has too many links", () { 160 test("a custom HTML file has too many links", () {
162 var testPath = p.join(_sandbox, "test.dart"); 161 var testPath = p.join(_sandbox, "test.dart");
163 new File(testPath).writeAsStringSync("void main(arg) {}"); 162 new File(testPath).writeAsStringSync("void main(arg) {}");
164 163
165 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" 164 new File(p.join(_sandbox, "test.html")).writeAsStringSync("""
166 <html> 165 <html>
167 <head> 166 <head>
168 <link rel='x-dart-test' href='test.dart'> 167 <link rel='x-dart-test' href='test.dart'>
169 <link rel='x-dart-test' href='test.dart'> 168 <link rel='x-dart-test' href='test.dart'>
170 <script src="packages/test/dart.js"></script> 169 <script src="packages/test/dart.js"></script>
171 </head> 170 </head>
172 </html> 171 </html>
173 """); 172 """);
174 173
174 var relativePath = p.relative(testPath, from: _sandbox);
175 var result = _runTest(["-p", "content-shell", "test.dart"]); 175 var result = _runTest(["-p", "content-shell", "test.dart"]);
176 expect(result.stdout, allOf([ 176 expect(result.stdout, allOf([
177 contains('-1: load error'), 177 contains('-1: loading $relativePath'),
178 contains( 178 contains(
179 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' 179 'Failed to load "$relativePath": '
180 'Expected exactly 1 <link rel="x-dart-test"> in test.html, ' 180 'Expected exactly 1 <link rel="x-dart-test"> in test.html, '
181 'found 2.\n') 181 'found 2.\n')
182 ])); 182 ]));
183 expect(result.exitCode, equals(1)); 183 expect(result.exitCode, equals(1));
184 }); 184 });
185 185
186 test("a custom HTML file has no href in the link", () { 186 test("a custom HTML file has no href in the link", () {
187 var testPath = p.join(_sandbox, "test.dart"); 187 var testPath = p.join(_sandbox, "test.dart");
188 new File(testPath).writeAsStringSync("void main(arg) {}"); 188 new File(testPath).writeAsStringSync("void main(arg) {}");
189 189
190 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" 190 new File(p.join(_sandbox, "test.html")).writeAsStringSync("""
191 <html> 191 <html>
192 <head> 192 <head>
193 <link rel='x-dart-test'> 193 <link rel='x-dart-test'>
194 <script src="packages/test/dart.js"></script> 194 <script src="packages/test/dart.js"></script>
195 </head> 195 </head>
196 </html> 196 </html>
197 """); 197 """);
198 198
199 var relativePath = p.relative(testPath, from: _sandbox);
199 var result = _runTest(["-p", "content-shell", "test.dart"]); 200 var result = _runTest(["-p", "content-shell", "test.dart"]);
200 expect(result.stdout, allOf([ 201 expect(result.stdout, allOf([
201 contains('-1: load error'), 202 contains('-1: loading $relativePath'),
202 contains( 203 contains(
203 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' 204 'Failed to load "$relativePath": '
204 'Expected <link rel="x-dart-test"> in test.html to have an ' 205 'Expected <link rel="x-dart-test"> in test.html to have an '
205 '"href" attribute.\n') 206 '"href" attribute.\n')
206 ])); 207 ]));
207 expect(result.exitCode, equals(1)); 208 expect(result.exitCode, equals(1));
208 }); 209 });
209 210
210 test("a custom HTML file has an invalid test URL", () { 211 test("a custom HTML file has an invalid test URL", () {
211 var testPath = p.join(_sandbox, "test.dart"); 212 var testPath = p.join(_sandbox, "test.dart");
212 new File(testPath).writeAsStringSync("void main(arg) {}"); 213 new File(testPath).writeAsStringSync("void main(arg) {}");
213 214
214 new File(p.join(_sandbox, "test.html")).writeAsStringSync(""" 215 new File(p.join(_sandbox, "test.html")).writeAsStringSync("""
215 <html> 216 <html>
216 <head> 217 <head>
217 <link rel='x-dart-test' href='wrong.dart'> 218 <link rel='x-dart-test' href='wrong.dart'>
218 <script src="packages/test/dart.js"></script> 219 <script src="packages/test/dart.js"></script>
219 </head> 220 </head>
220 </html> 221 </html>
221 """); 222 """);
222 223
224 var relativePath = p.relative(testPath, from: _sandbox);
223 var result = _runTest(["-p", "content-shell", "test.dart"]); 225 var result = _runTest(["-p", "content-shell", "test.dart"]);
224 expect(result.stdout, allOf([ 226 expect(result.stdout, allOf([
225 contains('-1: load error'), 227 contains('-1: loading $relativePath'),
226 contains( 228 contains(
227 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' 229 'Failed to load "$relativePath": '
228 'Failed to load script at ') 230 'Failed to load script at ')
229 ])); 231 ]));
230 expect(result.exitCode, equals(1)); 232 expect(result.exitCode, equals(1));
231 }); 233 });
232 234
233 // TODO(nweiz): test what happens when a test file is unreadable once issue 235 // TODO(nweiz): test what happens when a test file is unreadable once issue
234 // 15078 is fixed. 236 // 15078 is fixed.
235 }); 237 });
236 238
237 group("runs successful tests", () { 239 group("runs successful tests", () {
(...skipping 13 matching lines...) Expand all
251 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); 253 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
252 var result = _runTest(["-p", "content-shell", "test.dart"]); 254 var result = _runTest(["-p", "content-shell", "test.dart"]);
253 expect(result.stdout, isNot(contains("Compiling"))); 255 expect(result.stdout, isNot(contains("Compiling")));
254 expect(result.exitCode, equals(0)); 256 expect(result.exitCode, equals(0));
255 }); 257 });
256 258
257 test("on a JS and non-JS browser", () { 259 test("on a JS and non-JS browser", () {
258 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); 260 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
259 var result = _runTest( 261 var result = _runTest(
260 ["-p", "content-shell", "-p", "chrome", "test.dart"]); 262 ["-p", "content-shell", "-p", "chrome", "test.dart"]);
261 expect("Compiling".allMatches(result.stdout), hasLength(1)); 263 expect(result.stdout, contains("[Chrome] compiling"));
264 expect(result.stdout,
265 isNot(contains("[Dartium Content Shell] compiling")));
262 expect(result.exitCode, equals(0)); 266 expect(result.exitCode, equals(0));
263 }); 267 });
264 268
265 test("on a browser and the VM", () { 269 test("on a browser and the VM", () {
266 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success); 270 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(_success);
267 var result = _runTest(["-p", "content-shell", "-p", "vm", "test.dart"]); 271 var result = _runTest(["-p", "content-shell", "-p", "vm", "test.dart"]);
268 expect(result.exitCode, equals(0)); 272 expect(result.exitCode, equals(0));
269 }); 273 });
270 274
271 // Regression test; this broke in 0.12.0-beta.9. 275 // Regression test; this broke in 0.12.0-beta.9.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 expect(result.exitCode, equals(1)); 426 expect(result.exitCode, equals(1));
423 }); 427 });
424 428
425 test("on Chrome", () { 429 test("on Chrome", () {
426 var result = _runTest(["-p", "chrome", "test.dart"]); 430 var result = _runTest(["-p", "chrome", "test.dart"]);
427 expect(result.exitCode, equals(1)); 431 expect(result.exitCode, equals(1));
428 }); 432 });
429 }); 433 });
430 }); 434 });
431 435
436 test("the compiler uses colors if the test runner uses colors", () {
437 var testPath = p.join(_sandbox, "test.dart");
438 new File(testPath).writeAsStringSync("String main() => 12;\n");
439
440 var result = _runTest(["--color", "-p", "chrome", "test.dart"]);
441 expect(result.stdout, contains('\u001b[35m'));
442 expect(result.exitCode, equals(1));
443 });
444
432 test("forwards prints from the browser test", () { 445 test("forwards prints from the browser test", () {
433 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" 446 new File(p.join(_sandbox, "test.dart")).writeAsStringSync("""
434 import 'dart:async'; 447 import 'dart:async';
435 448
436 import 'package:test/test.dart'; 449 import 'package:test/test.dart';
437 450
438 void main() { 451 void main() {
439 test("test", () { 452 test("test", () {
440 print("Hello,"); 453 print("Hello,");
441 return new Future(() => print("world!")); 454 return new Future(() => print("world!"));
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 '''); 663 ''');
651 664
652 var result = _runTest(["-p", "content-shell", "test.dart"]); 665 var result = _runTest(["-p", "content-shell", "test.dart"]);
653 expect(result.stdout, contains("+1: All tests passed!")); 666 expect(result.stdout, contains("+1: All tests passed!"));
654 }); 667 });
655 }); 668 });
656 } 669 }
657 670
658 ProcessResult _runTest(List<String> args) => 671 ProcessResult _runTest(List<String> args) =>
659 runTest(args, workingDirectory: _sandbox); 672 runTest(args, workingDirectory: _sandbox);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698