Skip to content

Support running tests by absolute file: uri #1893

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

Merged
merged 20 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2630361
add a test for running by absolute file: uri
jakemac53 Feb 1, 2023
3497202
use p.url
jakemac53 Feb 1, 2023
3965b20
run on all platforms, rely on p.toUri to create the file URI
jakemac53 Feb 1, 2023
ab1ac62
update test name, assert that the uri is in fact a file: uri
jakemac53 Feb 1, 2023
cf3f9f2
always parse test paths as uris and grab paths from that
jakemac53 Feb 1, 2023
5912d65
add a test for running paths with a relative windows path
jakemac53 Feb 1, 2023
b33927f
update to use d.dir to create the root dir
jakemac53 Feb 1, 2023
7d17773
only parse as a Uri if it looks like it has a scheme
jakemac53 Feb 1, 2023
4aa2934
update changelog
jakemac53 Feb 1, 2023
847de6f
copy changelog entry to package:test as well
jakemac53 Feb 1, 2023
b3b958d
simplify logic a bit, unify URI parsing
jakemac53 Feb 2, 2023
4d2e580
further simplify logic, always parse test paths as URIs, but decode t…
jakemac53 Feb 2, 2023
8e87f7f
update tests to always expect test path outputs to be in URI format
jakemac53 Feb 2, 2023
e118ac7
remove unused imports
jakemac53 Feb 2, 2023
605dd1d
restore decodeComponent logic, add test for windows style path with q…
jakemac53 Feb 2, 2023
a499e13
fix windows, try removing decodeComponent logic again
jakemac53 Feb 3, 2023
b8f7c01
remove unused import
jakemac53 Feb 3, 2023
1a0588e
Merge branch 'master' into file-uri-test
jakemac53 Feb 6, 2023
c7520bd
restore decodeComponent logic
jakemac53 Feb 6, 2023
3078f79
Merge branch 'master' into file-uri-test
jakemac53 Feb 6, 2023
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
1 change: 1 addition & 0 deletions pkgs/test/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
reporter.
* Add support for CHROME_EXECUTABLE environment variable. This overrides any
config file settings.
* Support running tests by absolute file uri.

## 1.22.2

Expand Down
13 changes: 4 additions & 9 deletions pkgs/test/test/runner/configuration/platform_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

@TestOn('vm')
import 'dart:convert';
import 'dart:io';

import 'package:test/test.dart';
import 'package:test_core/src/util/exit_codes.dart' as exit_codes;
Expand Down Expand Up @@ -205,10 +204,8 @@ void main() {
var test = await runTest(['.']);
expect(
test.stdout,
containsInOrder([
'+0: .${Platform.pathSeparator}test_foo.dart: test_foo',
'+1: All tests passed!'
]));
containsInOrder(
['+0: ./test_foo.dart: test_foo', '+1: All tests passed!']));
await test.shouldExit(0);
});

Expand Down Expand Up @@ -243,10 +240,8 @@ void main() {
var test = await runTest(['.']);
expect(
test.stdout,
containsInOrder([
'+0: .${Platform.pathSeparator}foo_test.dart: foo_test',
'+1: All tests passed!'
]));
containsInOrder(
['+0: ./foo_test.dart: foo_test', '+1: All tests passed!']));
await test.shouldExit(0);
});

Expand Down
13 changes: 6 additions & 7 deletions pkgs/test/test/runner/configuration/randomize_order_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

@TestOn('vm')
import 'dart:convert';
import 'dart:io';

import 'package:test/test.dart';
import 'package:test_descriptor/test_descriptor.dart' as d;
Expand Down Expand Up @@ -148,14 +147,14 @@ void main() {
test.stdout,
emitsInAnyOrder([
containsInOrder([
'.${Platform.pathSeparator}1_test.dart: test 1.2',
'.${Platform.pathSeparator}1_test.dart: test 1.3',
'.${Platform.pathSeparator}1_test.dart: test 1.1'
'./1_test.dart: test 1.2',
'./1_test.dart: test 1.3',
'./1_test.dart: test 1.1'
]),
containsInOrder([
'.${Platform.pathSeparator}2_test.dart: test 2.2',
'.${Platform.pathSeparator}2_test.dart: test 2.3',
'.${Platform.pathSeparator}2_test.dart: test 2.1'
'./2_test.dart: test 2.2',
'./2_test.dart: test 2.3',
'./2_test.dart: test 2.1'
]),
contains('+6: All tests passed!')
]));
Expand Down
25 changes: 25 additions & 0 deletions pkgs/test/test/runner/runner_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import 'dart:io';
import 'dart:math' as math;

import 'package:path/path.dart' as p;
import 'package:test/test.dart';
import 'package:test_core/src/util/exit_codes.dart' as exit_codes;
import 'package:test_descriptor/test_descriptor.dart' as d;
Expand Down Expand Up @@ -362,6 +363,30 @@ $_usage''');
expect(test.stdout, emitsThrough(contains('+1: All tests passed!')));
await test.shouldExit(0);
});

test('given a file: uri', () async {
await d.file('test.dart', _success).create();
var fileUri = p.toUri(d.path('test.dart')).toString();
expect(fileUri, startsWith('file:///'));
var test = await runTest([fileUri]);
expect(test.stdout, emitsThrough(contains('+1: All tests passed!')));
await test.shouldExit(0);
});

test('with platform specific relative paths', () async {
await d.dir('foo', [d.file('test.dart', _success)]).create();
var test = await runTest([p.join('foo', 'test.dart')]);
expect(test.stdout, emitsThrough(contains('+1: All tests passed!')));
await test.shouldExit(0);
});

test('with platform specific relative paths containing query params',
() async {
await d.dir('foo', [d.file('test.dart', _success)]).create();
var test = await runTest(['${p.join('foo', 'test.dart')}?line=6']);
expect(test.stdout, emitsThrough(contains('+1: All tests passed!')));
await test.shouldExit(0);
});
});

group('runs successful tests with async setup', () {
Expand Down
39 changes: 12 additions & 27 deletions pkgs/test/test/runner/shard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

@TestOn('vm')

import 'dart:io';

import 'package:test/test.dart';
import 'package:test_core/src/util/exit_codes.dart' as exit_codes;
import 'package:test_descriptor/test_descriptor.dart' as d;
Expand Down Expand Up @@ -95,14 +92,10 @@ void main() {
test.stdout,
emitsInOrder([
emitsAnyOf([
containsInOrder([
'+0: .${Platform.pathSeparator}1_test.dart: test 1.1',
'+1: .${Platform.pathSeparator}2_test.dart: test 2.1'
]),
containsInOrder([
'+0: .${Platform.pathSeparator}2_test.dart: test 2.1',
'+1: .${Platform.pathSeparator}1_test.dart: test 1.1'
])
containsInOrder(
['+0: ./1_test.dart: test 1.1', '+1: ./2_test.dart: test 2.1']),
containsInOrder(
['+0: ./2_test.dart: test 2.1', '+1: ./1_test.dart: test 1.1'])
]),
contains('+2: All tests passed!')
]));
Expand All @@ -113,14 +106,10 @@ void main() {
test.stdout,
emitsInOrder([
emitsAnyOf([
containsInOrder([
'+0: .${Platform.pathSeparator}1_test.dart: test 1.2',
'+1: .${Platform.pathSeparator}2_test.dart: test 2.2'
]),
containsInOrder([
'+0: .${Platform.pathSeparator}2_test.dart: test 2.2',
'+1: .${Platform.pathSeparator}1_test.dart: test 1.2'
])
containsInOrder(
['+0: ./1_test.dart: test 1.2', '+1: ./2_test.dart: test 2.2']),
containsInOrder(
['+0: ./2_test.dart: test 2.2', '+1: ./1_test.dart: test 1.2'])
]),
contains('+2: All tests passed!')
]));
Expand All @@ -131,14 +120,10 @@ void main() {
test.stdout,
emitsInOrder([
emitsAnyOf([
containsInOrder([
'+0: .${Platform.pathSeparator}1_test.dart: test 1.3',
'+1: .${Platform.pathSeparator}2_test.dart: test 2.3'
]),
containsInOrder([
'+0: .${Platform.pathSeparator}2_test.dart: test 2.3',
'+1: .${Platform.pathSeparator}1_test.dart: test 1.3'
])
containsInOrder(
['+0: ./1_test.dart: test 1.3', '+1: ./2_test.dart: test 2.3']),
containsInOrder(
['+0: ./2_test.dart: test 2.3', '+1: ./1_test.dart: test 1.3'])
]),
contains('+2: All tests passed!')
]));
Expand Down
1 change: 1 addition & 0 deletions pkgs/test_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Avoid empty expandable groups for tests without extra output in Github
reporter.
* Support running tests by absolute file uri.
* Update `vm_service` constraint to `>=6.0.0 <12.0.0`.

# 0.4.22
Expand Down
4 changes: 2 additions & 2 deletions pkgs/test_core/lib/src/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'dart:io';

import 'package:async/async.dart';
import 'package:boolean_selector/boolean_selector.dart';
import 'package:path/path.dart' as p;
import 'package:stack_trace/stack_trace.dart';
// ignore: deprecated_member_use
import 'package:test_api/backend.dart'
Expand Down Expand Up @@ -317,7 +316,8 @@ class Runner {
'Cannot filter by line/column for this test suite, no suite'
'path available.');
}
var absoluteSuitePath = p.absolute(path);
// The absolute path as it will appear in stack traces.
var absoluteSuitePath = File(path).absolute.uri.toFilePath();

bool matchLineAndCol(Frame frame) {
if (frame.uri.scheme != 'file' ||
Expand Down
56 changes: 25 additions & 31 deletions pkgs/test_core/lib/src/runner/configuration/args.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,41 +177,35 @@ Configuration parse(List<String> args) => _Parser(args).parse();

void _parseTestSelection(
String option, Map<String, Set<TestSelection>> selections) {
var firstQuestion = option.indexOf('?');
TestSelection selection;
String path;
if (firstQuestion == -1) {
path = option;
selection = TestSelection();
} 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 `\\`).');
} else {
final uri = Uri.parse(option);
final uri = Uri.parse(option);
// Restore the path to how it was given (namely, we want to report paths
// with their original separators).
var path = Uri.decodeComponent(uri.path);
// Strip out the leading slash before the drive letter on windows.
if (Platform.isWindows && path.startsWith('/')) {
path = path.substring(1);
}

final names = uri.queryParametersAll['name'];
final fullName = uri.queryParameters['full-name'];
final line = uri.queryParameters['line'];
final col = uri.queryParameters['col'];
final names = uri.queryParametersAll['name'];
final fullName = uri.queryParameters['full-name'];
final line = uri.queryParameters['line'];
final col = uri.queryParameters['col'];

if (names != null && names.isNotEmpty && fullName != null) {
throw FormatException(
'Cannot specify both "name=<...>" and "full-name=<...>".',
);
}
path = uri.path;
selection = TestSelection(
testPatterns: fullName != null
? {RegExp('^${RegExp.escape(fullName)}\$')}
: {
if (names != null)
for (var name in names) RegExp(name)
},
line: line == null ? null : int.parse(line),
col: col == null ? null : int.parse(col),
if (names != null && names.isNotEmpty && fullName != null) {
throw FormatException(
'Cannot specify both "name=<...>" and "full-name=<...>".',
);
}
final selection = TestSelection(
testPatterns: fullName != null
? {RegExp('^${RegExp.escape(fullName)}\$')}
: {
if (names != null)
for (var name in names) RegExp(name)
},
line: line == null ? null : int.parse(line),
col: col == null ? null : int.parse(col),
);

selections.update(path, (selections) => selections..add(selection),
ifAbsent: () => {selection});
Expand Down