Skip to content

Commit 5803acf

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Update plugin tests to work through test runner
This removes a use of `Platform.script` so the tests work through the test runner. It also extracts some common code between this and the other integration tests to remove some duplication. Change-Id: Ia9d441424789ea99decb071f7fdc6c71c8e54a72 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419860 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent 853654d commit 5803acf

File tree

4 files changed

+60
-67
lines changed

4 files changed

+60
-67
lines changed

pkg/analysis_server/test/integration/lsp_server/integration_tests.dart

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'dart:async';
66
import 'dart:convert';
77
import 'dart:io';
8-
import 'dart:isolate';
98

109
import 'package:analysis_server/lsp_protocol/protocol.dart';
1110
import 'package:analysis_server/src/lsp/channel/lsp_byte_stream_channel.dart';
@@ -17,6 +16,7 @@ import 'package:path/path.dart';
1716

1817
import '../../lsp/request_helpers_mixin.dart';
1918
import '../../lsp/server_abstract.dart';
19+
import '../../support/sdk_paths.dart';
2020

2121
abstract class AbstractLspAnalysisServerIntegrationTest
2222
with
@@ -200,29 +200,7 @@ class LspServerClient {
200200
}
201201

202202
var dartBinary = join(dartSdkPath, 'bin', 'dart');
203-
204-
// Setting the `TEST_SERVER_SNAPSHOT` env var to 'false' will disable the
205-
// snapshot and run from source.
206-
var useSnapshot = Platform.environment['TEST_SERVER_SNAPSHOT'] != 'false';
207-
String serverPath;
208-
209-
if (useSnapshot) {
210-
// TODO(dantup): Consider changing this to "dart language_server" and
211-
// sharing this code with legacy-server integration tests.
212-
serverPath = normalize(
213-
join(dartSdkPath, 'bin', 'snapshots', 'analysis_server.dart.snapshot'),
214-
);
215-
} else {
216-
// Locate the root of the analysis server package without using
217-
// `Platform.script` as it fails when run through the `dart test`.
218-
// https://github.com/dart-lang/test/issues/110
219-
var serverLibUri = await Isolate.resolvePackageUri(
220-
Uri.parse('package:analysis_server/'),
221-
);
222-
serverPath = normalize(
223-
join(serverLibUri!.toFilePath(), '..', 'bin', 'server.dart'),
224-
);
225-
}
203+
var serverPath = getAnalysisServerPath(dartSdkPath);
226204

227205
var arguments = [...?vmArgs, serverPath, '--lsp', '--suppress-analytics'];
228206
var process = await Process.start(

pkg/analysis_server/test/integration/support/integration_tests.dart

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:async';
66
import 'dart:collection';
77
import 'dart:convert';
88
import 'dart:io';
9-
import 'dart:isolate';
109

1110
import 'package:analysis_server/protocol/protocol_constants.dart';
1211
import 'package:analysis_server/protocol/protocol_generated.dart';
@@ -21,6 +20,7 @@ import 'package:test/test.dart';
2120

2221
import '../../analysis_server_base.dart' show analysisOptionsContent;
2322
import '../../support/configuration_files.dart';
23+
import '../../support/sdk_paths.dart';
2424
import 'integration_test_methods.dart';
2525
import 'protocol_matchers.dart';
2626

@@ -677,34 +677,7 @@ class Server {
677677
_time.start();
678678

679679
var dartBinary = path.join(dartSdkPath, 'bin', 'dart');
680-
681-
// Setting the `TEST_SERVER_SNAPSHOT` env var to 'false' will disable the
682-
// snapshot and run from source.
683-
var useSnapshot = Platform.environment['TEST_SERVER_SNAPSHOT'] != 'false';
684-
String serverPath;
685-
686-
if (useSnapshot) {
687-
// TODO(dantup): Consider changing this to "dart language_server" and
688-
// sharing this code with LSP integration tests.
689-
serverPath = path.normalize(
690-
path.join(
691-
dartSdkPath,
692-
'bin',
693-
'snapshots',
694-
'analysis_server.dart.snapshot',
695-
),
696-
);
697-
} else {
698-
// Locate the root of the analysis server package without using
699-
// `Platform.script` as it fails when run through the `dart test`.
700-
// https://github.com/dart-lang/test/issues/110
701-
var serverLibUri = await Isolate.resolvePackageUri(
702-
Uri.parse('package:analysis_server/'),
703-
);
704-
serverPath = path.normalize(
705-
path.join(serverLibUri!.toFilePath(), '..', 'bin', 'server.dart'),
706-
);
707-
}
680+
var serverPath = getAnalysisServerPath(dartSdkPath);
708681

709682
var arguments = <String>['--disable-dart-dev', '--no-dds'];
710683
//

pkg/analysis_server/test/src/plugin/plugin_manager_test.dart

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import 'package:test/test.dart';
2323
import 'package:test_reflective_loader/test_reflective_loader.dart';
2424
import 'package:watcher/watcher.dart' as watcher;
2525

26+
import '../../support/sdk_paths.dart';
27+
2628
void main() {
2729
defineReflectiveSuite(() {
2830
defineReflectiveTests(BuiltInPluginInfoTest);
@@ -876,19 +878,6 @@ class MinimalPlugin extends ServerPlugin {
876878
}
877879
''';
878880

879-
/// The path to the package config file in the root of the Dart SDK.
880-
static String get _sdkPackageConfigPath {
881-
var filePath = io.Platform.script.toFilePath();
882-
// Walk up the directory structure from this script file to the
883-
// 'analysis_server' root directory.
884-
while (filePath.isNotEmpty &&
885-
path.basename(filePath) != 'analysis_server') {
886-
filePath = path.dirname(filePath);
887-
}
888-
filePath = path.dirname(path.dirname(filePath));
889-
return path.join(filePath, '.dart_tool', 'package_config.json');
890-
}
891-
892881
late PhysicalResourceProvider resourceProvider;
893882

894883
late TestNotificationManager notificationManager;
@@ -930,7 +919,7 @@ class MinimalPlugin extends ServerPlugin {
930919
path.join(pluginDartToolPath, 'package_config.json'),
931920
);
932921
packageConfigFile.writeAsStringSync(
933-
io.File(_sdkPackageConfigPath).readAsStringSync(),
922+
io.File(sdkPackageConfigPath).readAsStringSync(),
934923
);
935924
//
936925
// Create the 'bin' directory.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:io';
6+
import 'dart:isolate';
7+
8+
import 'package:path/path.dart' as path;
9+
10+
/// The path of the `pkg/analysis_server` folder, resolved using the active
11+
/// `package_config.json`.
12+
String get analysisServerPackagePath {
13+
// Locate the root of the analysis server package without using
14+
// `Platform.script` as it fails when run through the `dart test`.
15+
// https://github.com/dart-lang/test/issues/110
16+
var serverLibUri = Isolate.resolvePackageUriSync(
17+
Uri.parse('package:analysis_server/'),
18+
);
19+
return path.normalize(path.join(serverLibUri!.toFilePath(), '..'));
20+
}
21+
22+
/// The path of the `package_config.json` file in the root of the SDK,
23+
/// computed by resolving the path to `pkg:analysis_server`.
24+
String get sdkPackageConfigPath {
25+
return path.normalize(
26+
path.join(sdkRootPath, '.dart_tool', 'package_config.json'),
27+
);
28+
}
29+
30+
/// The path the SDK, computed as the parent of the `pkg/analysis_server`
31+
/// folder, resolved using the active `package_config.json`.
32+
String get sdkRootPath {
33+
return path.normalize(path.join(analysisServerPackagePath, '..', '..'));
34+
}
35+
36+
/// Gets the path of the analysis server entry point which may be a snapshot
37+
/// or the source script depending on the `TEST_SERVER_SNAPSHOT` environment
38+
/// variable.
39+
String getAnalysisServerPath(String dartSdkPath) {
40+
var snapshotPath = path.join(
41+
dartSdkPath,
42+
'bin',
43+
'snapshots',
44+
'analysis_server.dart.snapshot',
45+
);
46+
var sourcePath = path.join(analysisServerPackagePath, 'bin', 'server.dart');
47+
48+
// Setting the `TEST_SERVER_SNAPSHOT` env var to 'false' will disable the
49+
// snapshot and run from source.
50+
var useSnapshot = Platform.environment['TEST_SERVER_SNAPSHOT'] != 'false';
51+
var serverPath = useSnapshot ? snapshotPath : sourcePath;
52+
return path.normalize(serverPath);
53+
}

0 commit comments

Comments
 (0)