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