Skip to content

Commit

Permalink
Parts. More tests for import/export related warnings.
Browse files Browse the repository at this point in the history
Change-Id: Ia758cc27b05536a9969a6f510755e79b7d18f204
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384564
Reviewed-by: Samuel Rawlins <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Sep 10, 2024
1 parent 11aa023 commit 1a99ac6
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ main() {

@reflectiveTest
class DuplicateHiddenNameTest extends PubPackageResolutionTest {
test_hidden() async {
test_library_hidden() async {
newFile('$testPackageLibPath/lib1.dart', r'''
class A {}
class B {}
Expand All @@ -26,4 +26,21 @@ export 'lib1.dart' hide A, B, A;
error(WarningCode.DUPLICATE_HIDDEN_NAME, 30, 1),
]);
}

test_part_hidden() async {
var a = newFile('$testPackageLibPath/a.dart', r'''
part 'b.dart';
''');

var b = newFile('$testPackageLibPath/b.dart', r'''
part of 'a.dart';
export 'dart:math' hide pi, Random, pi;
''');

await assertErrorsInFile2(a, []);

await assertErrorsInFile2(b, [
error(WarningCode.DUPLICATE_HIDDEN_NAME, 54, 2),
]);
}
}
59 changes: 48 additions & 11 deletions pkg/analyzer/test/src/diagnostics/duplicate_import_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ main() {

@reflectiveTest
class DuplicateExportTest extends PubPackageResolutionTest {
test_duplicateExport() async {
test_library_duplicateExport() async {
newFile('$testPackageLibPath/lib1.dart', r'''
class A {}
class B {}
Expand All @@ -29,7 +29,7 @@ export 'lib1.dart';
]);
}

test_duplicateExport_differentShow() async {
test_library_duplicateExport_differentShow() async {
newFile('$testPackageLibPath/lib1.dart', r'''
class A {}
class B {}
Expand All @@ -40,7 +40,7 @@ export 'lib1.dart' show B;
''');
}

test_duplicateExport_sameShow() async {
test_library_duplicateExport_sameShow() async {
newFile('$testPackageLibPath/lib1.dart', r'''
class A {}
class B {}
Expand All @@ -52,11 +52,29 @@ export 'lib1.dart' show A;
error(WarningCode.DUPLICATE_EXPORT, 34, 11),
]);
}

test_part_duplicateExport() async {
var a = newFile('$testPackageLibPath/a.dart', r'''
part 'b.dart';
''');

var b = newFile('$testPackageLibPath/b.dart', r'''
part of 'a.dart';
export 'dart:math';
export 'dart:math';
''');

await assertErrorsInFile2(a, []);

await assertErrorsInFile2(b, [
error(WarningCode.DUPLICATE_EXPORT, 45, 11),
]);
}
}

@reflectiveTest
class DuplicateImportTest extends PubPackageResolutionTest {
test_duplicateImport_absolute_absolute() async {
test_library_duplicateImport_absolute_absolute() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {}
''');
Expand All @@ -71,7 +89,7 @@ final a = A();
]);
}

test_duplicateImport_relative_absolute() async {
test_library_duplicateImport_relative_absolute() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {}
''');
Expand All @@ -86,7 +104,7 @@ final a = A();
]);
}

test_duplicateImport_relative_relative() async {
test_library_duplicateImport_relative_relative() async {
newFile('$testPackageLibPath/a.dart', r'''
class A {}
''');
Expand All @@ -101,7 +119,7 @@ final a = A();
]);
}

test_importsHaveIdenticalShowHide() async {
test_library_importsHaveIdenticalShowHide() async {
var lib1 = newFile('$testPackageLibPath/lib1.dart', r'''
library lib1;
class A {}
Expand All @@ -121,7 +139,7 @@ M.A a = M.A();
]);
}

test_oneImportHasHide() async {
test_library_oneImportHasHide() async {
var lib1 = newFile('$testPackageLibPath/lib1.dart', r'''
library lib1;
class A {}
Expand All @@ -138,7 +156,7 @@ B b = B();
await assertErrorsInFile2(lib2, []);
}

test_oneImportHasShow() async {
test_library_oneImportHasShow() async {
var lib1 = newFile('$testPackageLibPath/lib1.dart', r'''
library lib1;
class A {}
Expand All @@ -157,7 +175,7 @@ B b = B();
await assertErrorsInFile2(lib2, []);
}

test_oneImportUsesAs() async {
test_library_oneImportUsesAs() async {
var lib1 = newFile('$testPackageLibPath/lib1.dart', r'''
library lib1;
class A {}''');
Expand All @@ -174,7 +192,7 @@ one.A a2 = one.A();
await assertErrorsInFile2(lib2, []);
}

test_twoDuplicateImports() async {
test_library_twoDuplicateImports() async {
var lib1 = newFile('$testPackageLibPath/lib1.dart', r'''
library lib1;
class A {}''');
Expand All @@ -193,4 +211,23 @@ A a = A();
error(WarningCode.DUPLICATE_IMPORT, 58, 11),
]);
}

test_part_duplicateImport() async {
var a = newFile('$testPackageLibPath/a.dart', r'''
part 'b.dart';
''');

var b = newFile('$testPackageLibPath/b.dart', r'''
part of 'a.dart';
import 'dart:math';
import 'dart:math';
void f(Random _) {}
''');

await assertErrorsInFile2(a, []);

await assertErrorsInFile2(b, [
error(WarningCode.DUPLICATE_IMPORT, 45, 11),
]);
}
}
19 changes: 18 additions & 1 deletion pkg/analyzer/test/src/diagnostics/duplicate_shown_name_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ main() {

@reflectiveTest
class DuplicateShownNameTest extends PubPackageResolutionTest {
test_hidden() async {
test_library_shown() async {
newFile('$testPackageLibPath/lib1.dart', r'''
class A {}
class B {}
Expand All @@ -26,4 +26,21 @@ export 'lib1.dart' show A, B, A;
error(WarningCode.DUPLICATE_SHOWN_NAME, 30, 1),
]);
}

test_part_shown() async {
var a = newFile('$testPackageLibPath/a.dart', r'''
part 'b.dart';
''');

var b = newFile('$testPackageLibPath/b.dart', r'''
part of 'a.dart';
export 'dart:math' show pi, Random, pi;
''');

await assertErrorsInFile2(a, []);

await assertErrorsInFile2(b, [
error(WarningCode.DUPLICATE_SHOWN_NAME, 54, 2),
]);
}
}

0 comments on commit 1a99ac6

Please sign in to comment.