Skip to content

Commit

Permalink
Extract and augment DUPLICATE_DEFINITION tests.
Browse files Browse the repository at this point in the history
R=brianwilkerson@google.com

Change-Id: Idbf6db69ea51ec784b3a8bf94586ea4d535252d5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112681
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
scheglov authored and commit-bot@chromium.org committed Aug 10, 2019
1 parent 261fd62 commit 357f8b7
Show file tree
Hide file tree
Showing 7 changed files with 998 additions and 568 deletions.
180 changes: 0 additions & 180 deletions pkg/analyzer/test/generated/compile_time_error_code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1097,186 +1097,6 @@ main() {
]);
}

test_duplicateDefinition_acrossLibraries() async {
var libFile = newFile('/test/lib/lib.dart', content: '''
library lib;
part 'a.dart';
part 'test.dart';
''');
newFile('/test/lib/a.dart', content: '''
part of lib;
class A {}
''');
String partContent = '''
part of lib;
class A {}
''';
newFile('/test/lib/test.dart', content: partContent);
await resolveFile(libFile.path);
await assertErrorsInCode(partContent, [
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 20, 1),
]);
}

test_duplicateDefinition_catch() async {
await assertErrorsInCode(r'''
main() {
try {} catch (e, e) {}
}''', [
error(HintCode.UNUSED_CATCH_STACK, 28, 1),
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 28, 1),
]);
}

test_duplicateDefinition_inPart() async {
var libFile = newFile('/test/lib/lib1.dart', content: '''
library test;
part 'test.dart';
class A {}
''');
String partContent = '''
part of test;
class A {}
''';
newFile('/test/lib/test.dart', content: partContent);
await resolveFile(libFile.path);
await assertErrorsInCode(partContent, [
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 20, 1),
]);
}

test_duplicateDefinition_locals_inCase() async {
await assertErrorsInCode(r'''
main() {
switch(1) {
case 1:
var a;
var a;
}
}
''', [
error(HintCode.UNUSED_LOCAL_VARIABLE, 45, 1),
error(HintCode.UNUSED_LOCAL_VARIABLE, 58, 1),
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 58, 1),
]);
}

test_duplicateDefinition_locals_inFunctionBlock() async {
await assertErrorsInCode(r'''
main() {
int m = 0;
m(a) {}
}
''', [
error(HintCode.UNUSED_LOCAL_VARIABLE, 15, 1),
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 24, 1),
error(HintCode.UNUSED_ELEMENT, 24, 1),
]);
}

test_duplicateDefinition_locals_inIf() async {
await assertErrorsInCode(r'''
main(int p) {
if (p != 0) {
var a;
var a;
}
}
''', [
error(HintCode.UNUSED_LOCAL_VARIABLE, 38, 1),
error(HintCode.UNUSED_LOCAL_VARIABLE, 49, 1),
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 49, 1),
]);
}

test_duplicateDefinition_locals_inMethodBlock() async {
await assertErrorsInCode(r'''
class A {
m() {
int a;
int a;
}
}
''', [
error(HintCode.UNUSED_LOCAL_VARIABLE, 26, 1),
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 37, 1),
error(HintCode.UNUSED_LOCAL_VARIABLE, 37, 1),
]);
}

test_duplicateDefinition_notInDefiningUnit() async {
newFile('/test/lib/a.dart', content: '''
part of test;
class A {}
''');
await assertNoErrorsInCode('''
library test;
part 'a.dart';
class A {}
''');
}

test_duplicateDefinition_parameters_inConstructor() async {
await assertErrorsInCode(r'''
class A {
int a;
A(int a, this.a);
}
''', [
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 35, 1),
]);
}

test_duplicateDefinition_parameters_inFunctionTypeAlias() async {
await assertErrorsInCode(r'''
typedef F(int a, double a);
''', [
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 24, 1),
]);
}

test_duplicateDefinition_parameters_inLocalFunction() async {
await assertErrorsInCode(r'''
main() {
f(int a, double a) {
};
}
''', [
error(HintCode.UNUSED_ELEMENT, 11, 1),
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 27, 1),
]);
}

test_duplicateDefinition_parameters_inMethod() async {
await assertErrorsInCode(r'''
class A {
m(int a, double a) {
}
}
''', [
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 28, 1),
]);
}

test_duplicateDefinition_parameters_inTopLevelFunction() async {
await assertErrorsInCode(r'''
f(int a, double a) {}
''', [
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 16, 1),
]);
}

test_duplicateDefinition_typeParameters() async {
await assertErrorsInCode(r'''
class A<T, T> {}
''', [
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 11, 1),
]);
}

test_duplicateNamedArgument() async {
await assertErrorsInCode(r'''
f({a, b}) {}
Expand Down
11 changes: 0 additions & 11 deletions pkg/analyzer/test/generated/compile_time_error_code_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,6 @@ f() async {
]);
}

test_duplicateDefinition_for_initializers() async {
await assertErrorsInCode(r'''
f() {
for (int i = 0, i = 0; i < 5;) {}
}
''', [
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 24, 1),
error(HintCode.UNUSED_LOCAL_VARIABLE, 24, 1),
]);
}

test_expectedOneListTypeArgument() async {
await assertErrorsInCode(r'''
main() {
Expand Down
154 changes: 0 additions & 154 deletions pkg/analyzer/test/src/dart/resolution/class_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -948,160 +948,6 @@ class C {
]);
}

test_error_duplicateDefinition_field_field() async {
addTestFile(r'''
class C {
int foo;
int foo;
}
''');
await resolveTestFile();
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
}

test_error_duplicateDefinition_field_field_static() async {
addTestFile(r'''
class C {
static int foo;
static int foo;
}
''');
await resolveTestFile();
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
}

test_error_duplicateDefinition_field_getter() async {
addTestFile(r'''
class C {
int foo;
int get foo => 0;
}
''');
await resolveTestFile();
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
}

test_error_duplicateDefinition_field_method() async {
addTestFile(r'''
class C {
int foo;
void foo() {}
}
''');
await resolveTestFile();
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
}

test_error_duplicateDefinition_getter_getter() async {
addTestFile(r'''
class C {
int get foo => 0;
int get foo => 0;
}
''');
await resolveTestFile();
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
}

test_error_duplicateDefinition_getter_method() async {
addTestFile(r'''
class C {
int get foo => 0;
void foo() {}
}
''');
await resolveTestFile();
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
}

test_error_duplicateDefinition_method_getter() async {
addTestFile(r'''
class C {
void foo() {}
int get foo => 0;
}
''');
await resolveTestFile();
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
}

test_error_duplicateDefinition_method_method() async {
addTestFile(r'''
class C {
void foo() {}
void foo() {}
}
''');
await resolveTestFile();
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
}

test_error_duplicateDefinition_method_setter() async {
addTestFile(r'''
class C {
void foo() {}
set foo(_) {}
}
''');
await resolveTestFile();
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
}

test_error_duplicateDefinition_OK_fieldFinal_setter() async {
addTestFile(r'''
class C {
final int foo = 0;
set foo(int x) {}
}
''');
await resolveTestFile();
assertNoTestErrors();
}

test_error_duplicateDefinition_OK_getter_setter() async {
addTestFile(r'''
class C {
int get foo => 0;
set foo(_) {}
}
''');
await resolveTestFile();
assertNoTestErrors();
}

test_error_duplicateDefinition_OK_setter_getter() async {
addTestFile(r'''
class C {
set foo(_) {}
int get foo => 0;
}
''');
await resolveTestFile();
assertNoTestErrors();
}

test_error_duplicateDefinition_setter_method() async {
addTestFile(r'''
class C {
set foo(_) {}
void foo() {}
}
''');
await resolveTestFile();
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
}

test_error_duplicateDefinition_setter_setter() async {
addTestFile(r'''
class C {
void set foo(_) {}
void set foo(_) {}
}
''');
await resolveTestFile();
assertTestErrorsWithCodes([CompileTimeErrorCode.DUPLICATE_DEFINITION]);
}

test_error_extendsNonClass_dynamic() async {
addTestFile(r'''
class A extends dynamic {}
Expand Down
Loading

0 comments on commit 357f8b7

Please sign in to comment.