OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:io'; |
| 6 import 'dart:isolate'; |
| 7 |
| 8 final SPAWN_PACKAGE_ROOT = "file:///no/such/package/root/"; |
| 9 final PACKAGE_URI = "package:foo/bar.dart"; |
| 10 final PACKAGE_PATH = "file:///no/such/package/root/foo/bar.dart"; |
| 11 |
| 12 void main([args, port]) async { |
| 13 if (port != null) { |
| 14 testPackageResolution(port); |
| 15 return; |
| 16 } |
| 17 var p = new RawReceivePort(); |
| 18 Isolate.spawnUri(Platform.script, |
| 19 [], |
| 20 p.sendPort, |
| 21 packageRoot: Uri.parse(SPAWN_PACKAGE_ROOT)); |
| 22 p.handler = (msg) { |
| 23 p.close(); |
| 24 if (msg is! List) { |
| 25 print(msg.runtimeType); |
| 26 throw "Failure return from spawned isolate:\n\n$msg"; |
| 27 } |
| 28 if (msg[0] != SPAWN_PACKAGE_ROOT) { |
| 29 throw "Bad package root in child isolate: ${msg[0]}"; |
| 30 } |
| 31 if (msg[1] != PACKAGE_PATH) { |
| 32 throw "Package path not matching: ${msg[1]}"; |
| 33 } |
| 34 print("SUCCESS"); |
| 35 }; |
| 36 print("Spawning isolate's package root: ${await Isolate.packageRoot}"); |
| 37 } |
| 38 |
| 39 testPackageResolution(port) async { |
| 40 try { |
| 41 var packageRootStr = Platform.packageRoot; |
| 42 var packageRoot = await Isolate.packageRoot; |
| 43 var resolvedPkg = await Isolate.resolvePackageUri(Uri.parse(PACKAGE_URI)); |
| 44 print("Spawned isolate's package root flag: $packageRootStr"); |
| 45 print("Spawned isolate's loaded package root: $packageRoot"); |
| 46 print("Spawned isolate's resolved package path: $resolvedPkg"); |
| 47 port.send([packageRoot?.toString(), resolvedPkg?.toString()]); |
| 48 } catch (e, s) { |
| 49 port.send("$e\n$s\n"); |
| 50 } |
| 51 } |
OLD | NEW |