OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import "dart:async"; | 5 import "dart:async"; |
6 import "dart:io"; | 6 import "dart:io"; |
7 import "dart:convert" show JSON; | 7 import "dart:convert" show JSON; |
8 import "package:path/path.dart" as p; | 8 import "package:path/path.dart" as p; |
9 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
10 | 10 |
11 main() async { | 11 main() async { |
12 asyncStart(); | 12 asyncStart(); |
13 | 13 |
14 // The `test` function can generate file or http resources. | 14 Future runTests(test) async { |
floitsch
2016/05/27 14:26:50
Move that function out. Should make the diff bette
| |
15 // It replaces "%file/" with URI of the root directory of generated files and | 15 // The `test` function can generate file or http resources. |
16 // "%http/" with the URI of the HTTP server's root in appropriate contexts | 16 // It replaces "%file/" with URI of the root directory of generated files an d |
floitsch
2016/05/27 14:26:50
Long line.
| |
17 // (all file contents and parameters). | 17 // "%http/" with the URI of the HTTP server's root in appropriate contexts |
18 | 18 // (all file contents and parameters). |
19 // With no specified resolutiuon and no implicit .packages or packages/ | 19 |
20 // available, nothing can be resolved and the package can't be imported. | 20 // With no specified resolutiuon and no implicit .packages or packages/ |
21 await test("file: no resolution", | 21 // available, nothing can be resolved and the package can't be imported. |
22 "%file/main.dart", | 22 await test("file: no resolution", |
23 file: {"main": testMain}, | 23 "%file/main.dart", |
24 expect: {"foo.x": null}); | 24 file: {"main": testMain}, |
25 | 25 expect: {"foo.x": null}); |
26 // An HTTP script with no ".packages" file assumes a "packages" dir. | 26 |
27 // All packages are resolved relative to that dir, whether it exists or not. | 27 // An HTTP script with no ".packages" file assumes a "packages" dir. |
28 await test("http: no resolution", "%http/main.dart", | 28 // All packages are resolved relative to that dir, whether it exists or not. |
29 http: {"main": testMain}, | 29 await test("http: no resolution", "%http/main.dart", |
30 expect: { | 30 http: {"main": testMain}, |
31 "iroot": "%http/packages/", | 31 expect: { |
32 // "foo": null, | 32 "iroot": "%http/packages/", |
33 "foo/": "%http/packages/foo/", | 33 // "foo": null, |
34 "foo/bar": "%http/packages/foo/bar", | 34 "foo/": "%http/packages/foo/", |
35 "foo.x": null, | 35 "foo/bar": "%http/packages/foo/bar", |
36 }); | 36 "foo.x": null, |
37 | 37 }); |
38 // A number of tests which behave similarly whether run as local files or | 38 |
39 // over HTTP. | 39 // A number of tests which behave similarly whether run as local files or |
40 for (var scheme in ["file", "http"]) { | 40 // over HTTP. |
41 | 41 for (var scheme in ["file", "http"]) { |
42 /// Run a test in the current scheme. | 42 |
43 /// | 43 /// Run a test in the current scheme. |
44 /// The files are served either through HTTP or in a local directory. | 44 /// |
45 /// Use "%$scheme/" to refer to the root of the served files. | 45 /// The files are served either through HTTP or in a local directory. |
46 testScheme(name, main, {expect, files, args, root, config}) { | 46 /// Use "%$scheme/" to refer to the root of the served files. |
47 return test("$scheme: $name", main, expect: expect, | 47 testScheme(name, main, {expect, files, args, root, config}) { |
48 root: root, config: config, args: args, | 48 return test("$scheme: $name", main, expect: expect, |
49 file: scheme == "file" ? files : null, | 49 root: root, config: config, args: args, |
50 http: scheme == "http" ? files : null); | 50 file: scheme == "file" ? files : null, |
51 http: scheme == "http" ? files : null); | |
52 } | |
53 | |
54 { | |
55 var files = {"main": testMain, "packages": fooPackage}; | |
56 // Expect implicitly detected package dir. | |
57 await testScheme("implicit packages dir","%$scheme/main.dart", | |
58 files: files, | |
59 expect: { | |
60 "iroot": "%$scheme/packages/", | |
61 // "foo": null, | |
62 "foo/": "%$scheme/packages/foo/", | |
63 "foo/bar": "%$scheme/packages/foo/bar", | |
64 }); | |
65 } | |
66 | |
67 { | |
68 var files = {"sub": {"main": testMain, "packages": fooPackage}, | |
69 ".packages": ""}; | |
70 // Expect implicitly detected package dir. | |
71 // Should not detect the .packages file in parent directory. | |
72 // That file is empty, so if it is used, the system cannot resolve "foo" . | |
73 await testScheme("implicit packages dir 2", "%$scheme/sub/main.dart", | |
74 files: files, | |
75 expect: { | |
76 "iroot": "%$scheme/sub/packages/", | |
77 // "foo": null, | |
78 "foo/": "%$scheme/sub/packages/foo/", | |
79 "foo/bar": "%$scheme/sub/packages/foo/bar", | |
80 }); | |
81 } | |
82 | |
83 { | |
84 var files = {"main": testMain, | |
85 ".packages": "foo:pkgs/foo/", | |
86 "pkgs": fooPackage}; | |
87 await testScheme("implicit .packages file", "%$scheme/main.dart", | |
88 files: files, | |
89 expect: { | |
90 "iconf": "%$scheme/.packages", | |
91 // "foo": null, | |
92 "foo/": "%$scheme/pkgs/foo/", | |
93 "foo/bar": "%$scheme/pkgs/foo/bar", | |
94 }); | |
95 } | |
96 | |
97 { | |
98 var files = {"main": testMain, | |
99 ".packages": "foo:packages/foo/", | |
100 "packages": fooPackage, | |
101 "pkgs": fooPackage}; | |
102 await testScheme("explicit package root, no slash", "%$scheme/main.dart" , | |
103 files: files, | |
104 root: "%$scheme/pkgs", | |
105 expect: { | |
106 "proot": "%$scheme/pkgs/", | |
107 "iroot": "%$scheme/pkgs/", | |
108 // "foo": null, | |
109 "foo/": "%$scheme/pkgs/foo/", | |
110 "foo/bar": "%$scheme/pkgs/foo/bar", | |
111 }); | |
112 } | |
113 | |
114 { | |
115 var files = {"main": testMain, | |
116 ".packages": "foo:packages/foo/", | |
117 "packages": fooPackage, | |
118 "pkgs": fooPackage}; | |
119 await testScheme("explicit package root, slash", "%$scheme/main.dart", | |
120 files: files, | |
121 root: "%$scheme/pkgs", | |
122 expect: { | |
123 "proot": "%$scheme/pkgs/", | |
124 "iroot": "%$scheme/pkgs/", | |
125 // "foo": null, | |
126 "foo/": "%$scheme/pkgs/foo/", | |
127 "foo/bar": "%$scheme/pkgs/foo/bar", | |
128 }); | |
129 } | |
130 | |
131 { | |
132 var files = {"main": testMain, | |
133 ".packages": "foo:packages/foo/", | |
134 "packages": fooPackage, | |
135 ".pkgs": "foo:pkgs/foo/", | |
136 "pkgs": fooPackage}; | |
137 await testScheme("explicit package config file", "%$scheme/main.dart", | |
138 files: files, | |
139 config: "%$scheme/.pkgs", | |
140 expect: { | |
141 "pconf": "%$scheme/.pkgs", | |
142 "iconf": "%$scheme/.pkgs", | |
143 // "foo": null, | |
144 "foo/": "%$scheme/pkgs/foo/", | |
145 "foo/bar": "%$scheme/pkgs/foo/bar", | |
146 }); | |
147 } | |
148 | |
149 { | |
150 /// The package config can be specified as a data: URI. | |
151 /// (In that case, relative URI references in the config file won't work ). | |
152 var files = {"main": testMain, | |
153 ".packages": "foo:packages/foo/", | |
154 "packages": fooPackage, | |
155 "pkgs": fooPackage}; | |
156 var dataUri = "data:,foo:%$scheme/pkgs/foo/\n"; | |
157 await testScheme("explicit data: config file", "%$scheme/main.dart", | |
158 files: files, | |
159 config: dataUri, | |
160 expect: { | |
161 "pconf": dataUri, | |
162 "iconf": dataUri, | |
163 // "foo": null, | |
164 "foo/": "%$scheme/pkgs/foo/", | |
165 "foo/bar": "%$scheme/pkgs/foo/bar", | |
166 }); | |
167 } | |
51 } | 168 } |
52 | 169 |
53 { | 170 { |
54 var files = {"main": testMain, "packages": fooPackage}; | 171 // With a file: URI, the lookup checks for a .packages file in superdirs |
55 // Expect implicitly detected package dir. | 172 // when it fails to find a ,packages file or packages/ directory next to |
56 await testScheme("implicit packages dir","%$scheme/main.dart", | 173 // the entry point. |
57 files: files, | 174 var files = {"sub": { "main": testMain }, |
175 ".packages": "foo:pkgs/foo/", | |
176 "pkgs": fooPackage}; | |
177 await test("file: implicit .packages file in ..", "%file/sub/main.dart", | |
178 file: files, | |
58 expect: { | 179 expect: { |
59 "iroot": "%$scheme/packages/", | 180 "iconf": "%file/.packages", |
60 // "foo": null, | 181 // "foo": null, |
61 "foo/": "%$scheme/packages/foo/", | 182 "foo/": "%file/pkgs/foo/", |
62 "foo/bar": "%$scheme/packages/foo/bar", | 183 "foo/bar": "%file/pkgs/foo/bar", |
63 }); | 184 }); |
64 } | 185 } |
65 | 186 |
66 { | 187 { |
67 var files = {"sub": {"main": testMain, "packages": fooPackage}, | 188 // With a non-file: URI, the lookup assumes a packges/ dir. |
68 ".packages": ""}; | 189 // The absence of a .packages file next to the entry point means |
69 // Expect implicitly detected package dir. | 190 // that the resolution assumes a packages directory, whether it exists or |
70 // Should not detect the .packages file in parent directory. | 191 // not. It should not find the .packages file in the parent directory. |
71 // That file is empty, so if it is used, the system cannot resolve "foo". | 192 var files = {"sub": { "main": testMain }, |
72 await testScheme("implicit packages dir 2", "%$scheme/sub/main.dart", | |
73 files: files, | |
74 expect: { | |
75 "iroot": "%$scheme/sub/packages/", | |
76 // "foo": null, | |
77 "foo/": "%$scheme/sub/packages/foo/", | |
78 "foo/bar": "%$scheme/sub/packages/foo/bar", | |
79 }); | |
80 } | |
81 | |
82 { | |
83 var files = {"main": testMain, | |
84 ".packages": "foo:pkgs/foo/", | 193 ".packages": "foo:pkgs/foo/", |
85 "pkgs": fooPackage}; | 194 "pkgs": fooPackage}; |
86 await testScheme("implicit .packages file", "%$scheme/main.dart", | 195 await test("http: implicit packages dir", "%http/sub/main.dart", |
87 files: files, | 196 http: files, |
88 expect: { | 197 expect: { |
89 "iconf": "%$scheme/.packages", | 198 "iroot": "%http/sub/packages/", |
90 // "foo": null, | 199 // "foo": null, |
91 "foo/": "%$scheme/pkgs/foo/", | 200 "foo/": "%http/sub/packages/foo/", |
92 "foo/bar": "%$scheme/pkgs/foo/bar", | 201 "foo/bar": "%http/sub/packages/foo/bar", |
93 }); | 202 "foo.x": null, |
94 } | |
95 | |
96 { | |
97 var files = {"main": testMain, | |
98 ".packages": "foo:packages/foo/", | |
99 "packages": fooPackage, | |
100 "pkgs": fooPackage}; | |
101 await testScheme("explicit package root, no slash", "%$scheme/main.dart", | |
102 files: files, | |
103 root: "%$scheme/pkgs", | |
104 expect: { | |
105 "proot": "%$scheme/pkgs/", | |
106 "iroot": "%$scheme/pkgs/", | |
107 // "foo": null, | |
108 "foo/": "%$scheme/pkgs/foo/", | |
109 "foo/bar": "%$scheme/pkgs/foo/bar", | |
110 }); | |
111 } | |
112 | |
113 { | |
114 var files = {"main": testMain, | |
115 ".packages": "foo:packages/foo/", | |
116 "packages": fooPackage, | |
117 "pkgs": fooPackage}; | |
118 await testScheme("explicit package root, slash", "%$scheme/main.dart", | |
119 files: files, | |
120 root: "%$scheme/pkgs", | |
121 expect: { | |
122 "proot": "%$scheme/pkgs/", | |
123 "iroot": "%$scheme/pkgs/", | |
124 // "foo": null, | |
125 "foo/": "%$scheme/pkgs/foo/", | |
126 "foo/bar": "%$scheme/pkgs/foo/bar", | |
127 }); | |
128 } | |
129 | |
130 { | |
131 var files = {"main": testMain, | |
132 ".packages": "foo:packages/foo/", | |
133 "packages": fooPackage, | |
134 ".pkgs": "foo:pkgs/foo/", | |
135 "pkgs": fooPackage}; | |
136 await testScheme("explicit package config file", "%$scheme/main.dart", | |
137 files: files, | |
138 config: "%$scheme/.pkgs", | |
139 expect: { | |
140 "pconf": "%$scheme/.pkgs", | |
141 "iconf": "%$scheme/.pkgs", | |
142 // "foo": null, | |
143 "foo/": "%$scheme/pkgs/foo/", | |
144 "foo/bar": "%$scheme/pkgs/foo/bar", | |
145 }); | |
146 } | |
147 | |
148 { | |
149 /// The package config can be specified as a data: URI. | |
150 /// (In that case, relative URI references in the config file won't work). | |
151 var files = {"main": testMain, | |
152 ".packages": "foo:packages/foo/", | |
153 "packages": fooPackage, | |
154 "pkgs": fooPackage}; | |
155 var dataUri = "data:,foo:%$scheme/pkgs/foo/\n"; | |
156 await testScheme("explicit data: config file", "%$scheme/main.dart", | |
157 files: files, | |
158 config: dataUri, | |
159 expect: { | |
160 "pconf": dataUri, | |
161 "iconf": dataUri, | |
162 // "foo": null, | |
163 "foo/": "%$scheme/pkgs/foo/", | |
164 "foo/bar": "%$scheme/pkgs/foo/bar", | |
165 }); | 203 }); |
166 } | 204 } |
167 } | 205 } |
168 | 206 |
169 { | 207 await runTests(test); |
170 // With a file: URI, the lookup checks for a .packages file in superdirs | 208 await runTests(testSpawn(test)); |
171 // when it fails to find a ,packages file or packages/ directory next to | 209 await runTests(testSpawn(testSpawn(test))); |
172 // the entry point. | |
173 var files = {"sub": { "main": testMain }, | |
174 ".packages": "foo:pkgs/foo/", | |
175 "pkgs": fooPackage}; | |
176 await test("file: implicit .packages file in ..", "%file/sub/main.dart", | |
177 file: files, | |
178 expect: { | |
179 "iconf": "%file/.packages", | |
180 // "foo": null, | |
181 "foo/": "%file/pkgs/foo/", | |
182 "foo/bar": "%file/pkgs/foo/bar", | |
183 }); | |
184 } | |
185 | |
186 { | |
187 // With a non-file: URI, the lookup assumes a packges/ dir. | |
188 // The absence of a .packages file next to the entry point means | |
189 // that the resolution assumes a packages directory, whether it exists or | |
190 // not. It should not find the .packages file in the parent directory. | |
191 var files = {"sub": { "main": testMain }, | |
192 ".packages": "foo:pkgs/foo/", | |
193 "pkgs": fooPackage}; | |
194 await test("http: implicit packages dir", "%http/sub/main.dart", | |
195 http: files, | |
196 expect: { | |
197 "iroot": "%http/sub/packages/", | |
198 // "foo": null, | |
199 "foo/": "%http/sub/packages/foo/", | |
200 "foo/bar": "%http/sub/packages/foo/bar", | |
201 "foo.x": null, | |
202 }); | |
203 } | |
204 | |
205 | 210 |
206 if (failingTests.isNotEmpty) { | 211 if (failingTests.isNotEmpty) { |
207 print("Errors found in tests:\n ${failingTests.join("\n ")}\n"); | 212 print("Errors found in tests:\n ${failingTests.join("\n ")}\n"); |
208 exit(255); | 213 exit(255); |
209 } | 214 } |
210 asyncEnd(); | 215 asyncEnd(); |
211 } | 216 } |
212 | 217 |
213 // --------------------------------------------------------- | 218 // --------------------------------------------------------- |
214 // Helper functionality. | 219 // Helper functionality. |
215 | 220 |
216 var failingTests = new Set(); | 221 var failingTests = new Set(); |
217 | 222 |
218 var fileHttpRegexp = new RegExp(r"%(?:file|http)/"); | 223 var fileHttpRegexp = new RegExp(r"%(?:file|http)/"); |
219 | 224 |
225 typedef Future Test(String name, String main, | |
226 {String root, String config, List<String> args, | |
227 Map file, Map http, Map expect}); | |
228 | |
220 Future test(String name, String main, | 229 Future test(String name, String main, |
221 {String root, String config, List<String> args, | 230 {String root, String config, List<String> args, |
222 Map file, Map http, Map expect}) async { | 231 Map file, Map http, Map expect}) async { |
223 // Default values that are easily recognized in output. | 232 // Default values that are easily recognized in output. |
224 String fileRoot = "<no files configured>"; | 233 String fileRoot = "<no files configured>"; |
225 String httpRoot = "<no http server configured>"; | 234 String httpRoot = "<no http server configured>"; |
226 | 235 |
227 /// Replaces markers `%file/` and `%http/` with the actual locations. | 236 /// Replaces markers `%file/` and `%http/` with the actual locations. |
228 /// | 237 /// |
229 /// Accepts a `null` [source] and returns `null` again. | 238 /// Accepts a `null` [source] and returns `null` again. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 // Unexpected error calling runDart or parsing the result. | 287 // Unexpected error calling runDart or parsing the result. |
279 // Report it and continue. | 288 // Report it and continue. |
280 print("ERROR running $name: $e\n$s"); | 289 print("ERROR running $name: $e\n$s"); |
281 failingTests.add(name); | 290 failingTests.add(name); |
282 } finally { | 291 } finally { |
283 if (https != null) await https.close(); | 292 if (https != null) await https.close(); |
284 if (tmpDir != null) tmpDir.deleteSync(recursive: true); | 293 if (tmpDir != null) tmpDir.deleteSync(recursive: true); |
285 } | 294 } |
286 } | 295 } |
287 | 296 |
297 Test testSpawn(Test test) => | |
298 (String name, String main, | |
299 {String root, String config, List<String> args, | |
300 Map file, Map http, Map expect}) { | |
301 // Add spawnMain file next to main file. | |
302 var spawnMainName = "_spawnMain${tmpNameCounter++}"; | |
303 var parts = main.split('/').toList(); | |
304 var files; | |
305 if (parts[0] == "%file") { | |
306 files = file; | |
307 } else { | |
308 assert(parts[0] == "%http"); | |
309 files = http; | |
310 } | |
311 for (var i = 1; i < parts.length - 1; i++) { | |
312 files = files[parts[i]]; | |
313 } | |
314 files[spawnMainName] = spawnMain.replaceAll("%main", main); | |
315 parts[parts.length - 1] = "$spawnMainName.dart"; | |
316 | |
317 return test("spawn: $name", parts.join("/"), | |
318 root: root, config: config, args: args, | |
319 file: file, http: http, expect: expect); | |
320 }; | |
321 | |
288 | 322 |
289 /// Test that the output of running testMain matches the expectations. | 323 /// Test that the output of running testMain matches the expectations. |
290 /// | 324 /// |
291 /// The output is a string which is parse as a JSON literal. | 325 /// The output is a string which is parse as a JSON literal. |
292 /// The resulting map is always mapping strings to strings, or possibly `null`. | 326 /// The resulting map is always mapping strings to strings, or possibly `null`. |
293 /// The expectations can have non-string values other than null, | 327 /// The expectations can have non-string values other than null, |
294 /// they are `toString`'ed before being compared (so the caller can use a URI | 328 /// they are `toString`'ed before being compared (so the caller can use a URI |
295 /// or a File/Directory directly as an expectation). | 329 /// or a File/Directory directly as an expectation). |
296 void match(Map actuals, Map expectations, String fixPaths(String expectation), | 330 void match(Map actuals, Map expectations, String fixPaths(String expectation), |
297 String name) { | 331 String name) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 const String spawnUriMain = r""" | 386 const String spawnUriMain = r""" |
353 import "dart:isolate"; | 387 import "dart:isolate"; |
354 main(args) async { | 388 main(args) async { |
355 Uri target = Uri.parse(args[0]); | 389 Uri target = Uri.parse(args[0]); |
356 Uri conf = args.length > 1 && args[1].isNotEmpty ? Uri.parse(args[1]) : null; | 390 Uri conf = args.length > 1 && args[1].isNotEmpty ? Uri.parse(args[1]) : null; |
357 Uri root = args.length > 2 && args[2].isNotEmpty ? Uri.parse(args[2]) : null; | 391 Uri root = args.length > 2 && args[2].isNotEmpty ? Uri.parse(args[2]) : null; |
358 var restArgs = args.skip(3).toList(); | 392 var restArgs = args.skip(3).toList(); |
359 var isolate = await Isolate.spawnUri(target, restArgs, | 393 var isolate = await Isolate.spawnUri(target, restArgs, |
360 packageRoot: root, packageConfig: conf, paused: true); | 394 packageRoot: root, packageConfig: conf, paused: true); |
361 // Wait for isolate to exit before exiting the main isolate. | 395 // Wait for isolate to exit before exiting the main isolate. |
362 var done = new RawReceivePort(); | 396 var port = new RawReceivePort(); |
363 done.handler = (_) { done.close(); }; | 397 port.handler = (res) async { |
364 isolate.addExitHandler(done.sendPort); | 398 port.close(); // Close on done or first error. |
399 if (res != null) { | |
400 await new Future.error(res[0], new Stacktrace.fromString(res[1])); | |
401 } | |
402 }; | |
403 isolate.addOnExitListener(port.sendPort); | |
404 isolate.addErrorListener(port.sendPort); | |
365 isolate.resume(isolate.pauseCapability); | 405 isolate.resume(isolate.pauseCapability); |
366 } | 406 } |
367 """; | 407 """; |
368 | 408 |
369 /// Script that spawns a new Isolate using Isolate.spawn. | 409 /// Script that spawns a new Isolate using Isolate.spawn. |
370 const String spawnMain = r""" | 410 const String spawnMain = r""" |
411 import "dart:async"; | |
371 import "dart:isolate"; | 412 import "dart:isolate"; |
372 import "testmain.dart" as test; | 413 import "%main" as test; |
373 main() async { | 414 main([_]) async { |
374 var isolate = await Isolate.spawn(test.main, [], paused: true); | 415 var isolate = await Isolate.spawn(test.main, [], paused: true); |
375 // Wait for isolate to exit before exiting the main isolate. | 416 // Wait for isolate to exit before exiting the main isolate. |
376 var done = new RawReceivePort(); | 417 var port = new RawReceivePort(); |
377 done.handler = (_) { done.close(); }; | 418 port.handler = (res) async { |
378 isolate.addExitHandler(done.sendPort); | 419 port.close(); // Close on port or first error. |
420 if (res != null) { | |
421 await new Future.error(res[0], new Stacktrace.fromString(res[1])); | |
422 } | |
423 }; | |
424 isolate.addOnExitListener(port.sendPort); | |
425 isolate.addErrorListener(port.sendPort); | |
379 isolate.resume(isolate.pauseCapability); | 426 isolate.resume(isolate.pauseCapability); |
380 } | 427 } |
381 """; | 428 """; |
382 | 429 |
383 /// A package directory containing only one package, "foo", with one file. | 430 /// A package directory containing only one package, "foo", with one file. |
384 const Map fooPackage = const { "foo": const { "foo": "var x = 'qux';" }}; | 431 const Map fooPackage = const { "foo": const { "foo": "var x = 'qux';" }}; |
385 | 432 |
386 /// Runs the Dart executable with the provided parameters. | 433 /// Runs the Dart executable with the provided parameters. |
387 /// | 434 /// |
388 /// Captures and returns the output. | 435 /// Captures and returns the output. |
389 Future<String> runDart(String script, | 436 Future<String> runDart(String script, |
390 {String root, String config, | 437 {String root, String config, |
391 Iterable<String> scriptArgs}) async { | 438 Iterable<String> scriptArgs}) async { |
439 var checked = false; | |
440 assert((checked = true)); | |
floitsch
2016/05/27 14:26:50
Add a comment.
| |
392 // TODO: Find a way to change CWD before running script. | 441 // TODO: Find a way to change CWD before running script. |
393 var executable = Platform.executable; | 442 var executable = Platform.executable; |
394 var args = []; | 443 var args = []; |
395 if (root != null) args..add("-p")..add(root); | 444 if (checked) args.add("--checked"); |
396 if (config != null) args..add("--packages=$config"); | 445 if (root != null) args.add("--package-root=$root"); |
446 if (config != null) args.add("--packages=$config"); | |
397 args.add(script); | 447 args.add(script); |
398 if (scriptArgs != null) { | 448 if (scriptArgs != null) { |
399 args.addAll(scriptArgs); | 449 args.addAll(scriptArgs); |
400 } | 450 } |
401 return Process.run(executable, args).then((results) { | 451 return Process.run(executable, args).then((results) { |
402 if (results.exitCode != 0) { | 452 if (results.exitCode != 0) { |
403 throw results.stderr; | 453 throw results.stderr; |
404 } | 454 } |
405 return results.stdout; | 455 return results.stdout; |
406 }); | 456 }); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 } | 534 } |
485 } | 535 } |
486 request.response..statusCode = HttpStatus.NOT_FOUND | 536 request.response..statusCode = HttpStatus.NOT_FOUND |
487 ..close(); | 537 ..close(); |
488 }); | 538 }); |
489 } | 539 } |
490 | 540 |
491 // Counter used to avoid reusing temporary directory names. | 541 // Counter used to avoid reusing temporary directory names. |
492 // Some platforms are timer based, and creating two temp-dirs withing a short | 542 // Some platforms are timer based, and creating two temp-dirs withing a short |
493 // duration may cause a collision. | 543 // duration may cause a collision. |
494 int tmpDirCounter = 0; | 544 int tmpNameCounter = 0; |
495 | 545 |
496 Directory createTempDir() { | 546 Directory createTempDir() { |
497 return Directory.systemTemp.createTempSync("pftest-${tmpDirCounter++}-"); | 547 return Directory.systemTemp.createTempSync("pftest-${tmpNameCounter++}-"); |
498 } | 548 } |
OLD | NEW |