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:isolate"; | |
8 import "dart:convert" show JSON; | 7 import "dart:convert" show JSON; |
9 import "package:path/path.dart" as p; | 8 import "package:path/path.dart" as p; |
10 import "package:expect/expect.dart"; | |
11 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
12 | 10 |
13 main() async { | 11 main() async { |
14 asyncStart(); | 12 asyncStart(); |
15 | 13 |
16 await test("file: no resolution", | 14 await test("file: no resolution", |
17 "%file/main.dart", | 15 "%file/main.dart", |
18 file: {"main": testMain}, | 16 file: {"main": testMain}, |
19 expect: {"foo.x": null}); | 17 expect: {"foo.x": null}); |
20 | 18 |
21 // An HTTP script with no ".packages" file assumes a "packages" dir. | 19 // An HTTP script with no ".packages" file assumes a "packages" dir. |
22 await test("http: no resolution", "%http/main.dart", | 20 await test("http: no resolution", "%http/main.dart", |
23 http: {"main": testMain}, | 21 http: {"main": testMain}, |
24 expect: { | 22 expect: { |
| 23 "iroot": "%http/packages/", |
25 // "foo": null, | 24 // "foo": null, |
26 "foo/": "%http/packages/foo/", | 25 "foo/": "%http/packages/foo/", |
27 "foo/bar": "%http/packages/foo/bar", | 26 "foo/bar": "%http/packages/foo/bar", |
28 "foo.x": null, | 27 "foo.x": null, |
29 }); | 28 }); |
30 | 29 |
31 for (var scheme in ["file", "http"]) { | 30 for (var scheme in ["file", "http"]) { |
32 | 31 |
33 testScheme(name, main, {expect, files, args, root, config}) { | 32 testScheme(name, main, {expect, files, args, root, config}) { |
34 return test("$scheme: $name", main, expect: expect, | 33 return test("$scheme: $name", main, expect: expect, |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 scriptArgs: args?.map(fixPaths)); | 238 scriptArgs: args?.map(fixPaths)); |
240 // These expectations are default. If not overridden the value will be | 239 // These expectations are default. If not overridden the value will be |
241 // expected to be null. That is, you can't avoid testing the actual | 240 // expected to be null. That is, you can't avoid testing the actual |
242 // value of these, you can only change what value to expect. | 241 // value of these, you can only change what value to expect. |
243 // For values not included here (commented out), the result is not tested | 242 // For values not included here (commented out), the result is not tested |
244 // unless a value (maybe null) is provided. | 243 // unless a value (maybe null) is provided. |
245 var expects = { | 244 var expects = { |
246 "pconf": null, | 245 "pconf": null, |
247 "proot": null, | 246 "proot": null, |
248 "iconf": null, | 247 "iconf": null, |
249 "iconf": null, | 248 "iroot": null, |
250 // "foo": null, | 249 // "foo": null, |
251 "foo/": null, | 250 "foo/": null, |
252 "foo/bar": null, | 251 "foo/bar": null, |
253 "foo.x": "qux", | 252 "foo.x": "qux", |
254 }..addAll(expect); | 253 }..addAll(expect); |
255 match(JSON.decode(output), expects, fixPaths, name); | 254 match(JSON.decode(output), expects, fixPaths, name); |
256 } catch (e) { | 255 } catch (e, s) { |
257 // Unexpected error calling runDart or parsing the result. | 256 // Unexpected error calling runDart or parsing the result. |
258 // Report it and continue. | 257 // Report it and continue. |
259 print("ERROR running $name: $e\n$s"); | 258 print("ERROR running $name: $e\n$s"); |
260 failingTests.add(name); | 259 failingTests.add(name); |
261 } finally { | 260 } finally { |
262 if (https != null) await https.close(); | 261 if (https != null) await https.close(); |
263 if (tmpDir != null) tmpDir.deleteSync(recursive: true); | 262 if (tmpDir != null) tmpDir.deleteSync(recursive: true); |
264 } | 263 } |
265 } | 264 } |
266 | 265 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 } | 467 } |
469 | 468 |
470 // Counter used to avoid reusing temporary directory names. | 469 // Counter used to avoid reusing temporary directory names. |
471 // Some platforms are timer based, and creating two temp-dirs withing a short | 470 // Some platforms are timer based, and creating two temp-dirs withing a short |
472 // duration may cause a collision. | 471 // duration may cause a collision. |
473 int tmpDirCounter = 0; | 472 int tmpDirCounter = 0; |
474 | 473 |
475 Directory createTempDir() { | 474 Directory createTempDir() { |
476 return Directory.systemTemp.createTempSync("pftest-${tmpDirCounter++}-"); | 475 return Directory.systemTemp.createTempSync("pftest-${tmpDirCounter++}-"); |
477 } | 476 } |
OLD | NEW |