Skip to content

Commit db3ac02

Browse files
authored
[flutter_tools] Add --preset option to flutter test (flutter#190878)
Adds support for \`--preset\` (and \`-P\`) to \`flutter test\`, allowing test presets defined in \`dart_test.yaml\` to be passed through to \`package:test\`. Fixes flutter#189191 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with \`///\`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent d794caa commit db3ac02

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
115115
'Run only tests that do not have the specified tags. See: https://pub.dev/packages/test#tagging-tests',
116116
splitCommas: false,
117117
)
118+
..addMultiOption(
119+
'preset',
120+
abbr: 'P',
121+
help: 'The configuration preset(s) to use. Presets are defined in "dart_test.yaml".',
122+
splitCommas: false,
123+
)
118124
..addFlag(
119125
'start-paused',
120126
negatable: false,
@@ -432,6 +438,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
432438
final List<String> plainNames = stringsArg('plain-name');
433439
final List<String> tags = stringsArg('tags');
434440
final List<String> excludeTags = stringsArg('exclude-tags');
441+
final List<String> presets = stringsArg('preset');
435442
final BuildInfo buildInfo = await getBuildInfo(
436443
forcedBuildMode: BuildMode.debug,
437444
forcedUseLocalCanvasKit: true,
@@ -676,6 +683,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
676683
plainNames: plainNames,
677684
tags: tags,
678685
excludeTags: excludeTags,
686+
presets: presets,
679687
machine: outputMachineFormat,
680688
updateGoldens: boolArg('update-goldens'),
681689
concurrency: jobs,
@@ -702,6 +710,7 @@ class TestCommand extends FlutterCommand with DeviceBasedDevelopmentArtifacts {
702710
plainNames: plainNames,
703711
tags: tags,
704712
excludeTags: excludeTags,
713+
presets: presets,
705714
watcher: watcher,
706715
enableVmService: collector != null || startPaused || enableVmService,
707716
machine: outputMachineFormat,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface class FlutterTestRunner {
4040
List<String> plainNames = const <String>[],
4141
List<String> tags = const <String>[],
4242
List<String> excludeTags = const <String>[],
43+
List<String> presets = const <String>[],
4344
bool enableVmService = false,
4445
bool machine = false,
4546
String? precompiledDillPath,
@@ -84,6 +85,7 @@ interface class FlutterTestRunner {
8485
if (randomSeed != null) '--test-randomize-ordering-seed=$randomSeed',
8586
for (final String tag in tags) ...<String>['--tags', tag],
8687
for (final String excludeTag in excludeTags) ...<String>['--exclude-tags', excludeTag],
88+
for (final String preset in presets) ...<String>['--preset', preset],
8789
if (failFast) '--fail-fast',
8890
if (runSkipped) '--run-skipped',
8991
if (totalShards != null) '--total-shards=$totalShards',
@@ -591,6 +593,7 @@ class SpawnPlugin extends PlatformPlugin {
591593
List<String> plainNames = const <String>[],
592594
List<String> tags = const <String>[],
593595
List<String> excludeTags = const <String>[],
596+
List<String> presets = const <String>[],
594597
bool machine = false,
595598
bool updateGoldens = false,
596599
required int? concurrency,
@@ -658,6 +661,7 @@ class SpawnPlugin extends PlatformPlugin {
658661
if (randomSeed != null) '--test-randomize-ordering-seed=$randomSeed',
659662
for (final String tag in tags) ...<String>['--tags', tag],
660663
for (final String excludeTag in excludeTags) ...<String>['--exclude-tags', excludeTag],
664+
for (final String preset in presets) ...<String>['--preset', preset],
661665
if (failFast) '--fail-fast',
662666
if (runSkipped) '--run-skipped',
663667
if (totalShards != null) '--total-shards=$totalShards',

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,46 @@ resolution: workspace
595595
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
596596
},
597597
);
598+
599+
testUsingContext(
600+
'passes --preset through to package:test',
601+
() async {
602+
final fakePackageTest = FakePackageTest();
603+
final testCommand = TestCommand(testWrapper: fakePackageTest);
604+
final CommandRunner<void> commandRunner = createTestCommandRunner(testCommand);
605+
606+
await commandRunner.run(<String>['test', '--no-pub', '--preset=foo', '--preset=bar']);
607+
expect(
608+
fakePackageTest.lastArgs,
609+
containsAllInOrder(<String>['--preset', 'foo', '--preset', 'bar']),
610+
);
611+
},
612+
overrides: <Type, Generator>{
613+
FileSystem: () => fs,
614+
ProcessManager: () => FakeProcessManager.any(),
615+
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
616+
},
617+
);
618+
619+
testUsingContext(
620+
'passes -P through to package:test',
621+
() async {
622+
final fakePackageTest = FakePackageTest();
623+
final testCommand = TestCommand(testWrapper: fakePackageTest);
624+
final CommandRunner<void> commandRunner = createTestCommandRunner(testCommand);
625+
626+
await commandRunner.run(<String>['test', '--no-pub', '-Pfoo', '-Pbar']);
627+
expect(
628+
fakePackageTest.lastArgs,
629+
containsAllInOrder(<String>['--preset', 'foo', '--preset', 'bar']),
630+
);
631+
},
632+
overrides: <Type, Generator>{
633+
FileSystem: () => fs,
634+
ProcessManager: () => FakeProcessManager.any(),
635+
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
636+
},
637+
);
598638
});
599639

600640
testUsingContext(
@@ -711,6 +751,7 @@ resolution: workspace
711751
'--test-randomize-ordering-seed=random',
712752
'--tags=tag1',
713753
'--exclude-tags=tag2',
754+
'--preset=preset1',
714755
'--fail-fast',
715756
'--run-skipped',
716757
'--total-shards=1',
@@ -749,6 +790,8 @@ const List<String> packageTestArgs = <String>[
749790
'tag1',
750791
'--exclude-tags',
751792
'tag2',
793+
'--preset',
794+
'preset1',
752795
'--fail-fast',
753796
'--run-skipped',
754797
'--total-shards=1',
@@ -1738,6 +1781,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
17381781
List<String> plainNames = const <String>[],
17391782
List<String> tags = const <String>[],
17401783
List<String> excludeTags = const <String>[],
1784+
List<String> presets = const <String>[],
17411785
bool enableVmService = false,
17421786
bool ipv6 = false,
17431787
bool machine = false,
@@ -1796,6 +1840,7 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
17961840
List<String> plainNames = const <String>[],
17971841
List<String> tags = const <String>[],
17981842
List<String> excludeTags = const <String>[],
1843+
List<String> presets = const <String>[],
17991844
bool machine = false,
18001845
bool updateGoldens = false,
18011846
required int? concurrency,

0 commit comments

Comments
 (0)