Skip to content

Commit

Permalink
[analysis_server] Add tests for Windows drive letter encoded colon issue
Browse files Browse the repository at this point in the history
See #53000

Committing separately to the revert of pathContext.fromUri() so if in future that CL is reverted (to re-land the change), it doesn't remove these tests.

Change-Id: I922e5e770a0c8dfcfc6a1cd41f6734d88c2edf7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315280
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
DanTup authored and Commit Queue committed Jul 21, 2023
1 parent be4189f commit d53070a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 0 additions & 5 deletions pkg/analysis_server/test/lsp/completion_dart_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3779,11 +3779,6 @@ void f() {
}

Future<void> test_snippets_testBlock() async {
// This test fails when running on macOS using Windows style paths. This
// is because DartSnippetProducer.isInTestDirectory compares a path using
// the tests PathContext (eg. backslashes when running as Windows-on-macOS)
// to `LinterContextImpl.testDirectories` which are always using native
// paths.
mainFilePath = join(projectFolderPath, 'test', 'foo_test.dart');
mainFileUri = pathContext.toUri(mainFilePath);
final content = '''
Expand Down
12 changes: 12 additions & 0 deletions pkg/analysis_server/test/lsp/initialization_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,11 @@ class InitializationTest extends AbstractLspAnalysisServerTest {
expect(server.contextManager.includedPaths, equals([projectFolderPath]));
}

Future<void> test_initialize_rootUri_encodedDriveLetterColon() async {
await initialize(rootUri: withEncodedDriveLetterColon(projectFolderUri));
expect(server.contextManager.includedPaths, equals([projectFolderPath]));
}

Future<void> test_initialize_rootUri_trailingSlash() async {
await initialize(rootUri: withTrailingSlashUri(projectFolderUri));
expect(server.contextManager.includedPaths, equals([projectFolderPath]));
Expand All @@ -865,6 +870,13 @@ class InitializationTest extends AbstractLspAnalysisServerTest {
expect(server.contextManager.includedPaths, equals([projectFolderPath]));
}

Future<void>
test_initialize_workspaceFolders_encodedDriveLetterColon() async {
await initialize(
workspaceFolders: [withEncodedDriveLetterColon(projectFolderUri)]);
expect(server.contextManager.includedPaths, equals([projectFolderPath]));
}

Future<void> test_initialize_workspaceFolders_trailingSlash() async {
await initialize(
workspaceFolders: [withTrailingSlashUri(projectFolderUri)]);
Expand Down
7 changes: 7 additions & 0 deletions pkg/analysis_server/test/lsp/server_abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ analyzer:
return verifier;
}

/// Encodes any drive letter colon in the URI.
///
/// file:///C:/foo -> file:///C%3A/foo
Uri withEncodedDriveLetterColon(Uri uri) {
return uri.replace(path: uri.path.replaceAll(':', '%3A'));
}

/// Adds a trailing slash (direction based on path context) to [path].
///
/// Throws if the path already has a trailing slash.
Expand Down
2 changes: 0 additions & 2 deletions pkg/analysis_server/test/lsp/server_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ class ServerTest extends AbstractLspAnalysisServerTest {
await initialize();
await expectLater(
getHover(missingDriveLetterFileUri, startOfDocPos),
// The pathContext.toUri() above translates to a non-file:// URI of just
// 'a/b.dart' so will get the not-file-scheme error message.
throwsA(isResponseError(ServerErrorCodes.InvalidFilePath,
message: 'URI was not an absolute file path (missing drive letter)')),
);
Expand Down

0 comments on commit d53070a

Please sign in to comment.