Skip to content

Commit e1faaad

Browse files
derekxu16Commit Queue
authored andcommitted
[ResidentFrontendServer] Fix Windows test failures
Fixes: #59659 Change-Id: I3ea0b01c1e12ada5e33b2a43106cd5e8f318eb28 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399700 Reviewed-by: Ben Konyi <[email protected]>
1 parent 931fbb3 commit e1faaad

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

pkg/frontend_server/lib/resident_frontend_server_utils.dart

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:convert' show jsonDecode;
6-
import 'dart:io' show Directory, File, InternetAddress, Platform, Socket;
6+
import 'dart:io' show Directory, File, InternetAddress, Socket;
77

88
import 'package:path/path.dart' as path;
99

@@ -60,22 +60,15 @@ final class ResidentCompilerInfo {
6060
String computeCachedDillPath(
6161
final String canonicalizedLibraryPath,
6262
) {
63-
final int lastSeparatorPosInCanonicalizedLibraryPath =
64-
canonicalizedLibraryPath.lastIndexOf(Platform.pathSeparator);
65-
final String dirname = canonicalizedLibraryPath.substring(
66-
0,
67-
lastSeparatorPosInCanonicalizedLibraryPath,
68-
);
69-
final String basename = canonicalizedLibraryPath.substring(
70-
lastSeparatorPosInCanonicalizedLibraryPath + 1,
71-
);
63+
final String dirname = path.dirname(canonicalizedLibraryPath);
64+
final String basename = path.basename(canonicalizedLibraryPath);
7265

7366
final String cachedKernelDirectoryPath = path.join(
7467
path.join(
7568
Directory.systemTemp.path,
7669
'dart_resident_compiler_kernel_cache',
7770
),
78-
dirname.replaceAll('/', '_').replaceAll(r'\', '_'),
71+
dirname.replaceAll(new RegExp(r':|\\|\/'), '_'),
7972
);
8073

8174
try {

pkg/frontend_server/test/src/resident_frontend_server_test.dart

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import 'dart:io';
88

99
import 'package:frontend_server/src/resident_frontend_server.dart';
1010
import 'package:frontend_server/resident_frontend_server_utils.dart'
11-
show sendAndReceiveResponse;
11+
show computeCachedDillPath, sendAndReceiveResponse;
1212
import 'package:frontend_server/starter.dart';
1313
import 'package:path/path.dart' as path;
1414
import 'package:test/test.dart';
@@ -21,6 +21,40 @@ void main() async {
2121
// the unit tests will not be counted as modified.
2222
const int statGranularity = 1100;
2323

24+
group('Resident Frontend Server utility functions: ', () {
25+
test('computeCachedDillPath', () async {
26+
// [computeCachedDillPath] is implemented using [path.dirname] and
27+
// [path.basename], and those functions are platform-sensitive, so we test
28+
// with an example of a Windows path on Windows, and an example of a POSIX
29+
// path on other platforms.
30+
if (Platform.isWindows) {
31+
const String exampleCanonicalizedLibraryPath =
32+
r'C:\Users\user\directory\file.dart';
33+
expect(
34+
computeCachedDillPath(exampleCanonicalizedLibraryPath),
35+
path.join(
36+
Directory.systemTemp.path,
37+
'dart_resident_compiler_kernel_cache',
38+
'C__Users_user_directory_file',
39+
'file.dart.dill',
40+
),
41+
);
42+
} else {
43+
const String exampleCanonicalizedLibraryPath =
44+
'/home/user/directory/file.dart';
45+
expect(
46+
computeCachedDillPath(exampleCanonicalizedLibraryPath),
47+
path.join(
48+
Directory.systemTemp.path,
49+
'dart_resident_compiler_kernel_cache',
50+
'_home_user_directory',
51+
'file.dart.dill',
52+
),
53+
);
54+
}
55+
});
56+
});
57+
2458
group('Resident Frontend Server: invalid input: ', () {
2559
test('no command given', () async {
2660
final String jsonResponse = await ResidentFrontendServer.handleRequest(

0 commit comments

Comments
 (0)