Skip to content

Commit

Permalink
Strip leading slash when spawning isolate (#2136)
Browse files Browse the repository at this point in the history
Pull out a small utility for stripping leading slashes on windows from
the arg parsing code so it can be reused when spawning isolates by path.

It's still not clear what specific conditions lead to paths which look
like this, but the behavior is triggering for this path in another CI
system.
  • Loading branch information
natebosch authored Nov 10, 2023
1 parent 075faff commit 8ba0940
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 17 deletions.
4 changes: 4 additions & 0 deletions pkgs/test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.24.10-wip

* Handle paths with leading `/` when spawning test isolates.

## 1.24.9

* Update the vm_service constraint to allow version `13.x`.
Expand Down
4 changes: 2 additions & 2 deletions pkgs/test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: test
version: 1.24.9
version: 1.24.10-wip
description: >-
A full featured library for writing and running Dart tests across platforms.
repository: https://github.com/dart-lang/test/tree/master/pkgs/test
Expand Down Expand Up @@ -35,7 +35,7 @@ dependencies:

# Use an exact version until the test_api and test_core package are stable.
test_api: 0.6.1
test_core: 0.5.9
test_core: 0.5.10

typed_data: ^1.3.0
web_socket_channel: ^2.0.0
Expand Down
4 changes: 4 additions & 0 deletions pkgs/test_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.10-wip

* Handle paths with leading `/` when spawning test isolates.

## 0.5.9

* Update the vm_service constraint to allow version `13.x`.
Expand Down
13 changes: 1 addition & 12 deletions pkgs/test_core/lib/src/runner/configuration/args.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,7 @@ void _parseTestSelection(
}
}
final uri = Uri.parse(option);
// Decode the path segment. Specifically, on github actions back slashes on
// windows end up being encoded into the URI instead of converted into forward
// slashes.
var path = Uri.decodeComponent(uri.path);
// Strip out the leading slash before the drive letter on windows.
if (Platform.isWindows &&
path.startsWith('/') &&
path.length >= 3 &&
path[2] == ':') {
path = path.substring(1);
}

final path = Uri.decodeComponent(uri.path).stripDriveLetterLeadingSlash;
final names = uri.queryParametersAll['name'];
final fullName = uri.queryParameters['full-name'];
final line = uri.queryParameters['line'];
Expand Down
5 changes: 3 additions & 2 deletions pkgs/test_core/lib/src/runner/vm/platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,9 @@ stderr: ${processResult.stderr}''');

Future<Isolate> _spawnPrecompiledIsolate(String testPath, SendPort message,
String precompiledPath, Compiler compiler) async {
testPath =
_absolute('${p.join(precompiledPath, testPath)}.vm_test.dart').path;
testPath = _absolute('${p.join(precompiledPath, testPath)}.vm_test.dart')
.path
.stripDriveLetterLeadingSlash;
switch (compiler) {
case Compiler.kernel:
var dillTestpath =
Expand Down
16 changes: 16 additions & 0 deletions pkgs/test_core/lib/src/util/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,19 @@ extension RetryDelete on FileSystemEntity {
}
}
}

extension WindowsFilePaths on String {
/// Strip out the leading slash before the drive letter on windows.
///
/// In some windows environments full paths get passed with `/` before the
/// drive letter. Normalize paths to exclude this slash when it exists.
String get stripDriveLetterLeadingSlash {
if (Platform.isWindows &&
startsWith('/') &&
length >= 3 &&
this[2] == ':') {
return substring(1);
}
return this;
}
}
2 changes: 1 addition & 1 deletion pkgs/test_core/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: test_core
version: 0.5.9
version: 0.5.10-wip
description: A basic library for writing tests and running them on the VM.
repository: https://github.com/dart-lang/test/tree/master/pkgs/test_core

Expand Down

0 comments on commit 8ba0940

Please sign in to comment.