CQ. Remove ResolutionTest.error/message, all goes through inline expected diagnostics now.
Change-Id: I46fd2efe14e1bb46fa7ec12423c19fcf551bdca9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510660 Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
@@ -8,7 +8,6 @@ import 'package:analyzer/dart/constant/value.dart';
|
|||||||
import 'package:analyzer/dart/element/element.dart';
|
import 'package:analyzer/dart/element/element.dart';
|
||||||
import 'package:analyzer/dart/element/type.dart';
|
import 'package:analyzer/dart/element/type.dart';
|
||||||
import 'package:analyzer/diagnostic/diagnostic.dart';
|
import 'package:analyzer/diagnostic/diagnostic.dart';
|
||||||
import 'package:analyzer/error/error.dart';
|
|
||||||
import 'package:analyzer/file_system/file_system.dart';
|
import 'package:analyzer/file_system/file_system.dart';
|
||||||
import 'package:analyzer/src/dart/analysis/results.dart';
|
import 'package:analyzer/src/dart/analysis/results.dart';
|
||||||
import 'package:analyzer/src/dart/ast/ast.dart';
|
import 'package:analyzer/src/dart/ast/ast.dart';
|
||||||
@@ -23,7 +22,6 @@ import 'package:analyzer/src/dart/element/type_system.dart';
|
|||||||
import 'package:analyzer/src/test_utilities/find_element2.dart';
|
import 'package:analyzer/src/test_utilities/find_element2.dart';
|
||||||
import 'package:analyzer/src/test_utilities/find_node.dart';
|
import 'package:analyzer/src/test_utilities/find_node.dart';
|
||||||
import 'package:analyzer_testing/resource_provider_mixin.dart';
|
import 'package:analyzer_testing/resource_provider_mixin.dart';
|
||||||
import 'package:analyzer_testing/src/analysis_rule/pub_package_resolution.dart';
|
|
||||||
import 'package:analyzer_testing/src/expected_diagnostics.dart';
|
import 'package:analyzer_testing/src/expected_diagnostics.dart';
|
||||||
import 'package:analyzer_utilities/testing/tree_string_sink.dart';
|
import 'package:analyzer_utilities/testing/tree_string_sink.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
@@ -242,31 +240,6 @@ mixin ResolutionTest implements ResourceProviderMixin {
|
|||||||
expect(node.staticType, isNull);
|
expect(node.staticType, isNull);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpectedError error(
|
|
||||||
DiagnosticCode code,
|
|
||||||
int offset,
|
|
||||||
int length, {
|
|
||||||
Pattern? correctionContains,
|
|
||||||
// TODO(FMorschel): refactor the uses of this to prefer `messageContains`
|
|
||||||
String? text,
|
|
||||||
List<Pattern> messageContains = const [],
|
|
||||||
List<ExpectedContextMessage> contextMessages =
|
|
||||||
const <ExpectedContextMessage>[],
|
|
||||||
}) {
|
|
||||||
assert(
|
|
||||||
text == null || messageContains.isEmpty,
|
|
||||||
'Only use one of text or messageContains',
|
|
||||||
);
|
|
||||||
return ExpectedError(
|
|
||||||
code,
|
|
||||||
offset,
|
|
||||||
length,
|
|
||||||
correctionContains: correctionContains,
|
|
||||||
messageContainsAll: text != null ? [text] : messageContains,
|
|
||||||
contextMessages: contextMessages,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Element? getNodeElement2(AstNode node) {
|
Element? getNodeElement2(AstNode node) {
|
||||||
if (node is Annotation) {
|
if (node is Annotation) {
|
||||||
return node.element;
|
return node.element;
|
||||||
@@ -318,9 +291,6 @@ mixin ResolutionTest implements ResourceProviderMixin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpectedContextMessage message(File file, int offset, int length) =>
|
|
||||||
ExpectedContextMessage(file, offset, length);
|
|
||||||
|
|
||||||
Future<ResolvedUnitResultImpl> resolveFile(File file);
|
Future<ResolvedUnitResultImpl> resolveFile(File file);
|
||||||
|
|
||||||
/// Resolve [file] and return a test view of it.
|
/// Resolve [file] and return a test view of it.
|
||||||
|
|||||||
@@ -2,13 +2,8 @@
|
|||||||
// for details. All rights reserved. Use of this source code is governed by a
|
// 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.
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:analyzer/dart/analysis/results.dart';
|
|
||||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
|
||||||
import 'package:matcher/src/core_matchers.dart';
|
|
||||||
import 'package:test/test.dart' show expect;
|
|
||||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||||
|
|
||||||
import '../../generated/test_support.dart';
|
|
||||||
import '../dart/resolution/context_collection_resolution.dart';
|
import '../dart/resolution/context_collection_resolution.dart';
|
||||||
import '../dart/resolution/node_text_expectations.dart';
|
import '../dart/resolution/node_text_expectations.dart';
|
||||||
|
|
||||||
@@ -101,24 +96,23 @@ class N {}
|
|||||||
newFile("$testPackageLibPath/lib2.dart", '''
|
newFile("$testPackageLibPath/lib2.dart", '''
|
||||||
class N {}
|
class N {}
|
||||||
''');
|
''');
|
||||||
var partFile = newFile('$testPackageLibPath/part.dart', '''
|
var partFile = getFile('$testPackageLibPath/part.dart');
|
||||||
part of 'lib.dart';
|
var libFile = getFile('$testPackageLibPath/lib.dart');
|
||||||
class A extends N {}
|
|
||||||
''');
|
await resolveFilesWithDiagnostics({
|
||||||
var libFile = newFile('$testPackageLibPath/lib.dart', '''
|
libFile: r'''
|
||||||
import 'lib1.dart';
|
import 'lib1.dart';
|
||||||
import 'lib2.dart';
|
import 'lib2.dart';
|
||||||
part 'part.dart';
|
part 'part.dart';
|
||||||
''');
|
''',
|
||||||
ResolvedUnitResult libResult = await resolveFile(libFile);
|
partFile: r'''
|
||||||
ResolvedUnitResult partResult = await resolveFile(partFile);
|
part of 'lib.dart';
|
||||||
expect(libResult.diagnostics, hasLength(0));
|
class A extends N {}
|
||||||
GatheringDiagnosticListener()
|
// ^
|
||||||
..addAll(partResult.diagnostics)
|
// [diag.extendsNonClass] Classes can only extend other classes.
|
||||||
..assertErrors([
|
// [diag.ambiguousImport] The name 'N' is defined in the libraries 'package:test/lib1.dart' and 'package:test/lib2.dart'.
|
||||||
error(diag.extendsNonClass, 36, 1),
|
''',
|
||||||
error(diag.ambiguousImport, 36, 1),
|
});
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test_instanceCreation() async {
|
test_instanceCreation() async {
|
||||||
|
|||||||
@@ -2,10 +2,8 @@
|
|||||||
// for details. All rights reserved. Use of this source code is governed by a
|
// 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.
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
import 'package:analyzer/src/diagnostic/diagnostic.dart' as diag;
|
|
||||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||||
|
|
||||||
import '../../generated/test_support.dart';
|
|
||||||
import '../dart/resolution/context_collection_resolution.dart';
|
import '../dart/resolution/context_collection_resolution.dart';
|
||||||
import '../dart/resolution/node_text_expectations.dart';
|
import '../dart/resolution/node_text_expectations.dart';
|
||||||
|
|
||||||
@@ -4153,69 +4151,52 @@ augment class A {}
|
|||||||
}
|
}
|
||||||
|
|
||||||
test_class_library_part() async {
|
test_class_library_part() async {
|
||||||
var lib = newFile('$testPackageLibPath/lib.dart', '''
|
var lib = getFile('$testPackageLibPath/lib.dart');
|
||||||
|
var a = getFile('$testPackageLibPath/a.dart');
|
||||||
|
|
||||||
|
await resolveFilesWithDiagnostics({
|
||||||
|
lib: r'''
|
||||||
part 'a.dart';
|
part 'a.dart';
|
||||||
|
|
||||||
class A {}
|
class A {}
|
||||||
''');
|
// ^
|
||||||
|
// [context 1] The first definition of this name.
|
||||||
var a = newFile('$testPackageLibPath/a.dart', '''
|
''',
|
||||||
|
a: r'''
|
||||||
part of 'lib.dart';
|
part of 'lib.dart';
|
||||||
|
|
||||||
class A {}
|
class A {}
|
||||||
''');
|
// ^
|
||||||
|
// [diag.duplicateDefinition][context 1] The name 'A' is already defined.
|
||||||
await resolveFile(lib);
|
''',
|
||||||
|
});
|
||||||
var aResult = await resolveFile(a);
|
|
||||||
GatheringDiagnosticListener()
|
|
||||||
..addAll(aResult.diagnostics)
|
|
||||||
..assertErrors([
|
|
||||||
error(
|
|
||||||
diag.duplicateDefinition,
|
|
||||||
27,
|
|
||||||
1,
|
|
||||||
contextMessages: [message(lib, 22, 1)],
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test_class_part_part() async {
|
test_class_part_part() async {
|
||||||
var lib = newFile('$testPackageLibPath/lib.dart', '''
|
var lib = getFile('$testPackageLibPath/lib.dart');
|
||||||
|
var a = getFile('$testPackageLibPath/a.dart');
|
||||||
|
var b = getFile('$testPackageLibPath/b.dart');
|
||||||
|
|
||||||
|
await resolveFilesWithDiagnostics({
|
||||||
|
lib: r'''
|
||||||
part 'a.dart';
|
part 'a.dart';
|
||||||
part 'b.dart';
|
part 'b.dart';
|
||||||
''');
|
''',
|
||||||
|
a: r'''
|
||||||
var a = newFile('$testPackageLibPath/a.dart', '''
|
|
||||||
part of 'lib.dart';
|
part of 'lib.dart';
|
||||||
|
|
||||||
class A {}
|
class A {}
|
||||||
''');
|
// ^
|
||||||
|
// [context 1] The first definition of this name.
|
||||||
var b = newFile('$testPackageLibPath/b.dart', '''
|
''',
|
||||||
|
b: r'''
|
||||||
part of 'lib.dart';
|
part of 'lib.dart';
|
||||||
|
|
||||||
class A {}
|
class A {}
|
||||||
''');
|
// ^
|
||||||
|
// [diag.duplicateDefinition][context 1] The name 'A' is already defined.
|
||||||
await resolveFile(lib);
|
''',
|
||||||
|
});
|
||||||
var aResult = await resolveFile(a);
|
|
||||||
GatheringDiagnosticListener()
|
|
||||||
..addAll(aResult.diagnostics)
|
|
||||||
..assertNoErrors();
|
|
||||||
|
|
||||||
var bResult = await resolveFile(b);
|
|
||||||
GatheringDiagnosticListener()
|
|
||||||
..addAll(bResult.diagnostics)
|
|
||||||
..assertErrors([
|
|
||||||
error(
|
|
||||||
diag.duplicateDefinition,
|
|
||||||
27,
|
|
||||||
1,
|
|
||||||
contextMessages: [message(a, 27, 1)],
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test_extension() async {
|
test_extension() async {
|
||||||
@@ -4231,31 +4212,25 @@ extension A on int {}
|
|||||||
}
|
}
|
||||||
|
|
||||||
test_extension_library_part() async {
|
test_extension_library_part() async {
|
||||||
var lib = newFile('$testPackageLibPath/lib.dart', '''
|
var lib = getFile('$testPackageLibPath/lib.dart');
|
||||||
|
var a = getFile('$testPackageLibPath/a.dart');
|
||||||
|
|
||||||
|
await resolveFilesWithDiagnostics({
|
||||||
|
lib: r'''
|
||||||
part 'a.dart';
|
part 'a.dart';
|
||||||
|
|
||||||
extension A on int {}
|
extension A on int {}
|
||||||
''');
|
// ^
|
||||||
|
// [context 1] The first definition of this name.
|
||||||
var a = newFile('$testPackageLibPath/a.dart', '''
|
''',
|
||||||
|
a: r'''
|
||||||
part of 'lib.dart';
|
part of 'lib.dart';
|
||||||
|
|
||||||
extension A on int {}
|
extension A on int {}
|
||||||
''');
|
// ^
|
||||||
|
// [diag.duplicateDefinition][context 1] The name 'A' is already defined.
|
||||||
await resolveFile(lib);
|
''',
|
||||||
|
});
|
||||||
var aResult = await resolveFile(a);
|
|
||||||
GatheringDiagnosticListener()
|
|
||||||
..addAll(aResult.diagnostics)
|
|
||||||
..assertErrors([
|
|
||||||
error(
|
|
||||||
diag.duplicateDefinition,
|
|
||||||
31,
|
|
||||||
1,
|
|
||||||
contextMessages: [message(lib, 26, 1)],
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test_extensionType() async {
|
test_extensionType() async {
|
||||||
@@ -4271,31 +4246,25 @@ extension type A(int it) {}
|
|||||||
}
|
}
|
||||||
|
|
||||||
test_extensionType_library_part() async {
|
test_extensionType_library_part() async {
|
||||||
var lib = newFile('$testPackageLibPath/lib.dart', '''
|
var lib = getFile('$testPackageLibPath/lib.dart');
|
||||||
|
var a = getFile('$testPackageLibPath/a.dart');
|
||||||
|
|
||||||
|
await resolveFilesWithDiagnostics({
|
||||||
|
lib: r'''
|
||||||
part 'a.dart';
|
part 'a.dart';
|
||||||
|
|
||||||
extension type A(int it) {}
|
extension type A(int it) {}
|
||||||
''');
|
// ^
|
||||||
|
// [context 1] The first definition of this name.
|
||||||
var a = newFile('$testPackageLibPath/a.dart', '''
|
''',
|
||||||
|
a: r'''
|
||||||
part of 'lib.dart';
|
part of 'lib.dart';
|
||||||
|
|
||||||
extension type A(int it) {}
|
extension type A(int it) {}
|
||||||
''');
|
// ^
|
||||||
|
// [diag.duplicateDefinition][context 1] The name 'A' is already defined.
|
||||||
await resolveFile(lib);
|
''',
|
||||||
|
});
|
||||||
var aResult = await resolveFile(a);
|
|
||||||
GatheringDiagnosticListener()
|
|
||||||
..addAll(aResult.diagnostics)
|
|
||||||
..assertErrors([
|
|
||||||
error(
|
|
||||||
diag.duplicateDefinition,
|
|
||||||
36,
|
|
||||||
1,
|
|
||||||
contextMessages: [message(lib, 31, 1)],
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test_mixin() async {
|
test_mixin() async {
|
||||||
@@ -4318,31 +4287,25 @@ augment mixin A {}
|
|||||||
}
|
}
|
||||||
|
|
||||||
test_mixin_library_part() async {
|
test_mixin_library_part() async {
|
||||||
var lib = newFile('$testPackageLibPath/lib.dart', '''
|
var lib = getFile('$testPackageLibPath/lib.dart');
|
||||||
|
var a = getFile('$testPackageLibPath/a.dart');
|
||||||
|
|
||||||
|
await resolveFilesWithDiagnostics({
|
||||||
|
lib: r'''
|
||||||
part 'a.dart';
|
part 'a.dart';
|
||||||
|
|
||||||
mixin A {}
|
mixin A {}
|
||||||
''');
|
// ^
|
||||||
|
// [context 1] The first definition of this name.
|
||||||
var a = newFile('$testPackageLibPath/a.dart', '''
|
''',
|
||||||
|
a: r'''
|
||||||
part of 'lib.dart';
|
part of 'lib.dart';
|
||||||
|
|
||||||
mixin A {}
|
mixin A {}
|
||||||
''');
|
// ^
|
||||||
|
// [diag.duplicateDefinition][context 1] The name 'A' is already defined.
|
||||||
await resolveFile(lib);
|
''',
|
||||||
|
});
|
||||||
var aResult = await resolveFile(a);
|
|
||||||
GatheringDiagnosticListener()
|
|
||||||
..addAll(aResult.diagnostics)
|
|
||||||
..assertErrors([
|
|
||||||
error(
|
|
||||||
diag.duplicateDefinition,
|
|
||||||
27,
|
|
||||||
1,
|
|
||||||
contextMessages: [message(lib, 22, 1)],
|
|
||||||
),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test_topLevelVariable() async {
|
test_topLevelVariable() async {
|
||||||
|
|||||||
Reference in New Issue
Block a user