dart-sdk/tests/lib/isolate/package_config_getter_test.dart
Martin Kustermann 57e54cdd31 [vm/isolate] Prefer .dart_tool/package_config.json over .packages
Flutter has migrated away from using the discontinued
`package:package_resolver`, see [0], which should allow us to prefer the new
`.dart_tool/package_config.json` format now.

[0] https://github.com/flutter/flutter/issues/56289

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

Change-Id: I9026af05756d01f4a3e0e0fc97fa77d27bf805b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/146840
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-05-11 17:32:07 +00:00

47 lines
1.6 KiB
Dart

// Copyright (c) 2020, 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 'package:path/path.dart' as path;
import 'spawn_uri__package_uri__test.dart';
final executable = Platform.executable;
main() async {
// Make a folder structure that has both ".dart_tool/package_config.json" and
// ".packages" and ensure VM prefers to use ".packages".
await withTempDir((String tempDir) async {
// Setup bogus ".packages" with "foo -> ..." with invalid mapping.
final dotPackagesPath = path.join(tempDir, '.packages');
final dotPackagesFile = File(dotPackagesPath);
await dotPackagesFile.writeAsString(buildDotPackages('invalid'));
// Setup ".dart_tool/package_config.json".
final dotDartToolDir = path.join(tempDir, '.dart_tool');
await Directory(dotDartToolDir).create();
final packageConfigJsonPath =
path.join(dotDartToolDir, 'package_config.json');
final packageConfigJsonFile = File(packageConfigJsonPath);
await packageConfigJsonFile.writeAsString(buildPackageConfig('foo', true));
final mainFile = path.join(tempDir, 'main.dart');
await File(mainFile).writeAsString('''
import 'dart:io' as io;
import 'dart:isolate';
main() async {
final uri = await Isolate.packageConfig;
final expectedUri = Uri.parse('${packageConfigJsonFile.uri}');
if (uri != expectedUri) {
throw 'VM should use .packages file (but used \$uri).';
}
}
''');
await run(executable, [mainFile]);
});
}