From 1a99ac64741e30017a8ce4ac458182d72a2bff5e Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Tue, 10 Sep 2024 22:22:49 +0000 Subject: [PATCH] Parts. More tests for import/export related warnings. Change-Id: Ia758cc27b05536a9969a6f510755e79b7d18f204 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384564 Reviewed-by: Samuel Rawlins Commit-Queue: Konstantin Shcheglov --- .../duplicate_hidden_name_test.dart | 19 +++++- .../diagnostics/duplicate_import_test.dart | 59 +++++++++++++++---- .../duplicate_shown_name_test.dart | 19 +++++- 3 files changed, 84 insertions(+), 13 deletions(-) diff --git a/pkg/analyzer/test/src/diagnostics/duplicate_hidden_name_test.dart b/pkg/analyzer/test/src/diagnostics/duplicate_hidden_name_test.dart index 45e86ee53002..2bd85fdfad90 100644 --- a/pkg/analyzer/test/src/diagnostics/duplicate_hidden_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/duplicate_hidden_name_test.dart @@ -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 {} @@ -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), + ]); + } } diff --git a/pkg/analyzer/test/src/diagnostics/duplicate_import_test.dart b/pkg/analyzer/test/src/diagnostics/duplicate_import_test.dart index 206002f5f88e..08c1ad780be2 100644 --- a/pkg/analyzer/test/src/diagnostics/duplicate_import_test.dart +++ b/pkg/analyzer/test/src/diagnostics/duplicate_import_test.dart @@ -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 {} @@ -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 {} @@ -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 {} @@ -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 {} '''); @@ -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 {} '''); @@ -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 {} '''); @@ -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 {} @@ -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 {} @@ -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 {} @@ -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 {}'''); @@ -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 {}'''); @@ -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), + ]); + } } diff --git a/pkg/analyzer/test/src/diagnostics/duplicate_shown_name_test.dart b/pkg/analyzer/test/src/diagnostics/duplicate_shown_name_test.dart index 27e1e5d489d4..fb7e7b62d0f2 100644 --- a/pkg/analyzer/test/src/diagnostics/duplicate_shown_name_test.dart +++ b/pkg/analyzer/test/src/diagnostics/duplicate_shown_name_test.dart @@ -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 {} @@ -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), + ]); + } }