Chromium Code Reviews| Index: tests/isolate/package_map_test.dart |
| diff --git a/tests/isolate/package_map_test.dart b/tests/isolate/package_map_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e33c7bf27e2639a138f84e2280b47e6817f93eb9 |
| --- /dev/null |
| +++ b/tests/isolate/package_map_test.dart |
| @@ -0,0 +1,65 @@ |
| +// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import 'dart:io'; |
| +import 'dart:isolate'; |
| + |
| +final NOT_HERE = "notHere"; |
| +final NOT_HERE_URI = "file:///no/such/file/"; |
| + |
| +class Foo {} |
| + |
| +void main([args, port]) { |
| + if (port != null) { |
| + testPackageRoot(port); |
| + return; |
| + } |
| + var p = new RawReceivePort(); |
| + p.handler = (msg) { |
| + p.close(); |
| + if (msg is! List) { |
| + throw "Bad response from child isolate: $msg"; |
| + } |
| + if (msg.length != 2) { |
| + throw "Length should be 2: ${msg.length}\nmsg: $msg"; |
| + } |
|
Lasse Reichstein Nielsen
2015/10/12 09:34:44
Add a comment that you are not using the expect pa
|
| + if (msg[0] != NOT_HERE) { |
| + throw "Key should be $NOT_HERE: ${msg[0]}"; |
| + } |
| + if (msg[1] != NOT_HERE_URI) { |
| + throw "Value should be $NOT_HERE_URI: ${msg[1]}"; |
| + } |
| + }; |
| + Isolate.spawnUri(Platform.script, |
| + [], |
| + p.sendPort, |
| + packages: { |
| + NOT_HERE: Uri.parse(NOT_HERE_URI) |
| + }); |
| +} |
| + |
| +testPackageRoot(port) async { |
| + var packageMap = await Isolate.packageMap; |
| + var packageMapEntries = []; |
| + if (packageMap is! Map) { |
| + port.send("packageMap is not a Map: ${packageMap.runtimeType}"); |
| + return; |
| + } |
| + 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
|
| + packageMap.forEach((k, v) { |
| + if (ok && (k is! String)) { |
| + port.send("Key $k is not a String: ${k.runtimeType}"); |
| + ok = false; |
| + } |
| + packageMapEntries.add(k); |
| + if (ok && (v is! Uri)) { |
| + port.send("Value $v is not a Uri: ${v.runtimeType}"); |
| + ok = false; |
| + } |
| + packageMapEntries.add(v.toString()); |
|
Lasse Reichstein Nielsen
2015/10/12 09:34:44
It's slightly surprising that you add the entries
|
| + }); |
| + if (ok) { |
| + port.send(packageMapEntries); |
| + } |
| +} |