Skip to content

Commit

Permalink
[analysis_server] Replace URI fields in tests with getters to avoid h…
Browse files Browse the repository at this point in the history
…aving to set all paths twice

This is a minor refactoring to swap some fields for URIs to getters so that any tests that modify them don't have to set both a path and URI (or risk them being out-of-sync).

Change-Id: Ic3776d250f4cfd9b0f16a7fc578ab5e7f19e52a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384762
Reviewed-by: Brian Wilkerson <[email protected]>
Reviewed-by: Phil Quitslund <[email protected]>
Commit-Queue: Brian Wilkerson <[email protected]>
  • Loading branch information
DanTup authored and Commit Queue committed Sep 11, 2024
1 parent e4b505b commit 0ed6907
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
1 change: 0 additions & 1 deletion pkg/analysis_server/benchmark/perf/memory_tests.dart
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ class LspAnalysisServerBenchmarkTest extends AbstractBenchmarkTest
_test.instrumentationService = InstrumentationLogAdapter(_logger);
await _test.setUp();
_test.projectFolderPath = roots.single;
_test.projectFolderUri = Uri.file(_test.projectFolderPath);
await _test.initialize();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,8 @@ abstract class AbstractLspAnalysisServerIntegrationTest
.resolveSymbolicLinksSync();
newFolder(projectFolderPath);
newFolder(join(projectFolderPath, 'lib'));
projectFolderUri = Uri.file(projectFolderPath);
mainFilePath = join(projectFolderPath, 'lib', 'main.dart');
mainFileUri = Uri.file(mainFilePath);
analysisOptionsPath = join(projectFolderPath, 'analysis_options.yaml');
analysisOptionsUri = Uri.file(analysisOptionsPath);

var client = LspServerClient(instrumentationService);
this.client = client;
Expand Down
2 changes: 0 additions & 2 deletions pkg/analysis_server/test/lsp/completion_dart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4472,7 +4472,6 @@ void f() {

Future<void> test_snippets_testBlock() async {
mainFilePath = join(projectFolderPath, 'test', 'foo_test.dart');
mainFileUri = pathContext.toUri(mainFilePath);
var content = '''
void f() {
test^
Expand All @@ -4497,7 +4496,6 @@ void f() {

Future<void> test_snippets_testGroupBlock() async {
mainFilePath = join(projectFolderPath, 'test', 'foo_test.dart');
mainFileUri = pathContext.toUri(mainFilePath);
var content = '''
void f() {
group^
Expand Down
26 changes: 16 additions & 10 deletions pkg/analysis_server/test/lsp/server_abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,14 @@ abstract class AbstractLspAnalysisServerTest
server.pluginManager = pluginManager;

projectFolderPath = convertPath('/home/my_project');
projectFolderUri = toUri(projectFolderPath);
newFolder(projectFolderPath);
newFolder(join(projectFolderPath, 'lib'));
// Create a folder and file to aid testing that includes imports/completion.
newFolder(join(projectFolderPath, 'lib', 'folder'));
newFile(join(projectFolderPath, 'lib', 'file.dart'), '');
mainFilePath = join(projectFolderPath, 'lib', 'main.dart');
mainFileUri = toUri(mainFilePath);
nonExistentFilePath = join(projectFolderPath, 'lib', 'not_existing.dart');
nonExistentFileUri = toUri(nonExistentFilePath);
pubspecFilePath = join(projectFolderPath, file_paths.pubspecYaml);
pubspecFileUri = toUri(pubspecFilePath);
analysisOptionsPath = join(projectFolderPath, 'analysis_options.yaml');
newFile(analysisOptionsPath, '''
analyzer:
Expand All @@ -313,7 +309,6 @@ analyzer:
- wildcard-variables
''');

analysisOptionsUri = pathContext.toUri(analysisOptionsPath);
writeTestPackageConfig();
}

Expand Down Expand Up @@ -804,11 +799,7 @@ mixin LspAnalysisServerTestMixin
nonExistentFilePath,
pubspecFilePath,
analysisOptionsPath;
late Uri projectFolderUri,
mainFileUri,
nonExistentFileUri,
pubspecFileUri,
analysisOptionsUri;

final String simplePubspecContent = 'name: my_project';

/// The client capabilities sent to the server during initialization.
Expand Down Expand Up @@ -845,6 +836,9 @@ mixin LspAnalysisServerTestMixin
/// server.
bool failTestOnErrorDiagnostic = true;

/// [analysisOptionsPath] as a 'file:///' [Uri].
Uri get analysisOptionsUri => pathContext.toUri(analysisOptionsPath);

/// A stream of [NotificationMessage]s from the server that may be errors.
Stream<NotificationMessage> get errorNotificationsFromServer {
return notificationsFromServer.where(_isErrorNotification);
Expand All @@ -867,6 +861,12 @@ mixin LspAnalysisServerTestMixin
/// The URI for the macro-generated contents for [mainFileUri].
Uri get mainFileMacroUri => mainFileUri.replace(scheme: macroClientUriScheme);

/// [mainFilePath] as a 'file:///' [Uri].
Uri get mainFileUri => pathContext.toUri(mainFilePath);

/// [nonExistentFilePath] as a 'file:///' [Uri].
Uri get nonExistentFileUri => pathContext.toUri(nonExistentFilePath);

/// A stream of [NotificationMessage]s from the server.
@override
Stream<NotificationMessage> get notificationsFromServer {
Expand All @@ -883,6 +883,9 @@ mixin LspAnalysisServerTestMixin

path.Context get pathContext;

/// [projectFolderPath] as a 'file:///' [Uri].
Uri get projectFolderUri => pathContext.toUri(projectFolderPath);

/// A stream of diagnostic notifications from the server.
Stream<PublishDiagnosticsParams> get publishedDiagnostics {
return notificationsFromServer
Expand All @@ -892,6 +895,9 @@ mixin LspAnalysisServerTestMixin
notification.params as Map<String, Object?>));
}

/// [pubspecFilePath] as a 'file:///' [Uri].
Uri get pubspecFileUri => pathContext.toUri(pubspecFilePath);

/// A stream of [RequestMessage]s from the server.
Stream<RequestMessage> get requestsFromServer {
return serverToClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,6 @@ class A {}
// Put the file in tool/ so we can use a package: import for the file
// above but get a relative import back to src.
mainFilePath = join(projectFolderPath, 'tool', 'main.dart');
// TODO(dantup): Make these URIs getters to avoid setting these twice in
// each test.
mainFileUri = pathContext.toUri(mainFilePath);

newFile(libFilePath, 'mixin PackageMixin {};');
var originalSource = '''
Expand Down

0 comments on commit 0ed6907

Please sign in to comment.