mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:49:00 +00:00
Migrate AnalysisHoverBazelTest to BazelWorkspaceAnalysisServerTest.
Change-Id: Ibafbeb27d6b494c2139a298dd3e3cab74c7c1e4e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241994 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
9846fe2621
commit
cf36021633
2 changed files with 127 additions and 109 deletions
|
@ -7,7 +7,6 @@ import 'package:analysis_server/src/protocol_server.dart';
|
|||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../analysis_abstract.dart';
|
||||
import '../analysis_server_base.dart';
|
||||
|
||||
void main() {
|
||||
|
@ -18,26 +17,26 @@ void main() {
|
|||
}
|
||||
|
||||
@reflectiveTest
|
||||
class AnalysisHoverBazelTest extends AbstractAnalysisTest {
|
||||
class AnalysisHoverBazelTest extends BazelWorkspaceAnalysisServerTest {
|
||||
Future<void> test_bazel_notOwnedUri() async {
|
||||
newFile('/workspace/WORKSPACE', '');
|
||||
projectPath = newFolder('/workspace').path;
|
||||
testFile = convertPath('/workspace/dart/my/lib/test.dart');
|
||||
|
||||
newFile(
|
||||
'/workspace/bazel-genfiles/dart/my/lib/test.dart',
|
||||
'$workspaceRootPath/bazel-genfiles/dart/my/lib/test.dart',
|
||||
'// generated',
|
||||
);
|
||||
|
||||
await createProject();
|
||||
await setRoots(included: [workspaceRootPath], excluded: []);
|
||||
|
||||
addTestFile('''
|
||||
var testFile = newFile('$myPackageLibPath/test.dart', '''
|
||||
class A {}
|
||||
''');
|
||||
|
||||
var request = AnalysisGetHoverParams(testFile, 0).toRequest('0');
|
||||
var response = await waitResponse(request);
|
||||
expect(response.error, isNotNull);
|
||||
var request = AnalysisGetHoverParams(testFile.path, 0).toRequest('0');
|
||||
var response = await handleRequest(request);
|
||||
assertResponseFailure(
|
||||
response,
|
||||
requestId: '0',
|
||||
errorCode: RequestErrorCode.FILE_NOT_ANALYZED,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:analysis_server/src/analysis_server.dart';
|
||||
import 'package:analysis_server/src/domain_analysis.dart';
|
||||
import 'package:analysis_server/src/protocol_server.dart';
|
||||
import 'package:analysis_server/src/server/crash_reporting_attachments.dart';
|
||||
import 'package:analysis_server/src/utilities/mocks.dart';
|
||||
|
@ -68,7 +67,22 @@ class AnalysisOptionsFileConfig {
|
|||
}
|
||||
}
|
||||
|
||||
class PubPackageAnalysisServerTest with ResourceProviderMixin {
|
||||
class BazelWorkspaceAnalysisServerTest extends ContextResolutionTest {
|
||||
String get myPackageLibPath => '$myPackageRootPath/lib';
|
||||
|
||||
String get myPackageRootPath => '$workspaceRootPath/dart/my';
|
||||
|
||||
Folder get workspaceRoot => getFolder(workspaceRootPath);
|
||||
|
||||
String get workspaceRootPath => '/workspace';
|
||||
|
||||
@override
|
||||
void createDefaultFiles() {
|
||||
newFile('$workspaceRootPath/WORKSPACE', '');
|
||||
}
|
||||
}
|
||||
|
||||
class ContextResolutionTest with ResourceProviderMixin {
|
||||
final TestPluginManager pluginManager = TestPluginManager();
|
||||
late final MockServerChannel serverChannel;
|
||||
late final AnalysisServer server;
|
||||
|
@ -76,56 +90,8 @@ class PubPackageAnalysisServerTest with ResourceProviderMixin {
|
|||
final List<GeneralAnalysisService> _analysisGeneralServices = [];
|
||||
final Map<AnalysisService, List<String>> _analysisFileSubscriptions = {};
|
||||
|
||||
AnalysisDomainHandler get analysisDomain {
|
||||
return server.handlers.whereType<AnalysisDomainHandler>().single;
|
||||
}
|
||||
|
||||
List<String> get experiments => [
|
||||
EnableString.enhanced_enums,
|
||||
EnableString.named_arguments_anywhere,
|
||||
EnableString.super_parameters,
|
||||
];
|
||||
|
||||
/// The path that is not in [workspaceRootPath], contains external packages.
|
||||
String get packagesRootPath => '/packages';
|
||||
|
||||
Folder get sdkRoot => newFolder('/sdk');
|
||||
|
||||
File get testFile => getFile(testFilePath);
|
||||
|
||||
analysis.AnalysisOptions get testFileAnalysisOptions {
|
||||
var analysisDriver = server.getAnalysisDriver(testFile.path)!;
|
||||
return analysisDriver.analysisOptions;
|
||||
}
|
||||
|
||||
String get testFileContent => testFile.readAsStringSync();
|
||||
|
||||
String get testFilePath => '$testPackageLibPath/test.dart';
|
||||
|
||||
String get testPackageLibPath => '$testPackageRootPath/lib';
|
||||
|
||||
Folder get testPackageRoot => getFolder(testPackageRootPath);
|
||||
|
||||
String get testPackageRootPath => '$workspaceRootPath/test';
|
||||
|
||||
String get testPackageTestPath => '$testPackageRootPath/test';
|
||||
|
||||
Folder get workspaceRoot => getFolder(workspaceRootPath);
|
||||
|
||||
String get workspaceRootPath => '/home';
|
||||
|
||||
Future<void> addAnalysisSubscription(
|
||||
AnalysisService service,
|
||||
File file,
|
||||
) async {
|
||||
(_analysisFileSubscriptions[service] ??= []).add(file.path);
|
||||
await handleSuccessfulRequest(
|
||||
AnalysisSetSubscriptionsParams(
|
||||
_analysisFileSubscriptions,
|
||||
).toRequest('0'),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> addGeneralAnalysisSubscription(
|
||||
GeneralAnalysisService service,
|
||||
) async {
|
||||
|
@ -133,11 +99,6 @@ class PubPackageAnalysisServerTest with ResourceProviderMixin {
|
|||
await _setGeneralAnalysisSubscriptions();
|
||||
}
|
||||
|
||||
/// TODO(scheglov) rename
|
||||
void addTestFile(String content) {
|
||||
newFile(testFilePath, content);
|
||||
}
|
||||
|
||||
void assertResponseFailure(
|
||||
Response response, {
|
||||
required String requestId,
|
||||
|
@ -149,20 +110,7 @@ class PubPackageAnalysisServerTest with ResourceProviderMixin {
|
|||
);
|
||||
}
|
||||
|
||||
void deleteTestPackageAnalysisOptionsFile() {
|
||||
deleteAnalysisOptionsYamlFile(testPackageRootPath);
|
||||
}
|
||||
|
||||
void deleteTestPackageConfigJsonFile() {
|
||||
deletePackageConfigJsonFile(testPackageRootPath);
|
||||
}
|
||||
|
||||
/// Returns the offset of [search] in [testFileContent].
|
||||
/// Fails if not found.
|
||||
/// TODO(scheglov) Rename it.
|
||||
int findOffset(String search) {
|
||||
return offsetInFile(testFile, search);
|
||||
}
|
||||
void createDefaultFiles() {}
|
||||
|
||||
Future<Response> handleRequest(Request request) async {
|
||||
return await serverChannel.sendRequest(request);
|
||||
|
@ -175,19 +123,6 @@ class PubPackageAnalysisServerTest with ResourceProviderMixin {
|
|||
return response;
|
||||
}
|
||||
|
||||
void modifyTestFile(String content) {
|
||||
modifyFile(testFilePath, content);
|
||||
}
|
||||
|
||||
/// Returns the offset of [search] in [file].
|
||||
/// Fails if not found.
|
||||
int offsetInFile(File file, String search) {
|
||||
var content = file.readAsStringSync();
|
||||
var offset = content.indexOf(search);
|
||||
expect(offset, isNot(-1));
|
||||
return offset;
|
||||
}
|
||||
|
||||
void processNotification(Notification notification) {}
|
||||
|
||||
Future<void> removeGeneralAnalysisSubscription(
|
||||
|
@ -229,13 +164,7 @@ class PubPackageAnalysisServerTest with ResourceProviderMixin {
|
|||
root: sdkRoot,
|
||||
);
|
||||
|
||||
writeTestPackageConfig();
|
||||
|
||||
writeTestPackageAnalysisOptionsFile(
|
||||
AnalysisOptionsFileConfig(
|
||||
experiments: experiments,
|
||||
),
|
||||
);
|
||||
createDefaultFiles();
|
||||
|
||||
serverChannel.notifications.listen(processNotification);
|
||||
|
||||
|
@ -263,6 +192,104 @@ class PubPackageAnalysisServerTest with ResourceProviderMixin {
|
|||
await server.onAnalysisComplete;
|
||||
}
|
||||
|
||||
Future<void> _setGeneralAnalysisSubscriptions() async {
|
||||
await handleSuccessfulRequest(
|
||||
AnalysisSetGeneralSubscriptionsParams(
|
||||
_analysisGeneralServices,
|
||||
).toRequest('0'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class PubPackageAnalysisServerTest extends ContextResolutionTest {
|
||||
List<String> get experiments => [
|
||||
EnableString.enhanced_enums,
|
||||
EnableString.named_arguments_anywhere,
|
||||
EnableString.super_parameters,
|
||||
];
|
||||
|
||||
/// The path that is not in [workspaceRootPath], contains external packages.
|
||||
String get packagesRootPath => '/packages';
|
||||
|
||||
File get testFile => getFile(testFilePath);
|
||||
|
||||
analysis.AnalysisOptions get testFileAnalysisOptions {
|
||||
var analysisDriver = server.getAnalysisDriver(testFile.path)!;
|
||||
return analysisDriver.analysisOptions;
|
||||
}
|
||||
|
||||
String get testFileContent => testFile.readAsStringSync();
|
||||
|
||||
String get testFilePath => '$testPackageLibPath/test.dart';
|
||||
|
||||
String get testPackageLibPath => '$testPackageRootPath/lib';
|
||||
|
||||
Folder get testPackageRoot => getFolder(testPackageRootPath);
|
||||
|
||||
String get testPackageRootPath => '$workspaceRootPath/test';
|
||||
|
||||
String get testPackageTestPath => '$testPackageRootPath/test';
|
||||
|
||||
Folder get workspaceRoot => getFolder(workspaceRootPath);
|
||||
|
||||
String get workspaceRootPath => '/home';
|
||||
|
||||
Future<void> addAnalysisSubscription(
|
||||
AnalysisService service,
|
||||
File file,
|
||||
) async {
|
||||
(_analysisFileSubscriptions[service] ??= []).add(file.path);
|
||||
await handleSuccessfulRequest(
|
||||
AnalysisSetSubscriptionsParams(
|
||||
_analysisFileSubscriptions,
|
||||
).toRequest('0'),
|
||||
);
|
||||
}
|
||||
|
||||
/// TODO(scheglov) rename
|
||||
void addTestFile(String content) {
|
||||
newFile(testFilePath, content);
|
||||
}
|
||||
|
||||
@override
|
||||
void createDefaultFiles() {
|
||||
writeTestPackageConfig();
|
||||
|
||||
writeTestPackageAnalysisOptionsFile(
|
||||
AnalysisOptionsFileConfig(
|
||||
experiments: experiments,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void deleteTestPackageAnalysisOptionsFile() {
|
||||
deleteAnalysisOptionsYamlFile(testPackageRootPath);
|
||||
}
|
||||
|
||||
void deleteTestPackageConfigJsonFile() {
|
||||
deletePackageConfigJsonFile(testPackageRootPath);
|
||||
}
|
||||
|
||||
/// Returns the offset of [search] in [testFileContent].
|
||||
/// Fails if not found.
|
||||
/// TODO(scheglov) Rename it.
|
||||
int findOffset(String search) {
|
||||
return offsetInFile(testFile, search);
|
||||
}
|
||||
|
||||
void modifyTestFile(String content) {
|
||||
modifyFile(testFilePath, content);
|
||||
}
|
||||
|
||||
/// Returns the offset of [search] in [file].
|
||||
/// Fails if not found.
|
||||
int offsetInFile(File file, String search) {
|
||||
var content = file.readAsStringSync();
|
||||
var offset = content.indexOf(search);
|
||||
expect(offset, isNot(-1));
|
||||
return offset;
|
||||
}
|
||||
|
||||
void writePackageConfig(Folder root, PackageConfigFileBuilder config) {
|
||||
newPackageConfigJsonFile(
|
||||
root.path,
|
||||
|
@ -299,12 +326,4 @@ class PubPackageAnalysisServerTest with ResourceProviderMixin {
|
|||
void writeTestPackagePubspecYamlFile(String content) {
|
||||
newPubspecYamlFile(testPackageRootPath, content);
|
||||
}
|
||||
|
||||
Future<void> _setGeneralAnalysisSubscriptions() async {
|
||||
await handleSuccessfulRequest(
|
||||
AnalysisSetGeneralSubscriptionsParams(
|
||||
_analysisGeneralServices,
|
||||
).toRequest('0'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue