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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 expect(result.stderr, equals(""" | 94 expect(result.stderr, equals(""" |
95 Could not find an option named "asdf". | 95 Could not find an option named "asdf". |
96 | 96 |
97 $_usage""")); | 97 $_usage""")); |
98 expect(result.exitCode, equals(exit_codes.usage)); | 98 expect(result.exitCode, equals(exit_codes.usage)); |
99 }); | 99 }); |
100 | 100 |
101 test("a non-existent file is passed", () { | 101 test("a non-existent file is passed", () { |
102 var result = _runTest(["file"]); | 102 var result = _runTest(["file"]); |
103 expect(result.stdout, allOf([ | 103 expect(result.stdout, allOf([ |
104 contains('-1: load error'), | 104 contains('-1: loading file'), |
105 contains('Failed to load "file": Does not exist.') | 105 contains('Failed to load "file": Does not exist.') |
106 ])); | 106 ])); |
107 expect(result.exitCode, equals(1)); | 107 expect(result.exitCode, equals(1)); |
108 }); | 108 }); |
109 | 109 |
110 test("the default directory doesn't exist", () { | 110 test("the default directory doesn't exist", () { |
111 var result = _runTest([]); | 111 var result = _runTest([]); |
112 expect(result.stderr, equals(""" | 112 expect(result.stderr, equals(""" |
113 No test files were passed and the default "test/" directory doesn't exist. | 113 No test files were passed and the default "test/" directory doesn't exist. |
114 | 114 |
115 $_usage""")); | 115 $_usage""")); |
116 expect(result.exitCode, equals(exit_codes.data)); | 116 expect(result.exitCode, equals(exit_codes.data)); |
117 }); | 117 }); |
118 | 118 |
119 test("a test file fails to load", () { | 119 test("a test file fails to load", () { |
120 var testPath = p.join(_sandbox, "test.dart"); | 120 var testPath = p.join(_sandbox, "test.dart"); |
121 new File(testPath).writeAsStringSync("invalid Dart file"); | 121 new File(testPath).writeAsStringSync("invalid Dart file"); |
122 var result = _runTest(["test.dart"]); | 122 var result = _runTest(["test.dart"]); |
123 | 123 |
124 expect(result.stdout, allOf([ | 124 expect(result.stdout, allOf([ |
125 contains('-1: load error'), | 125 contains('-1: loading test.dart'), |
126 contains( | 126 contains( |
127 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' | 127 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' |
128 " line 1 pos 1: unexpected token 'invalid'\n" | 128 " line 1 pos 1: unexpected token 'invalid'\n" |
129 " invalid Dart file\n" | 129 " invalid Dart file\n" |
130 " ^\n") | 130 " ^\n") |
131 ])); | 131 ])); |
132 expect(result.exitCode, equals(1)); | 132 expect(result.exitCode, equals(1)); |
133 }); | 133 }); |
134 | 134 |
135 // This syntax error is detected lazily, and so requires some extra | 135 // This syntax error is detected lazily, and so requires some extra |
136 // machinery to support. | 136 // machinery to support. |
137 test("a test file fails to parse due to a missing semicolon", () { | 137 test("a test file fails to parse due to a missing semicolon", () { |
138 var testPath = p.join(_sandbox, "test.dart"); | 138 var testPath = p.join(_sandbox, "test.dart"); |
139 new File(testPath).writeAsStringSync("void main() {foo}"); | 139 new File(testPath).writeAsStringSync("void main() {foo}"); |
140 var result = _runTest(["test.dart"]); | 140 var result = _runTest(["test.dart"]); |
141 | 141 |
142 expect(result.stdout, allOf([ | 142 expect(result.stdout, allOf([ |
143 contains('-1: load error'), | 143 contains('-1: loading test.dart'), |
144 contains( | 144 contains( |
145 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' | 145 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' |
146 " line 1 pos 17: semicolon expected\n" | 146 " line 1 pos 17: semicolon expected\n" |
147 " void main() {foo}\n" | 147 " void main() {foo}\n" |
148 " ^\n") | 148 " ^\n") |
149 ])); | 149 ])); |
150 expect(result.exitCode, equals(1)); | 150 expect(result.exitCode, equals(1)); |
151 }); | 151 }); |
152 | 152 |
153 // This is slightly different from the above test because it's an error | 153 // This is slightly different from the above test because it's an error |
154 // that's caught first by the analyzer when it's used to parse the file. | 154 // that's caught first by the analyzer when it's used to parse the file. |
155 test("a test file fails to parse", () { | 155 test("a test file fails to parse", () { |
156 var testPath = p.join(_sandbox, "test.dart"); | 156 var testPath = p.join(_sandbox, "test.dart"); |
157 new File(testPath).writeAsStringSync("@TestOn)"); | 157 new File(testPath).writeAsStringSync("@TestOn)"); |
158 var result = _runTest(["test.dart"]); | 158 var result = _runTest(["test.dart"]); |
159 | 159 |
160 expect(result.stdout, allOf([ | 160 expect(result.stdout, allOf([ |
161 contains('-1: load error'), | 161 contains('-1: loading test.dart'), |
162 contains( | 162 contains( |
163 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' | 163 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' |
164 " line 1 pos 8: unexpected token ')'\n" | 164 " line 1 pos 8: unexpected token ')'\n" |
165 " @TestOn)\n" | 165 " @TestOn)\n" |
166 " ^\n") | 166 " ^\n") |
167 ])); | 167 ])); |
168 expect(result.exitCode, equals(1)); | 168 expect(result.exitCode, equals(1)); |
169 }); | 169 }); |
170 | 170 |
171 test("an annotation's structure is invalid", () { | 171 test("an annotation's structure is invalid", () { |
172 var testPath = p.join(_sandbox, "test.dart"); | 172 var testPath = p.join(_sandbox, "test.dart"); |
173 new File(testPath).writeAsStringSync("@TestOn()\nlibrary foo;"); | 173 new File(testPath).writeAsStringSync("@TestOn()\nlibrary foo;"); |
174 var result = _runTest(["test.dart"]); | 174 var result = _runTest(["test.dart"]); |
175 | 175 |
176 expect(result.stdout, allOf([ | 176 expect(result.stdout, allOf([ |
177 contains('-1: load error'), | 177 contains('-1: loading test.dart'), |
178 contains( | 178 contains( |
179 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' | 179 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' |
180 " Error on line 1, column 8: TestOn takes 1 argument.\n" | 180 " Error on line 1, column 8: TestOn takes 1 argument.\n" |
181 " @TestOn()\n" | 181 " @TestOn()\n" |
182 " ^^\n") | 182 " ^^\n") |
183 ])); | 183 ])); |
184 expect(result.exitCode, equals(1)); | 184 expect(result.exitCode, equals(1)); |
185 }); | 185 }); |
186 | 186 |
187 test("an annotation's contents are invalid", () { | 187 test("an annotation's contents are invalid", () { |
188 var testPath = p.join(_sandbox, "test.dart"); | 188 var testPath = p.join(_sandbox, "test.dart"); |
189 new File(testPath).writeAsStringSync("@TestOn('zim')\nlibrary foo;"); | 189 new File(testPath).writeAsStringSync("@TestOn('zim')\nlibrary foo;"); |
190 var result = _runTest(["test.dart"]); | 190 var result = _runTest(["test.dart"]); |
191 | 191 |
192 expect(result.stdout, allOf([ | 192 expect(result.stdout, allOf([ |
193 contains('-1: load error'), | 193 contains('-1: loading test.dart'), |
194 contains( | 194 contains( |
195 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' | 195 ' Failed to load "${p.relative(testPath, from: _sandbox)}":\n' |
196 " Error on line 1, column 10: Undefined variable.\n" | 196 " Error on line 1, column 10: Undefined variable.\n" |
197 " @TestOn('zim')\n" | 197 " @TestOn('zim')\n" |
198 " ^^^\n") | 198 " ^^^\n") |
199 ])); | 199 ])); |
200 expect(result.exitCode, equals(1)); | 200 expect(result.exitCode, equals(1)); |
201 }); | 201 }); |
202 | 202 |
203 test("a test file throws", () { | 203 test("a test file throws", () { |
204 var testPath = p.join(_sandbox, "test.dart"); | 204 var testPath = p.join(_sandbox, "test.dart"); |
205 new File(testPath).writeAsStringSync("void main() => throw 'oh no';"); | 205 new File(testPath).writeAsStringSync("void main() => throw 'oh no';"); |
206 | 206 |
207 var result = _runTest(["test.dart"]); | 207 var result = _runTest(["test.dart"]); |
208 expect(result.stdout, allOf([ | 208 expect(result.stdout, allOf([ |
209 contains('-1: load error'), | 209 contains('-1: loading test.dart'), |
210 contains( | 210 contains( |
211 'Failed to load "${p.relative(testPath, from: _sandbox)}": oh no') | 211 'Failed to load "${p.relative(testPath, from: _sandbox)}": oh no') |
212 ])); | 212 ])); |
213 expect(result.exitCode, equals(1)); | 213 expect(result.exitCode, equals(1)); |
214 }); | 214 }); |
215 | 215 |
216 test("a test file doesn't have a main defined", () { | 216 test("a test file doesn't have a main defined", () { |
217 var testPath = p.join(_sandbox, "test.dart"); | 217 var testPath = p.join(_sandbox, "test.dart"); |
218 new File(testPath).writeAsStringSync("void foo() {}"); | 218 new File(testPath).writeAsStringSync("void foo() {}"); |
219 | 219 |
220 var result = _runTest(["test.dart"]); | 220 var result = _runTest(["test.dart"]); |
221 expect(result.stdout, allOf([ | 221 expect(result.stdout, allOf([ |
222 contains('-1: load error'), | 222 contains('-1: loading test.dart'), |
223 contains( | 223 contains( |
224 'Failed to load "${p.relative(testPath, from: _sandbox)}": No ' | 224 'Failed to load "${p.relative(testPath, from: _sandbox)}": No ' |
225 'top-level main() function defined.') | 225 'top-level main() function defined.') |
226 ])); | 226 ])); |
227 expect(result.exitCode, equals(1)); | 227 expect(result.exitCode, equals(1)); |
228 }); | 228 }); |
229 | 229 |
230 test("a test file has a non-function main", () { | 230 test("a test file has a non-function main", () { |
231 var testPath = p.join(_sandbox, "test.dart"); | 231 var testPath = p.join(_sandbox, "test.dart"); |
232 new File(testPath).writeAsStringSync("int main;"); | 232 new File(testPath).writeAsStringSync("int main;"); |
233 | 233 |
234 var result = _runTest(["test.dart"]); | 234 var result = _runTest(["test.dart"]); |
235 expect(result.stdout, allOf([ | 235 expect(result.stdout, allOf([ |
236 contains('-1: load error'), | 236 contains('-1: loading test.dart'), |
237 contains( | 237 contains( |
238 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' | 238 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' |
239 'Top-level main getter is not a function.') | 239 'Top-level main getter is not a function.') |
240 ])); | 240 ])); |
241 expect(result.exitCode, equals(1)); | 241 expect(result.exitCode, equals(1)); |
242 }); | 242 }); |
243 | 243 |
244 test("a test file has a main with arguments", () { | 244 test("a test file has a main with arguments", () { |
245 var testPath = p.join(_sandbox, "test.dart"); | 245 var testPath = p.join(_sandbox, "test.dart"); |
246 new File(testPath).writeAsStringSync("void main(arg) {}"); | 246 new File(testPath).writeAsStringSync("void main(arg) {}"); |
247 | 247 |
248 var result = _runTest(["test.dart"]); | 248 var result = _runTest(["test.dart"]); |
249 expect(result.stdout, allOf([ | 249 expect(result.stdout, allOf([ |
250 contains('-1: load error'), | 250 contains('-1: loading test.dart'), |
251 contains( | 251 contains( |
252 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' | 252 'Failed to load "${p.relative(testPath, from: _sandbox)}": ' |
253 'Top-level main() function takes arguments.') | 253 'Top-level main() function takes arguments.') |
254 ])); | 254 ])); |
255 expect(result.exitCode, equals(1)); | 255 expect(result.exitCode, equals(1)); |
256 }); | 256 }); |
257 | 257 |
258 test("multiple load errors occur", () { | 258 test("multiple load errors occur", () { |
259 var testPath = p.join(_sandbox, "test.dart"); | 259 var testPath = p.join(_sandbox, "test.dart"); |
260 new File(testPath).writeAsStringSync("invalid Dart file"); | 260 new File(testPath).writeAsStringSync("invalid Dart file"); |
261 var result = _runTest(["test.dart", "nonexistent.dart"]); | 261 var result = _runTest(["test.dart", "nonexistent.dart"]); |
262 | 262 |
263 expect(result.stdout, allOf([ | 263 expect(result.stdout, allOf([ |
264 contains('test.dart: load error'), | 264 contains('loading test.dart'), |
265 contains( | 265 contains( |
266 ' Failed to load "test.dart":\n' | 266 ' Failed to load "test.dart":\n' |
267 " line 1 pos 1: unexpected token 'invalid'\n" | 267 " line 1 pos 1: unexpected token 'invalid'\n" |
268 " invalid Dart file\n" | 268 " invalid Dart file\n" |
269 " ^\n"), | 269 " ^\n"), |
270 contains('nonexistent.dart: load error'), | 270 contains('loading nonexistent.dart'), |
271 contains('Failed to load "nonexistent.dart": Does not exist.') | 271 contains('Failed to load "nonexistent.dart": Does not exist.') |
272 ])); | 272 ])); |
273 }); | 273 }); |
274 | 274 |
275 // TODO(nweiz): test what happens when a test file is unreadable once issue | 275 // TODO(nweiz): test what happens when a test file is unreadable once issue |
276 // 15078 is fixed. | 276 // 15078 is fixed. |
277 }); | 277 }); |
278 | 278 |
279 group("runs successful tests", () { | 279 group("runs successful tests", () { |
280 test("defined in a single file", () { | 280 test("defined in a single file", () { |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 | 624 |
625 var result = _runTest(["--name", "no match", "test.dart"]); | 625 var result = _runTest(["--name", "no match", "test.dart"]); |
626 expect(result.stderr, | 626 expect(result.stderr, |
627 contains('No tests match regular expression "no match".')); | 627 contains('No tests match regular expression "no match".')); |
628 expect(result.exitCode, equals(exit_codes.data)); | 628 expect(result.exitCode, equals(exit_codes.data)); |
629 }); | 629 }); |
630 | 630 |
631 test("doesn't filter out load exceptions", () { | 631 test("doesn't filter out load exceptions", () { |
632 var result = _runTest(["--name", "name", "file"]); | 632 var result = _runTest(["--name", "name", "file"]); |
633 expect(result.stdout, allOf([ | 633 expect(result.stdout, allOf([ |
634 contains('-1: load error'), | 634 contains('-1: loading file'), |
635 contains('Failed to load "file": Does not exist.') | 635 contains('Failed to load "file": Does not exist.') |
636 ])); | 636 ])); |
637 expect(result.exitCode, equals(1)); | 637 expect(result.exitCode, equals(1)); |
638 }); | 638 }); |
639 }); | 639 }); |
640 | 640 |
641 group("with the --plain-name flag,", () { | 641 group("with the --plain-name flag,", () { |
642 test("selects tests with matching names", () { | 642 test("selects tests with matching names", () { |
643 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" | 643 new File(p.join(_sandbox, "test.dart")).writeAsStringSync(""" |
644 import 'dart:async'; | 644 import 'dart:async'; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 }); | 685 }); |
686 }); | 686 }); |
687 }); | 687 }); |
688 } | 688 } |
689 | 689 |
690 ProcessResult _runTest(List<String> args) => | 690 ProcessResult _runTest(List<String> args) => |
691 runTest(args, workingDirectory: _sandbox); | 691 runTest(args, workingDirectory: _sandbox); |
692 | 692 |
693 ProcessResult _runDart(List<String> args) => | 693 ProcessResult _runDart(List<String> args) => |
694 runDart(args, workingDirectory: _sandbox); | 694 runDart(args, workingDirectory: _sandbox); |
OLD | NEW |