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 if (msg is! List) { | |
22 throw "Bad response from child isolate: $msg"; | |
23 } | |
24 if (msg.length != 2) { | |
25 throw "Length should be 2: ${msg.length}\nmsg: $msg"; | |
26 } | |
Lasse Reichstein Nielsen
2015/10/12 09:34:44
Add a comment that you are not using the expect pa
| |
27 if (msg[0] != NOT_HERE) { | |
28 throw "Key should be $NOT_HERE: ${msg[0]}"; | |
29 } | |
30 if (msg[1] != NOT_HERE_URI) { | |
31 throw "Value should be $NOT_HERE_URI: ${msg[1]}"; | |
32 } | |
33 }; | |
34 Isolate.spawnUri(Platform.script, | |
35 [], | |
36 p.sendPort, | |
37 packages: { | |
38 NOT_HERE: Uri.parse(NOT_HERE_URI) | |
39 }); | |
40 } | |
41 | |
42 testPackageRoot(port) async { | |
43 var packageMap = await Isolate.packageMap; | |
44 var packageMapEntries = []; | |
45 if (packageMap is! Map) { | |
46 port.send("packageMap is not a Map: ${packageMap.runtimeType}"); | |
47 return; | |
48 } | |
49 var ok = true; | |
Lasse Reichstein Nielsen
2015/10/12 09:34:44
You don't actually need the ok variable - the firs
Ivan Posva
2015/10/12 16:05:22
I did not want to have an expectation where multip
| |
50 packageMap.forEach((k, v) { | |
51 if (ok && (k is! String)) { | |
52 port.send("Key $k is not a String: ${k.runtimeType}"); | |
53 ok = false; | |
54 } | |
55 packageMapEntries.add(k); | |
56 if (ok && (v is! Uri)) { | |
57 port.send("Value $v is not a Uri: ${v.runtimeType}"); | |
58 ok = false; | |
59 } | |
60 packageMapEntries.add(v.toString()); | |
Lasse Reichstein Nielsen
2015/10/12 09:34:44
It's slightly surprising that you add the entries
| |
61 }); | |
62 if (ok) { | |
63 port.send(packageMapEntries); | |
64 } | |
65 } | |
OLD | NEW |