| 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 // PackageRoot=none | 5 // PackageRoot=none |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
| 9 | 9 |
| 10 import "package:foo/foo.dart"; | |
| 11 import "package:bar/bar.dart"; | |
| 12 | |
| 13 var CONFIG_URI = "package:bar/package.config"; | |
| 14 | |
| 15 main([args, port]) async { | 10 main([args, port]) async { |
| 16 if (port != null) { | 11 if (port != null) { |
| 17 testCorrectBarPackage(port); | 12 testBadResolvePackage(port); |
| 18 return; | 13 return; |
| 19 } | 14 } |
| 20 var p = new RawReceivePort(); | 15 var p = new RawReceivePort(); |
| 21 Isolate.spawnUri(Platform.script, | 16 Isolate.spawnUri(Platform.script, [], p.sendPort); |
| 22 [], | |
| 23 p.sendPort, | |
| 24 packageConfig: Uri.parse(CONFIG_URI)); | |
| 25 p.handler = (msg) { | 17 p.handler = (msg) { |
| 26 p.close(); | 18 p.close(); |
| 27 if (msg is! List) { | 19 if (msg is! List) { |
| 28 print(msg.runtimeType); | 20 print(msg.runtimeType); |
| 29 throw "Failure return from spawned isolate:\n\n$msg"; | 21 throw "Failure return from spawned isolate:\n\n$msg"; |
| 30 } | 22 } |
| 31 if (msg[0] != "Foo") { | 23 // Expecting a null resolution for inexistent package mapping. |
| 24 if (msg[0] != null) { |
| 32 throw "Bad package config in child isolate: ${msg[0]}\n" | 25 throw "Bad package config in child isolate: ${msg[0]}\n" |
| 33 "Expected: 'Foo'"; | 26 "Expected: 'Foo'"; |
| 34 } | 27 } |
| 35 if (msg[1] != "Bar2") { | |
| 36 throw "Package path not matching: ${msg[1]}\n" | |
| 37 "Expected: 'Bar2'"; | |
| 38 } | |
| 39 print("SUCCESS"); | 28 print("SUCCESS"); |
| 40 }; | 29 }; |
| 41 if (Bar.value != "Bar1") { | |
| 42 throw "Spawning isolate package:bar invalid."; | |
| 43 } | |
| 44 print("Spawned isolate resolved $CONFIG_URI to: " | |
| 45 "${await Isolate.resolvePackageUri(Uri.parse(CONFIG_URI))}"); | |
| 46 } | 30 } |
| 47 | 31 |
| 48 testCorrectBarPackage(port) async { | 32 testBadResolvePackage(port) async { |
| 49 try { | 33 try { |
| 50 var packageRootStr = Platform.packageRoot; | 34 var packageRootStr = Platform.packageRoot; |
| 51 var packageConfigStr = Platform.packageConfig; | 35 var packageConfigStr = Platform.packageConfig; |
| 52 var packageConfig = await Isolate.packageConfig; | 36 var packageConfig = await Isolate.packageConfig; |
| 53 var resolvedPkg = await Isolate.resolvePackageUri(Uri.parse(CONFIG_URI)); | 37 var badPackageUri = Uri.parse("package:asdf/qwerty.dart"); |
| 38 var resolvedPkg = await Isolate.resolvePackageUri(badPackageUri); |
| 54 print("Spawned isolate's package root flag: $packageRootStr"); | 39 print("Spawned isolate's package root flag: $packageRootStr"); |
| 55 print("Spawned isolate's package config flag: $packageConfigStr"); | 40 print("Spawned isolate's package config flag: $packageConfigStr"); |
| 56 print("Spawned isolate's loaded package config: $packageConfig"); | 41 print("Spawned isolate's loaded package config: $packageConfig"); |
| 57 print("Spawned isolate's resolved package path: $resolvedPkg"); | 42 print("Spawned isolate's resolved package path: $resolvedPkg"); |
| 58 port.send([Foo.value, Bar.value]); | 43 port.send([resolvedPkg]); |
| 59 } catch (e, s) { | 44 } catch (e, s) { |
| 60 port.send("$e\n$s\n"); | 45 port.send("$e\n$s\n"); |
| 61 } | 46 } |
| 62 } | 47 } |
| OLD | NEW |