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 <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
Konstantin Shcheglov 2023-11-02 21:50:29 +00:00 committed by Commit Queue
parent f3cd5c1473
commit c753f25160
4 changed files with 29 additions and 25 deletions

View file

@ -349,7 +349,7 @@ class SdkLibraryImpl implements SdkLibrary {
bool get isImplementation => _implementation; bool get isImplementation => _implementation;
@override @override
bool get isInternal => category == "Internal"; bool get isInternal => shortName.startsWith('dart:_');
@override @override
bool get isShared => category == "Shared"; bool get isShared => category == "Shared";

View file

@ -714,7 +714,7 @@ class A {}
// Configure `package:my`. // Configure `package:my`.
writePackageConfig( writePackageConfig(
getFile('${myRoot.path}/.dart_tool/package_config.json').path, myRoot.path,
PackageConfigFileBuilder()..add(name: 'my', rootPath: myRoot.path), PackageConfigFileBuilder()..add(name: 'my', rootPath: myRoot.path),
); );

View file

@ -353,12 +353,8 @@ class PubPackageResolutionTest extends ContextResolutionTest {
}) async { }) async {
final rootFolder = getFolder('$workspaceRootPath/foo'); final rootFolder = getFolder('$workspaceRootPath/foo');
final packageConfigFile = getFile(
'${rootFolder.path}/.dart_tool/package_config.json',
);
writePackageConfig( writePackageConfig(
packageConfigFile.path, rootFolder.path,
PackageConfigFileBuilder()..add(name: 'foo', rootPath: rootFolder.path), PackageConfigFileBuilder()..add(name: 'foo', rootPath: rootFolder.path),
); );
@ -399,13 +395,14 @@ class PubPackageResolutionTest extends ContextResolutionTest {
); );
} }
void writePackageConfig(String path, PackageConfigFileBuilder config) { void writePackageConfig(
newFile( String directoryPath,
path, PackageConfigFileBuilder config,
config.toContent( ) {
toUriStr: toUriStr, final content = config.toContent(
), toUriStr: toUriStr,
); );
newPackageConfigJsonFile(directoryPath, content);
} }
Future<File> writeSdkSummary() async { Future<File> writeSdkSummary() async {
@ -488,8 +485,7 @@ class PubPackageResolutionTest extends ContextResolutionTest {
); );
} }
var path = '$testPackageRootPath/.dart_tool/package_config.json'; writePackageConfig(testPackageRootPath, config);
writePackageConfig(path, config);
} }
void writeTestPackageConfigWithMeta() { void writeTestPackageConfigWithMeta() {

View file

@ -30,8 +30,8 @@ import 'dart:_internal';
} }
test_wasm_fromJs() async { test_wasm_fromJs() async {
var filePath = _pathInPackage('js'); final packageRootPath = _newPackage('js');
final file = newFile(filePath, ''' final file = newFile('$packageRootPath/lib/js.dart', '''
import 'dart:_wasm'; import 'dart:_wasm';
'''); ''');
await resolveFile2(file); 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 { test_wasm_fromUi() async {
var filePath = _pathInPackage('ui'); final packageRootPath = _newPackage('ui');
final file = newFile(filePath, ''' final file = newFile('$packageRootPath/lib/ui.dart', '''
import 'dart:_wasm'; import 'dart:_wasm';
'''); ''');
await resolveFile2(file); await resolveFile2(file);
@ -51,16 +60,15 @@ import 'dart:_wasm';
]); ]);
} }
String _pathInPackage(String packageName) { String _newPackage(String packageName) {
var packageRoot = '$workspaceRootPath/$packageName'; var packageRootPath = '$workspaceRootPath/$packageName';
var builder = PackageConfigFileBuilder(); var builder = PackageConfigFileBuilder();
builder.add( builder.add(
name: packageName, name: packageName,
rootPath: packageRoot, rootPath: packageRootPath,
languageVersion: testPackageLanguageVersion, languageVersion: testPackageLanguageVersion,
); );
var path = '$packageRoot/.dart_tool/package_config.json'; writePackageConfig(packageRootPath, builder);
writePackageConfig(path, builder); return packageRootPath;
return '$packageRoot/lib/$packageName.dart';
} }
} }