Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix parsing of windows file paths into a URI #1611

Merged
merged 6 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.19.1

* Fix parsing of file paths into a URI on windows.

## 1.19.0

* Support query parameters `name`, `full-name`, `line`, and `col` on test paths,
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.19.0
version: 1.19.1
description: >-
A full featured library for writing and running Dart tests across platforms.
repository: https://github.com/dart-lang/test/blob/master/pkgs/test
Expand Down Expand Up @@ -33,7 +33,7 @@ dependencies:
yaml: ^3.0.0
# Use an exact version until the test_api and test_core package are stable.
test_api: 0.4.6
test_core: 0.4.6
test_core: 0.4.7

dev_dependencies:
fake_async: ^1.0.0
Expand Down
2 changes: 1 addition & 1 deletion pkgs/test/test/runner/name_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void main() {

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

await test.shouldExit(255);
await test.shouldExit(64);
});

group('with the --name flag,', () {
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.4.7

* Fix parsing of file paths into a URI on windows.

## 0.4.6

* Support query parameters `name`, `full-name`, `line`, and `col` on test paths,
Expand Down
23 changes: 18 additions & 5 deletions pkgs/test_core/lib/src/runner/configuration/args.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ String get usage => _parser.usage;
Configuration parse(List<String> args) => _Parser(args).parse();

PathConfiguration _parsePathConfiguration(String option) {
var firstQuestion = option.indexOf('?');
if (firstQuestion == -1) {
return PathConfiguration(testPath: option);
} else if (option.substring(0, firstQuestion).contains('\\')) {
throw FormatException(
'When passing test path queries, you must pass the path in URI '
'format (use `/` for directory separators instead of `\\`).');
}

final uri = Uri.parse(option);

final names = uri.queryParametersAll['name'];
Expand Down Expand Up @@ -210,8 +219,9 @@ class _Parser {
/// Returns the parsed configuration.
Configuration parse() {
var patterns = (_options['name'] as List<String>)
.map<Pattern>(
(value) => _wrapFormatException('name', () => RegExp(value)))
.map<Pattern>((value) => _wrapFormatException(
value, () => RegExp(value),
optionName: 'name'))
.toList()
..addAll(_options['plain-name'] as List<String>);

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

return _wrapFormatException(name, () => parse(value as String));
return _wrapFormatException(value, () => parse(value as String),
optionName: name);
}

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

/// Runs [parse], and wraps any [FormatException] it throws with additional
/// information.
T _wrapFormatException<T>(String name, T Function() parse) {
T _wrapFormatException<T>(Object? value, T Function() parse,
{String? optionName}) {
try {
return parse();
} on FormatException catch (error) {
throw FormatException('Couldn\'t parse --$name "${_options[name]}": '
throw FormatException(
'Couldn\'t parse ${optionName == null ? '' : '--$optionName '}"$value": '
'${error.message}');
}
}
Expand Down
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.4.6
version: 0.4.7
description: A basic library for writing tests and running them on the VM.
homepage: https://github.com/dart-lang/test/blob/master/pkgs/test_core

Expand Down