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 NOT_HERE = "notHere"; | |
9 final NOT_HERE_URI = "file:///no/such/file/"; | |
10 | |
11 class Foo {} | |
12 | |
13 void main([args, port]) { | |
14 if (port != null) { | |
15 testPackageRoot(port); | |
16 return; | |
17 } | |
18 var p = new RawReceivePort(); | |
19 p.handler = (msg) { | |
20 p.close(); | |
21 // Cannot use the expect package here because the spawned isolate | |
22 // would not be able to handle it. | |
23 if (msg is! List) { | |
24 throw "Bad response from child isolate: $msg"; | |
25 } | |
26 if (msg.length != 2) { | |
27 throw "Length should be 2: ${msg.length}\nmsg: $msg"; | |
28 } | |
29 if (msg[0] != NOT_HERE) { | |
30 throw "Key should be $NOT_HERE: ${msg[0]}"; | |
31 } | |
32 if (msg[1] != NOT_HERE_URI) { | |
33 throw "Value should be $NOT_HERE_URI: ${msg[1]}"; | |
34 } | |
35 }; | |
36 Isolate.spawnUri(Platform.script, | |
37 [], | |
38 p.sendPort, | |
39 packageMap: { | |
40 NOT_HERE: Uri.parse(NOT_HERE_URI) | |
41 }); | |
42 } | |
43 | |
44 testPackageRoot(port) async { | |
45 var packageMap = await Isolate.packageMap; | |
46 var packageMapEntries = []; | |
47 if (packageMap is! Map) { | |
48 port.send("packageMap is not a Map: ${packageMap.runtimeType}"); | |
49 return; | |
50 } | |
51 var ok = true; | |
52 packageMap.forEach((k, v) { | |
53 if (ok && (k is! String)) { | |
54 port.send("Key $k is not a String: ${k.runtimeType}"); | |
55 ok = false; | |
56 } | |
57 packageMapEntries.add(k); | |
58 if (ok && (v is! Uri)) { | |
59 port.send("Value $v is not a Uri: ${v.runtimeType}"); | |
60 ok = false; | |
61 } | |
62 packageMapEntries.add(v.toString()); | |
63 }); | |
64 if (ok) { | |
65 port.send(packageMapEntries); | |
66 } | |
67 } | |
OLD | NEW |