Skip to content

Commit 451d918

Browse files
authored
Fix some extensions + file util tests on Windows (#8846)
* Fix some extensions + file util tests * Rename projectRoot -> projectRootUriString * Rename directoryPath -> projectRootDirectoryUriString
1 parent 05012db commit 451d918

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

packages/devtools_shared/test/helpers/extension_test_manager.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ class TestPackageWithExtension {
394394
final bool requiresConnection;
395395
final bool isPubliclyHosted;
396396
final String? packageVersion;
397+
398+
/// The relative path from the extensions.
399+
///
400+
/// Uses the paths separator for the current platform.
397401
final String relativePathFromExtensions;
398402

399403
String get configYamlContent => '''
@@ -439,8 +443,9 @@ ${_dependenciesAsString()}
439443
} else {
440444
sb
441445
..writeln() // Add a new line for the path dependency.
446+
// Always write paths in pubspec.yaml with forward slashes.
442447
..writeln(
443-
' path: $pathToExtensions/${dep.relativePathFromExtensions}',
448+
' path: $pathToExtensions/${dep.relativePathFromExtensions.replaceAll(r'\', '/')}',
444449
);
445450
}
446451
}

packages/devtools_shared/test/helpers/extension_test_manager_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd.
44

5+
import 'package:path/path.dart' as p;
56
import 'package:test/test.dart';
67

78
import 'extension_test_manager.dart';
@@ -115,7 +116,7 @@ requiresConnection: false
115116
expect(newerStaticExtension1Package.packageVersion, null);
116117
expect(
117118
newerStaticExtension1Package.relativePathFromExtensions,
118-
'newer/static_extension_1',
119+
p.join('newer', 'static_extension_1'),
119120
);
120121
expect(
121122
newerStaticExtension1Package.pubspecContent,

packages/devtools_shared/test/server/devtools_extensions_api_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ void main() {
146146

147147
group(ExtensionsApi.apiExtensionEnabledState, () {
148148
late File optionsFile;
149-
late final optionsFileUriString = p.join(
149+
late final optionsFileUriString = p.posix.join(
150150
extensionTestManager.runtimeAppRoot,
151151
devtoolsOptionsFileName,
152152
);
153153

154154
setUp(() async {
155155
await initializeTestDirectory();
156-
optionsFile = File.fromUri(Uri.file(optionsFileUriString));
156+
optionsFile = File.fromUri(Uri.parse(optionsFileUriString));
157157
});
158158

159159
Future<Response> sendEnabledStateRequest({
@@ -374,7 +374,7 @@ void _verifyExtension(
374374
ext.extensionAssetsPath,
375375
endsWith(
376376
p.join(
377-
'.pub-cache',
377+
Platform.isWindows ? r'Pub\Cache' : '.pub-cache',
378378
'hosted',
379379
'pub.dev',
380380
'${extensionPackage.name}-${extensionPackage.packageVersion}',
@@ -401,7 +401,7 @@ void _verifyExtension(
401401
expect(
402402
ext.devtoolsOptionsUri,
403403
endsWith(
404-
p.join('packages', detectedFromPath, devtoolsOptionsFileName),
404+
p.posix.join('packages', detectedFromPath, devtoolsOptionsFileName),
405405
),
406406
);
407407
expect(ext.detectedFromStaticContext, fromStaticContext);

packages/devtools_shared/test/utils/file_utils_test.dart

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ import 'package:test/test.dart';
1212
import '../helpers/helpers.dart';
1313

1414
const projectRootParts = ['absolute_path_to', 'my_app_root'];
15-
late String projectRoot;
15+
16+
/// The project root as a URI string.
17+
late String projectRootUriString;
1618

1719
late Directory testDirectory;
1820
late File libFile;
@@ -46,7 +48,7 @@ void main() {
4648

4749
await testDtdConnection!.setIDEWorkspaceRoots(
4850
dtd!.info!.secret!,
49-
[Uri.parse(projectRoot)],
51+
[Uri.parse(projectRootUriString)],
5052
);
5153
});
5254

@@ -72,7 +74,7 @@ void main() {
7274
dtd: useDtd ? testDtdConnection! : null,
7375
throwOnDtdSearchFailed: useDtd,
7476
);
75-
expect(result, equals(expected ?? projectRoot));
77+
expect(result, equals(expected ?? projectRootUriString));
7678
}
7779

7880
test('packageRootFromFileUriString throw exception for invalid input', () {
@@ -130,24 +132,26 @@ void main() {
130132
// Dart file in a nested project.
131133
await verifyPackageRoot(
132134
nestedProjectLibFile.uri.toString(),
133-
expected: p.join(projectRoot, 'example', 'nested_project'),
135+
expected:
136+
p.posix.join(projectRootUriString, 'example', 'nested_project'),
134137
useDtd: useDtd,
135138
);
136139
await verifyPackageRoot(
137140
nestedProjectTestFile.uri.toString(),
138-
expected: p.join(projectRoot, 'example', 'nested_project'),
141+
expected:
142+
p.posix.join(projectRootUriString, 'example', 'nested_project'),
139143
useDtd: useDtd,
140144
);
141145

142146
// Dart file under an unknown directory.
143147
await verifyPackageRoot(
144148
anyFile.uri.toString(),
145-
expected: useDtd ? projectRoot : anyFile.uri.toString(),
149+
expected: useDtd ? projectRootUriString : anyFile.uri.toString(),
146150
useDtd: useDtd,
147151
);
148152
await verifyPackageRoot(
149153
anySubFile.uri.toString(),
150-
expected: useDtd ? projectRoot : anySubFile.uri.toString(),
154+
expected: useDtd ? projectRootUriString : anySubFile.uri.toString(),
151155
useDtd: useDtd,
152156
);
153157
},
@@ -200,11 +204,12 @@ void _setupTestDirectoryStructure() {
200204
final projectRootDirectory =
201205
Directory(p.joinAll([testDirectory.path, ...projectRootParts]))
202206
..createSync(recursive: true);
203-
final directoryPath =
207+
final projectRootDirectoryUriString =
204208
Uri.file(projectRootDirectory.uri.toFilePath()).toString();
205209

206210
// Remove the trailing slash and set the value of [projectRoot].
207-
projectRoot = directoryPath.substring(0, directoryPath.length - 1);
211+
projectRootUriString = projectRootDirectoryUriString.substring(
212+
0, projectRootDirectoryUriString.length - 1);
208213

209214
// Set up the project root contents.
210215
Directory(p.join(projectRootDirectory.path, '.dart_tool'))

0 commit comments

Comments
 (0)