From c753f25160d500c216edbcb05b2e770c7ec662d8 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Thu, 2 Nov 2023 21:50:29 +0000 Subject: [PATCH] Add negative dart:_wasm test, fix SdkLibrary.isInternal While doing a previous CL, noticed that we don't actually report the corresponding error. Change-Id: I77ae11de6f6e84b3625b13db803e846966c806d6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333641 Commit-Queue: Konstantin Shcheglov Reviewed-by: Samuel Rawlins Reviewed-by: Brian Wilkerson --- pkg/analyzer/lib/src/generated/sdk.dart | 2 +- .../test/src/dart/analysis/search_test.dart | 2 +- .../context_collection_resolution.dart | 22 ++++++--------- .../import_internal_library_test.dart | 28 ++++++++++++------- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/pkg/analyzer/lib/src/generated/sdk.dart b/pkg/analyzer/lib/src/generated/sdk.dart index 265ce7963fc..2959543becb 100644 --- a/pkg/analyzer/lib/src/generated/sdk.dart +++ b/pkg/analyzer/lib/src/generated/sdk.dart @@ -349,7 +349,7 @@ class SdkLibraryImpl implements SdkLibrary { bool get isImplementation => _implementation; @override - bool get isInternal => category == "Internal"; + bool get isInternal => shortName.startsWith('dart:_'); @override bool get isShared => category == "Shared"; diff --git a/pkg/analyzer/test/src/dart/analysis/search_test.dart b/pkg/analyzer/test/src/dart/analysis/search_test.dart index 83fe8f4d65d..3df7e4759a5 100644 --- a/pkg/analyzer/test/src/dart/analysis/search_test.dart +++ b/pkg/analyzer/test/src/dart/analysis/search_test.dart @@ -714,7 +714,7 @@ class A {} // Configure `package:my`. writePackageConfig( - getFile('${myRoot.path}/.dart_tool/package_config.json').path, + myRoot.path, PackageConfigFileBuilder()..add(name: 'my', rootPath: myRoot.path), ); diff --git a/pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart b/pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart index 703dbd1aa4e..c32703e2887 100644 --- a/pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart +++ b/pkg/analyzer/test/src/dart/resolution/context_collection_resolution.dart @@ -353,12 +353,8 @@ class PubPackageResolutionTest extends ContextResolutionTest { }) async { final rootFolder = getFolder('$workspaceRootPath/foo'); - final packageConfigFile = getFile( - '${rootFolder.path}/.dart_tool/package_config.json', - ); - writePackageConfig( - packageConfigFile.path, + rootFolder.path, PackageConfigFileBuilder()..add(name: 'foo', rootPath: rootFolder.path), ); @@ -399,13 +395,14 @@ class PubPackageResolutionTest extends ContextResolutionTest { ); } - void writePackageConfig(String path, PackageConfigFileBuilder config) { - newFile( - path, - config.toContent( - toUriStr: toUriStr, - ), + void writePackageConfig( + String directoryPath, + PackageConfigFileBuilder config, + ) { + final content = config.toContent( + toUriStr: toUriStr, ); + newPackageConfigJsonFile(directoryPath, content); } Future writeSdkSummary() async { @@ -488,8 +485,7 @@ class PubPackageResolutionTest extends ContextResolutionTest { ); } - var path = '$testPackageRootPath/.dart_tool/package_config.json'; - writePackageConfig(path, config); + writePackageConfig(testPackageRootPath, config); } void writeTestPackageConfigWithMeta() { diff --git a/pkg/analyzer/test/src/diagnostics/import_internal_library_test.dart b/pkg/analyzer/test/src/diagnostics/import_internal_library_test.dart index ecb885b0ff7..6068a6c46df 100644 --- a/pkg/analyzer/test/src/diagnostics/import_internal_library_test.dart +++ b/pkg/analyzer/test/src/diagnostics/import_internal_library_test.dart @@ -30,8 +30,8 @@ import 'dart:_internal'; } test_wasm_fromJs() async { - var filePath = _pathInPackage('js'); - final file = newFile(filePath, ''' + final packageRootPath = _newPackage('js'); + final file = newFile('$packageRootPath/lib/js.dart', ''' import 'dart:_wasm'; '''); await resolveFile2(file); @@ -40,9 +40,18 @@ import 'dart:_wasm'; ]); } + test_wasm_fromTest() async { + await assertErrorsInCode(''' +import 'dart:_wasm'; +''', [ + error(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, 7, 12), + error(WarningCode.UNUSED_IMPORT, 7, 12), + ]); + } + test_wasm_fromUi() async { - var filePath = _pathInPackage('ui'); - final file = newFile(filePath, ''' + final packageRootPath = _newPackage('ui'); + final file = newFile('$packageRootPath/lib/ui.dart', ''' import 'dart:_wasm'; '''); await resolveFile2(file); @@ -51,16 +60,15 @@ import 'dart:_wasm'; ]); } - String _pathInPackage(String packageName) { - var packageRoot = '$workspaceRootPath/$packageName'; + String _newPackage(String packageName) { + var packageRootPath = '$workspaceRootPath/$packageName'; var builder = PackageConfigFileBuilder(); builder.add( name: packageName, - rootPath: packageRoot, + rootPath: packageRootPath, languageVersion: testPackageLanguageVersion, ); - var path = '$packageRoot/.dart_tool/package_config.json'; - writePackageConfig(path, builder); - return '$packageRoot/lib/$packageName.dart'; + writePackageConfig(packageRootPath, builder); + return packageRootPath; } }