Update resolveFile2() to accept File instead of String.

Change-Id: I5ded2930457ef963fa3e53895ae3b46ace2b75c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333700
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2023-11-02 20:15:42 +00:00
parent dfdadb83b8
commit c2ef69dff5
21 changed files with 84 additions and 93 deletions

View file

@ -347,21 +347,18 @@ void main() {
}
test_locate_PartOfDirective_withName() async {
var libPath = convertPath('$testPackageLibPath/lib.dart');
var partPath = convertPath('$testPackageLibPath/test.dart');
newFile(libPath, r'''
final libFile = newFile('$testPackageLibPath/lib.dart', r'''
library my.lib;
part 'test.dart';
''');
newFile(partPath, r'''
final partFile = newFile('$testPackageLibPath/test.dart', r'''
part of my.lib;
''');
await resolveFile(libPath);
await resolveFile(libFile.path);
await resolveFile2(partPath);
await resolveFile2(partFile);
var node = findNode.partOf('part of');
var element = ElementLocator.locate(node);
expect(element, isLibraryElement);

View file

@ -2443,7 +2443,7 @@ void func() {
// No resolved files yet.
_assertResolvedFiles([]);
await resolveFile2(testFile.path);
await resolveFile2(testFile);
var result1 = result;
// The file was resolved.
@ -2453,7 +2453,7 @@ void func() {
expect(fileResolver.cachedResults, contains(testFile.path));
// Ask again, no changes, not resolved.
await resolveFile2(testFile.path);
await resolveFile2(testFile);
_assertResolvedFiles([]);
// The same result was returned.
@ -2464,7 +2464,7 @@ void func() {
fileResolver.changeFiles([a_path]);
// The was a change to a file, no matter which, resolve again.
await resolveFile2(testFile.path);
await resolveFile2(testFile);
_assertResolvedFiles([testFile]);
// Get should get a new result.

View file

@ -30,7 +30,7 @@ import augment 'c.dart';
library augment 'b.dart';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertNoErrorsInResult();
final node = findNode.augmentationImportDirective('c.dart');
@ -62,7 +62,7 @@ import augment 'c.dart' /*2*/;
library augment 'b.dart';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.DUPLICATE_AUGMENTATION_IMPORT, 66, 8),
]);
@ -93,7 +93,7 @@ import augment 'c.dart';
newFile('$testPackageLibPath/c.dart', '');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.IMPORT_OF_NOT_AUGMENTATION, 41, 8),
]);
@ -122,7 +122,7 @@ library augment 'a.dart';
import augment ':net';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.INVALID_URI, 41, 6),
]);
@ -151,7 +151,7 @@ library augment 'a.dart';
import augment '${'foo'}.dart';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.URI_WITH_INTERPOLATION, 41, 15),
]);
@ -190,7 +190,7 @@ library augment 'a.dart';
import augment 'foo:bar';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.URI_DOES_NOT_EXIST, 41, 9),
]);

View file

@ -27,7 +27,7 @@ library augment 'a.dart';
newFile('$testPackageLibPath/c.dart', '');
await resolveFile2(b.path);
await resolveFile2(b);
assertNoErrorsInResult();
final node = findNode.libraryAugmentation('a.dart');

View file

@ -28,7 +28,7 @@ export 'c.dart';
newFile('$testPackageLibPath/c.dart', '');
await resolveFile2(b.path);
await resolveFile2(b);
assertNoErrorsInResult();
final node = findNode.export('c.dart');
@ -54,7 +54,7 @@ library augment 'a.dart';
export 'c.dart';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.URI_DOES_NOT_EXIST, 33, 8),
]);
@ -82,7 +82,7 @@ library augment 'a.dart';
export ':net';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.INVALID_URI, 33, 6),
]);
@ -110,7 +110,7 @@ library augment 'a.dart';
export '${'foo'}.dart';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.URI_WITH_INTERPOLATION, 33, 15),
]);
@ -148,7 +148,7 @@ library augment 'a.dart';
export 'foo:bar';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.URI_DOES_NOT_EXIST, 33, 9),
]);
@ -180,7 +180,7 @@ export 'c.dart';
library augment 'b.dart';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, 33, 8),
]);
@ -212,7 +212,7 @@ export 'c.dart';
part of my.lib;
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, 33, 8),
]);
@ -244,7 +244,7 @@ export 'c.dart';
part of 'b.dart';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, 33, 8),
]);

View file

@ -27,7 +27,7 @@ import 'c.dart';
newFile('$testPackageLibPath/c.dart', '');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(WarningCode.UNUSED_IMPORT, 33, 8),
]);
@ -55,7 +55,7 @@ library augment 'a.dart';
import 'c.dart';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.URI_DOES_NOT_EXIST, 33, 8),
]);
@ -83,7 +83,7 @@ library augment 'a.dart';
import ':net';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.INVALID_URI, 33, 6),
]);
@ -111,7 +111,7 @@ library augment 'a.dart';
import '${'foo'}.dart';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.URI_WITH_INTERPOLATION, 33, 15),
]);
@ -149,7 +149,7 @@ library augment 'a.dart';
import 'foo:bar';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.URI_DOES_NOT_EXIST, 33, 9),
]);
@ -181,7 +181,7 @@ import 'c.dart';
library augment 'b.dart';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY, 33, 8),
]);
@ -213,7 +213,7 @@ import 'c.dart';
part of my.lib;
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY, 33, 8),
]);
@ -245,7 +245,7 @@ import 'c.dart';
part of 'b.dart';
''');
await resolveFile2(b.path);
await resolveFile2(b);
assertErrorsInResult([
error(CompileTimeErrorCode.IMPORT_OF_NON_LIBRARY, 33, 8),
]);

View file

@ -216,7 +216,7 @@ const foo = 42;
library augment 'test.dart';
''');
await resolveFile2(a.path);
await resolveFile2(a);
assertNoErrorsInResult();
_assertAtFoo42();
@ -357,7 +357,7 @@ const foo = 42;
part of 'test.dart';
''');
await resolveFile2(a.path);
await resolveFile2(a);
assertNoErrorsInResult();
_assertAtFoo42();

View file

@ -157,7 +157,7 @@ void foo() {}
class A {}
''');
await resolveFile2(a.path);
await resolveFile2(a);
final node = findNode.singleMethodInvocation;
assertResolvedNodeText(node, r'''

View file

@ -451,11 +451,9 @@ mixin ResolutionTest implements ResourceProviderMixin {
Future<ResolvedUnitResult> resolveFile(String path);
/// Resolve the file with the [path] into [result].
Future<void> resolveFile2(String path) async {
path = convertPath(path);
result = await resolveFile(path);
/// Resolve [file] into [result].
Future<void> resolveFile2(File file) async {
result = await resolveFile(file.path);
findNode = FindNode(result.content, result.unit);
findElement = FindElement(result.unit);
@ -463,8 +461,8 @@ mixin ResolutionTest implements ResourceProviderMixin {
/// Create a new file with the [path] and [content], resolve it into [result].
Future<void> resolveFileCode(String path, String content) {
newFile(path, content);
return resolveFile2(path);
final file = newFile(path, content);
return resolveFile2(file);
}
/// Put the [code] into the test file, and resolve it.
@ -474,7 +472,7 @@ mixin ResolutionTest implements ResourceProviderMixin {
}
Future<void> resolveTestFile() {
return resolveFile2(testFile.path);
return resolveFile2(testFile);
}
/// Choose the type display string, depending on whether the [result] is

View file

@ -160,7 +160,7 @@ part 'a.dart';
error(CompileTimeErrorCode.INCONSISTENT_LANGUAGE_VERSION_OVERRIDE, 5, 8),
]);
await resolveFile2(a.path);
await resolveFile2(a);
final node = findNode.switchStatement('switch');
assertResolvedNodeText(node, r'''

View file

@ -31,7 +31,7 @@ import augment 'a.dart';
class A {}
''');
await resolveFile2(a.path);
await resolveFile2(a);
nodeTextConfiguration.withInterfaceTypeElements = true;
@ -61,7 +61,7 @@ import augment 'a.dart';
mixin M {}
''');
await resolveFile2(a.path);
await resolveFile2(a);
assertNoErrorsInResult();
nodeTextConfiguration.withInterfaceTypeElements = true;

View file

@ -172,7 +172,7 @@ class A {
await resolveTestFile();
assertNoErrorsInResult();
await resolveFile2(a.path);
await resolveFile2(a);
assertNoErrorsInResult();
}
@ -196,7 +196,7 @@ class A {
await resolveTestFile();
assertNoErrorsInResult();
await resolveFile2(a.path);
await resolveFile2(a);
assertErrorsInResult([
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 55, 3,
contextMessages: [message('/home/test/lib/test.dart', 43, 3)]),
@ -1591,7 +1591,7 @@ mixin A {
await resolveTestFile();
assertNoErrorsInResult();
await resolveFile2(a.path);
await resolveFile2(a);
assertNoErrorsInResult();
}
@ -1615,7 +1615,7 @@ mixin A {
await resolveTestFile();
assertNoErrorsInResult();
await resolveFile2(a.path);
await resolveFile2(a);
assertErrorsInResult([
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 55, 3,
contextMessages: [message('/home/test/lib/test.dart', 43, 3)]),
@ -2150,7 +2150,7 @@ class A {}
await resolveTestFile();
assertNoErrorsInResult();
await resolveFile2(a.path);
await resolveFile2(a);
assertNoErrorsInResult();
}
@ -2170,7 +2170,7 @@ mixin A {}
await resolveTestFile();
assertNoErrorsInResult();
await resolveFile2(a.path);
await resolveFile2(a);
assertNoErrorsInResult();
}

View file

@ -48,7 +48,7 @@ class A implements MapEntry<int, int> {
}
''');
await resolveFile2(a.path);
await resolveFile2(a);
assertNoErrorsInResult();
await assertNoErrorsInCode(r'''

View file

@ -47,7 +47,7 @@ class A implements MapEntry<int, int> {
}
''');
await resolveFile2(a.path);
await resolveFile2(a);
assertNoErrorsInResult();
await assertErrorsInCode(r'''

View file

@ -30,28 +30,28 @@ import 'dart:_internal';
}
test_wasm_fromJs() async {
var filePath = _inPackage('js');
newFile(filePath, '''
var filePath = _pathInPackage('js');
final file = newFile(filePath, '''
import 'dart:_wasm';
''');
await resolveFile2(filePath);
await resolveFile2(file);
assertErrorsInResolvedUnit(result, [
error(WarningCode.UNUSED_IMPORT, 7, 12),
]);
}
test_wasm_fromUi() async {
var filePath = _inPackage('ui');
newFile(filePath, '''
var filePath = _pathInPackage('ui');
final file = newFile(filePath, '''
import 'dart:_wasm';
''');
await resolveFile2(filePath);
await resolveFile2(file);
assertErrorsInResolvedUnit(result, [
error(WarningCode.UNUSED_IMPORT, 7, 12),
]);
}
String _inPackage(String packageName) {
String _pathInPackage(String packageName) {
var packageRoot = '$workspaceRootPath/$packageName';
var builder = PackageConfigFileBuilder();
builder.add(
@ -61,6 +61,6 @@ import 'dart:_wasm';
);
var path = '$packageRoot/.dart_tool/package_config.json';
writePackageConfig(path, builder);
return convertPath('$packageRoot/lib/$packageName.dart');
return '$packageRoot/lib/$packageName.dart';
}
}

View file

@ -45,12 +45,12 @@ import 'package:meta/meta.dart';
@internal
class A {}
''');
newFile('$fooPackageRootPath/lib/a.dart', '''
final a = newFile('$fooPackageRootPath/lib/a.dart', '''
import 'src/a.dart';
A a = A();
''');
await resolveFile2('$fooPackageRootPath/lib/a.dart');
await resolveFile2(a);
assertNoErrorsInResult();
}
@ -61,12 +61,12 @@ import 'package:meta/meta.dart';
@internal
extension type E(int i) {}
''');
newFile('$fooPackageRootPath/lib/a.dart', '''
final a = newFile('$fooPackageRootPath/lib/a.dart', '''
import 'src/a.dart';
E e = E(1);
''');
await resolveFile2('$fooPackageRootPath/lib/a.dart');
await resolveFile2(a);
assertNoErrorsInResult();
}

View file

@ -50,57 +50,57 @@ mixin Bar on Foo {}
}
test_withinPackageLibDirectory_OK() async {
newFile('$testPackageLibPath/lib1.dart', r'''
final lib1 = newFile('$testPackageLibPath/lib1.dart', r'''
import 'package:meta/meta.dart';
@sealed class Foo {}
''');
newFile('$testPackageLibPath/src/lib2.dart', r'''
final lib2 = newFile('$testPackageLibPath/src/lib2.dart', r'''
import '../lib1.dart';
mixin Bar on Foo {}
''');
await resolveFile2('$testPackageLibPath/lib1.dart');
await resolveFile2(lib1);
assertNoErrorsInResult();
await resolveFile2('$testPackageLibPath/src/lib2.dart');
await resolveFile2(lib2);
assertNoErrorsInResult();
}
test_withinPackageTestDirectory_OK() async {
newFile('$testPackageLibPath/lib1.dart', r'''
final lib1 = newFile('$testPackageLibPath/lib1.dart', r'''
import 'package:meta/meta.dart';
@sealed class Foo {}
''');
newFile('$testPackageRootPath/test/lib2.dart', r'''
final lib2 = newFile('$testPackageRootPath/test/lib2.dart', r'''
import 'package:test/lib1.dart';
mixin Bar on Foo {}
''');
await resolveFile2('$testPackageLibPath/lib1.dart');
await resolveFile2(lib1);
assertNoErrorsInResult();
await resolveFile2('$testPackageRootPath/test/lib2.dart');
await resolveFile2(lib2);
assertNoErrorsInResult();
}
test_withinPart_OK() async {
newFile('$testPackageLibPath/lib1.dart', r'''
final lib1 = newFile('$testPackageLibPath/lib1.dart', r'''
import 'package:meta/meta.dart';
part 'part1.dart';
@sealed class Foo {}
''');
newFile('$testPackageLibPath/part1.dart', r'''
final lib2 = newFile('$testPackageLibPath/part1.dart', r'''
part of 'lib1.dart';
mixin Bar on Foo {}
''');
await resolveFile2('$testPackageLibPath/lib1.dart');
await resolveFile2(lib1);
assertNoErrorsInResult();
await resolveFile2('$testPackageLibPath/part1.dart');
await resolveFile2(lib2);
assertNoErrorsInResult();
}
}

View file

@ -42,12 +42,11 @@ part 'part.g.dart';
part of 'foo.dart';
''');
var path = '$testPackageRootPath/example/foo.dart';
newFile(path, '''
final foo = newFile('$testPackageRootPath/example/foo.dart', '''
part 'foo.g.dart';
''');
await resolveFile2(path);
await resolveFile2(foo);
assertErrorsInResolvedUnit(result, const []);
}

View file

@ -64,7 +64,7 @@ import 'dart:collection';
abstract class A implements LinkedListEntry<Never> {}
''');
await resolveFile2(a.path);
await resolveFile2(a);
assertNoErrorsInResult();
await assertErrorsInCode(r'''
@ -115,7 +115,7 @@ import 'dart:collection';
abstract class A implements LinkedListEntry<Never> {}
''');
await resolveFile2(a.path);
await resolveFile2(a);
assertNoErrorsInResult();
await assertErrorsInCode(r'''

View file

@ -55,7 +55,7 @@ class A implements MapEntry<int, int> {
}
''');
await resolveFile2(a.path);
await resolveFile2(a);
assertNoErrorsInResult();
await assertErrorsInCode(r'''
@ -113,7 +113,7 @@ class A implements MapEntry<int, int> {
}
''');
await resolveFile2(a.path);
await resolveFile2(a);
assertNoErrorsInResult();
await assertErrorsInCode(r'''

View file

@ -193,17 +193,14 @@ mixin Bar5 implements Foo {}
}
test_withinPart_language219() async {
var libPath = '$testPackageLibPath/a.dart';
var partPath = '$testPackageLibPath/b.dart';
newFile(libPath, r'''
final lib = newFile('$testPackageLibPath/a.dart', r'''
// @dart = 2.19
import 'package:meta/meta.dart';
part 'b.dart';
@sealed class Foo {}
''');
newFile(partPath, r'''
final part = newFile('$testPackageLibPath/b.dart', r'''
// @dart = 2.19
part of 'a.dart';
class Bar1 extends Foo {}
@ -212,10 +209,10 @@ class Bar4 = Bar1 with Foo;
mixin Bar5 implements Foo {}
''');
await resolveFile2(libPath);
await resolveFile2(lib);
assertNoErrorsInResult();
await resolveFile2(partPath);
await resolveFile2(part);
assertNoErrorsInResult();
}
}