Files
sdk/tests/lib/isolate/package_resolve_test.dart
T
Martin Kustermann a94b8ae45d Reland "[vm] Make VM support .dart_tool/package_config.json"
This relands the following CLs

    [vm] Make VM support .dart_tool/package_config.json
    https://dart-review.googlesource.com/c/sdk/+/145462

    [vm] Make Isolate.resolveUri() work for both `.packages` and `dart_tool/package_config.json`
    https://dart-review.googlesource.com/c/sdk/+/145803

    [vm] Skip (newly enabled) isolate tests on simarm* and hot-reload configs
    https://dart-review.googlesource.com/c/sdk/+/145861

    [vm] Remove ../0 postfix from status file entries (test framework does not recognize those multitests)
    https://dart-review.googlesource.com/c/sdk/+/145940

    [vm] - Fix hang when no package config or .packages exist
    https://dart-review.googlesource.com/c/sdk/+/145661

The only change (extra patchset) is to let VM prefer the old/legacy
".packages" format and only use the newer
".dart_tool/package_config.json" if we failed to find a ".packages".

Closes https://github.com/dart-lang/sdk/issues/41739
Closes https://github.com/dart-lang/sdk/issues/41649

Change-Id: I220f808540e6e521d985ae763968f64dbf57fe67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145942
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-05-04 14:51:14 +00:00

76 lines
2.1 KiB
Dart

// Copyright (c) 2016, 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.
// VMOptions=--enable-isolate-groups
// VMOptions=--no-enable-isolate-groups
import 'dart:io';
import 'dart:isolate';
final packageUriToResolve = "package:foo/bar.dart";
final packageResolvedUri = "file:///no/such/directory/lib/bar.dart";
final dotPackages = """
# This is the content of a .packages file.
foo:file:///no/such/directory/lib/
""";
final packageConfigJson = """
{
"configVersion": 2,
"packages": [
{
"name": "foo",
"rootUri": "file:///no/such/directory",
"packageUri": "lib/",
"languageVersion": "2.7"
}
]
}
""";
main([args, port]) async {
if (port != null) {
testPackageResolution(port);
return;
}
await runTest(dotPackages);
await runTest(packageConfigJson);
}
Future runTest(String packageConfig) async {
final data = Uri.dataFromString(packageConfig);
final port = ReceivePort();
await Isolate.spawnUri(Platform.script, [], port.sendPort,
packageConfig: data);
final msg = await port.first;
if (msg is! List) {
print(msg.runtimeType);
throw "Failure return from spawned isolate:\n\n$msg";
}
if (msg[0] != data.toString()) {
throw "Bad package config in child isolate: ${msg[0]}\n"
"Expected: $data";
}
if (msg[1] != packageResolvedUri) {
throw "Package path not matching: ${msg[1]}";
}
print("SUCCESS");
}
testPackageResolution(port) async {
try {
var packageConfigStr = Platform.packageConfig;
var packageConfig = await Isolate.packageConfig;
var resolvedPkg =
await Isolate.resolvePackageUri(Uri.parse(packageUriToResolve));
print("Spawned isolate's package config flag: $packageConfigStr");
print("Spawned isolate's loaded package config: $packageConfig");
print("Spawned isolate's resolved package path: $resolvedPkg");
port.send([packageConfig?.toString(), resolvedPkg?.toString()]);
} catch (e, s) {
port.send("$e\n$s\n");
}
}