Skip to content

Commit 777bb15

Browse files
authored
fix parsing of windows file paths into a URI (#1611)
#1614
1 parent 497900f commit 777bb15

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

pkgs/test/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.19.1
2+
3+
* Fix parsing of file paths into a URI on windows.
4+
15
## 1.19.0
26

37
* Support query parameters `name`, `full-name`, `line`, and `col` on test paths,

pkgs/test/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: test
2-
version: 1.19.0
2+
version: 1.19.1
33
description: >-
44
A full featured library for writing and running Dart tests across platforms.
55
repository: https://github.com/dart-lang/test/blob/master/pkgs/test
@@ -33,7 +33,7 @@ dependencies:
3333
yaml: ^3.0.0
3434
# Use an exact version until the test_api and test_core package are stable.
3535
test_api: 0.4.6
36-
test_core: 0.4.6
36+
test_core: 0.4.7
3737

3838
dev_dependencies:
3939
fake_async: ^1.0.0

pkgs/test/test/runner/name_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ void main() {
294294

295295
var test = await runTest(['test.dart?name=selected&full-name=selected 1']);
296296

297-
await test.shouldExit(255);
297+
await test.shouldExit(64);
298298
});
299299

300300
group('with the --name flag,', () {

pkgs/test_core/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.7
2+
3+
* Fix parsing of file paths into a URI on windows.
4+
15
## 0.4.6
26

37
* Support query parameters `name`, `full-name`, `line`, and `col` on test paths,

pkgs/test_core/lib/src/runner/configuration/args.dart

+18-5
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ String get usage => _parser.usage;
175175
Configuration parse(List<String> args) => _Parser(args).parse();
176176

177177
PathConfiguration _parsePathConfiguration(String option) {
178+
var firstQuestion = option.indexOf('?');
179+
if (firstQuestion == -1) {
180+
return PathConfiguration(testPath: option);
181+
} else if (option.substring(0, firstQuestion).contains('\\')) {
182+
throw FormatException(
183+
'When passing test path queries, you must pass the path in URI '
184+
'format (use `/` for directory separators instead of `\\`).');
185+
}
186+
178187
final uri = Uri.parse(option);
179188

180189
final names = uri.queryParametersAll['name'];
@@ -210,8 +219,9 @@ class _Parser {
210219
/// Returns the parsed configuration.
211220
Configuration parse() {
212221
var patterns = (_options['name'] as List<String>)
213-
.map<Pattern>(
214-
(value) => _wrapFormatException('name', () => RegExp(value)))
222+
.map<Pattern>((value) => _wrapFormatException(
223+
value, () => RegExp(value),
224+
optionName: 'name'))
215225
.toList()
216226
..addAll(_options['plain-name'] as List<String>);
217227

@@ -342,7 +352,8 @@ class _Parser {
342352
var value = _options[name];
343353
if (value == null) return null;
344354

345-
return _wrapFormatException(name, () => parse(value as String));
355+
return _wrapFormatException(value, () => parse(value as String),
356+
optionName: name);
346357
}
347358

348359
Map<String, String>? _parseFileReporterOption() =>
@@ -362,11 +373,13 @@ class _Parser {
362373

363374
/// Runs [parse], and wraps any [FormatException] it throws with additional
364375
/// information.
365-
T _wrapFormatException<T>(String name, T Function() parse) {
376+
T _wrapFormatException<T>(Object? value, T Function() parse,
377+
{String? optionName}) {
366378
try {
367379
return parse();
368380
} on FormatException catch (error) {
369-
throw FormatException('Couldn\'t parse --$name "${_options[name]}": '
381+
throw FormatException(
382+
'Couldn\'t parse ${optionName == null ? '' : '--$optionName '}"$value": '
370383
'${error.message}');
371384
}
372385
}

pkgs/test_core/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: test_core
2-
version: 0.4.6
2+
version: 0.4.7
33
description: A basic library for writing tests and running them on the VM.
44
homepage: https://github.com/dart-lang/test/blob/master/pkgs/test_core
55

0 commit comments

Comments
 (0)