Skip to content

Commit

Permalink
Add negative dart:_wasm test, fix SdkLibrary.isInternal
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Samuel Rawlins <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Nov 2, 2023
1 parent f3cd5c1 commit c753f25
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/generated/sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/test/src/dart/analysis/search_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);

Expand Down Expand Up @@ -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<File> writeSdkSummary() async {
Expand Down Expand Up @@ -488,8 +485,7 @@ class PubPackageResolutionTest extends ContextResolutionTest {
);
}

var path = '$testPackageRootPath/.dart_tool/package_config.json';
writePackageConfig(path, config);
writePackageConfig(testPackageRootPath, config);
}

void writeTestPackageConfigWithMeta() {
Expand Down
28 changes: 18 additions & 10 deletions pkg/analyzer/test/src/diagnostics/import_internal_library_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
}

0 comments on commit c753f25

Please sign in to comment.