Skip to content

Commit e930aa7

Browse files
authored
[flutter_tools] Support boolean selectors and multiple tag options in test command (flutter#189193) (flutter#190541)
Fixes flutter#189193 In `TestCommand`, `--tags` (`-t`) and `--exclude-tags` (`-x`) were registered using `addOption(...)` instead of `addMultiOption(...)`. This scalar option definition retained only the last CLI occurrence when passed multiple times (`-t a -t b` became `'b'`). Additionally, default comma splitting in `package:args` mangled composite boolean selector expressions (`||`, `&&`, `!`) before forwarding arguments to `package:test`. This PR migrates `--tags` and `--exclude-tags` to `addMultiOption(..., splitCommas: false)` in `TestCommand` and updates `FlutterTestRunner` to forward all `--tags` and `--exclude-tags` values sequentially to `dart test`. ## Testing - Added hermetic regression test `passes boolean selectors and multiple tags/exclude-tags through to package:test` in `packages/flutter_tools/test/commands.shard/hermetic/test_test.dart`.
1 parent 1470e0a commit e930aa7

3 files changed

Lines changed: 54 additions & 16 deletions

File tree

‎packages/flutter_tools/lib/src/commands/test.dart‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,19 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
101101
valueHelp: 'substring',
102102
splitCommas: false,
103103
)
104-
..addOption(
104+
..addMultiOption(
105105
'tags',
106106
abbr: 't',
107107
help:
108108
'Run only tests associated with the specified tags. See: https://pub.dev/packages/test#tagging-tests',
109+
splitCommas: false,
109110
)
110-
..addOption(
111+
..addMultiOption(
111112
'exclude-tags',
112113
abbr: 'x',
113114
help:
114115
'Run only tests that do not have the specified tags. See: https://pub.dev/packages/test#tagging-tests',
116+
splitCommas: false,
115117
)
116118
..addFlag(
117119
'start-paused',
@@ -428,8 +430,8 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
428430
final bool buildTestAssets = boolArg('test-assets');
429431
final List<String> names = stringsArg('name');
430432
final List<String> plainNames = stringsArg('plain-name');
431-
final String? tags = stringArg('tags');
432-
final String? excludeTags = stringArg('exclude-tags');
433+
final List<String> tags = stringsArg('tags');
434+
final List<String> excludeTags = stringsArg('exclude-tags');
433435
final BuildInfo buildInfo = await getBuildInfo(
434436
forcedBuildMode: BuildMode.debug,
435437
forcedUseLocalCanvasKit: true,

‎packages/flutter_tools/lib/src/test/runner.dart‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ interface class FlutterTestRunner {
3838
required DebuggingOptions debuggingOptions,
3939
List<String> names = const <String>[],
4040
List<String> plainNames = const <String>[],
41-
String? tags,
42-
String? excludeTags,
41+
List<String> tags = const <String>[],
42+
List<String> excludeTags = const <String>[],
4343
bool enableVmService = false,
4444
bool machine = false,
4545
String? precompiledDillPath,
@@ -82,8 +82,8 @@ interface class FlutterTestRunner {
8282
for (final String name in names) ...<String>['--name', name],
8383
for (final String plainName in plainNames) ...<String>['--plain-name', plainName],
8484
if (randomSeed != null) '--test-randomize-ordering-seed=$randomSeed',
85-
if (tags != null) ...<String>['--tags', tags],
86-
if (excludeTags != null) ...<String>['--exclude-tags', excludeTags],
85+
for (final String tag in tags) ...<String>['--tags', tag],
86+
for (final String excludeTag in excludeTags) ...<String>['--exclude-tags', excludeTag],
8787
if (failFast) '--fail-fast',
8888
if (runSkipped) '--run-skipped',
8989
if (totalShards != null) '--total-shards=$totalShards',
@@ -589,8 +589,8 @@ class SpawnPlugin extends PlatformPlugin {
589589
required DebuggingOptions debuggingOptions,
590590
List<String> names = const <String>[],
591591
List<String> plainNames = const <String>[],
592-
String? tags,
593-
String? excludeTags,
592+
List<String> tags = const <String>[],
593+
List<String> excludeTags = const <String>[],
594594
bool machine = false,
595595
bool updateGoldens = false,
596596
required int? concurrency,
@@ -656,8 +656,8 @@ class SpawnPlugin extends PlatformPlugin {
656656
for (final String name in names) ...<String>['--name', name],
657657
for (final String plainName in plainNames) ...<String>['--plain-name', plainName],
658658
if (randomSeed != null) '--test-randomize-ordering-seed=$randomSeed',
659-
if (tags != null) ...<String>['--tags', tags],
660-
if (excludeTags != null) ...<String>['--exclude-tags', excludeTags],
659+
for (final String tag in tags) ...<String>['--tags', tag],
660+
for (final String excludeTag in excludeTags) ...<String>['--exclude-tags', excludeTag],
661661
if (failFast) '--fail-fast',
662662
if (runSkipped) '--run-skipped',
663663
if (totalShards != null) '--total-shards=$totalShards',

‎packages/flutter_tools/test/commands.shard/hermetic/test_test.dart‎

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,42 @@ dev_dependencies:
216216
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
217217
},
218218
);
219+
220+
testUsingContext(
221+
'passes boolean selectors and multiple tags/exclude-tags through to package:test',
222+
() async {
223+
final fakePackageTest = FakePackageTest();
224+
final testCommand = TestCommand(testWrapper: fakePackageTest);
225+
final CommandRunner<void> commandRunner = createTestCommandRunner(testCommand);
226+
227+
await commandRunner.run(<String>[
228+
'test',
229+
'--no-pub',
230+
'--tags=a || b',
231+
'--tags=c',
232+
'--exclude-tags=d && e',
233+
'--exclude-tags=f',
234+
]);
235+
expect(
236+
fakePackageTest.lastArgs,
237+
containsAllInOrder(<String>[
238+
'--tags',
239+
'a || b',
240+
'--tags',
241+
'c',
242+
'--exclude-tags',
243+
'd && e',
244+
'--exclude-tags',
245+
'f',
246+
]),
247+
);
248+
},
249+
overrides: <Type, Generator>{
250+
FileSystem: () => fs,
251+
ProcessManager: () => FakeProcessManager.any(),
252+
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
253+
},
254+
);
219255
});
220256

221257
group('--reporter/-r', () {
@@ -1692,8 +1728,8 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
16921728
required DebuggingOptions debuggingOptions,
16931729
List<String> names = const <String>[],
16941730
List<String> plainNames = const <String>[],
1695-
String? tags,
1696-
String? excludeTags,
1731+
List<String> tags = const <String>[],
1732+
List<String> excludeTags = const <String>[],
16971733
bool enableVmService = false,
16981734
bool ipv6 = false,
16991735
bool machine = false,
@@ -1750,8 +1786,8 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
17501786
required DebuggingOptions debuggingOptions,
17511787
List<String> names = const <String>[],
17521788
List<String> plainNames = const <String>[],
1753-
String? tags,
1754-
String? excludeTags,
1789+
List<String> tags = const <String>[],
1790+
List<String> excludeTags = const <String>[],
17551791
bool machine = false,
17561792
bool updateGoldens = false,
17571793
required int? concurrency,

0 commit comments

Comments
 (0)