From 777bb15b6fcaa54303cc72f7c914e1094f69dc76 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Thu, 21 Oct 2021 11:01:47 -0700 Subject: [PATCH] fix parsing of windows file paths into a URI (#1611) https://github.com/dart-lang/test/issues/1614 --- pkgs/test/CHANGELOG.md | 4 ++++ pkgs/test/pubspec.yaml | 4 ++-- pkgs/test/test/runner/name_test.dart | 2 +- pkgs/test_core/CHANGELOG.md | 4 ++++ .../lib/src/runner/configuration/args.dart | 23 +++++++++++++++---- pkgs/test_core/pubspec.yaml | 2 +- 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/pkgs/test/CHANGELOG.md b/pkgs/test/CHANGELOG.md index f17e0d167..6753d5b22 100644 --- a/pkgs/test/CHANGELOG.md +++ b/pkgs/test/CHANGELOG.md @@ -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, diff --git a/pkgs/test/pubspec.yaml b/pkgs/test/pubspec.yaml index e892a4613..cb7496f2b 100644 --- a/pkgs/test/pubspec.yaml +++ b/pkgs/test/pubspec.yaml @@ -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 @@ -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 diff --git a/pkgs/test/test/runner/name_test.dart b/pkgs/test/test/runner/name_test.dart index 301b21e24..a11f45ab7 100644 --- a/pkgs/test/test/runner/name_test.dart +++ b/pkgs/test/test/runner/name_test.dart @@ -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,', () { diff --git a/pkgs/test_core/CHANGELOG.md b/pkgs/test_core/CHANGELOG.md index 5ec11fac6..1596b3a90 100644 --- a/pkgs/test_core/CHANGELOG.md +++ b/pkgs/test_core/CHANGELOG.md @@ -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, diff --git a/pkgs/test_core/lib/src/runner/configuration/args.dart b/pkgs/test_core/lib/src/runner/configuration/args.dart index 71f4da3ff..59f8b943f 100644 --- a/pkgs/test_core/lib/src/runner/configuration/args.dart +++ b/pkgs/test_core/lib/src/runner/configuration/args.dart @@ -175,6 +175,15 @@ String get usage => _parser.usage; Configuration parse(List 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']; @@ -210,8 +219,9 @@ class _Parser { /// Returns the parsed configuration. Configuration parse() { var patterns = (_options['name'] as List) - .map( - (value) => _wrapFormatException('name', () => RegExp(value))) + .map((value) => _wrapFormatException( + value, () => RegExp(value), + optionName: 'name')) .toList() ..addAll(_options['plain-name'] as List); @@ -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? _parseFileReporterOption() => @@ -362,11 +373,13 @@ class _Parser { /// Runs [parse], and wraps any [FormatException] it throws with additional /// information. - T _wrapFormatException(String name, T Function() parse) { + T _wrapFormatException(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}'); } } diff --git a/pkgs/test_core/pubspec.yaml b/pkgs/test_core/pubspec.yaml index 46296a8b1..66e452217 100644 --- a/pkgs/test_core/pubspec.yaml +++ b/pkgs/test_core/pubspec.yaml @@ -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