Skip to content

Commit 009656a

Browse files
authored
feat: add flavor option to test command (#1530)
1 parent f63571a commit 009656a

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

lib/src/commands/test/test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class FlutterTestOptions {
2929
required this.platform,
3030
required this.reportOn,
3131
required this.runSkipped,
32+
required this.flavor,
3233
required this.rest,
3334
});
3435

@@ -63,6 +64,7 @@ class FlutterTestOptions {
6364
final platform = argResults['platform'] as String?;
6465
final reportOn = argResults['report-on'] as String?;
6566
final runSkipped = argResults['run-skipped'] as bool;
67+
final flavor = argResults['flavor'] as String?;
6668
final rest = argResults.rest;
6769

6870
return FlutterTestOptions._(
@@ -84,6 +86,7 @@ class FlutterTestOptions {
8486
platform: platform,
8587
reportOn: reportOn,
8688
runSkipped: runSkipped,
89+
flavor: flavor,
8790
rest: rest,
8891
);
8992
}
@@ -144,6 +147,9 @@ class FlutterTestOptions {
144147
/// Whether to run skipped tests instead of skipping them.
145148
final bool runSkipped;
146149

150+
/// The flavor to build for testing.
151+
final String? flavor;
152+
147153
/// The remaining arguments passed to the test command.
148154
final List<String> rest;
149155
}
@@ -314,6 +320,13 @@ class TestCommand extends Command<int> {
314320
'run-skipped',
315321
help: 'Run skipped tests instead of skipping them.',
316322
negatable: false,
323+
)
324+
..addOption(
325+
'flavor',
326+
help:
327+
'Build a custom app flavor as defined by platform-specific build '
328+
'setup. Supports the use of product flavors in Android Gradle '
329+
'scripts, and the use of custom Xcode schemes.',
317330
);
318331
}
319332

@@ -383,6 +396,7 @@ This command should be run from the root of your Flutter project.''');
383396
if (options.updateGoldens) '--update-goldens',
384397
if (options.failFast) '--fail-fast',
385398
if (options.runSkipped) '--run-skipped',
399+
if (options.flavor != null) ...['--flavor', options.flavor!],
386400
if (options.platform != null) ...['--platform', options.platform!],
387401
if (options.dartDefine != null)
388402
for (final value in options.dartDefine!) '--dart-define=$value',

test/src/commands/test/test_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const expectedTestUsage = [
4949
' --platform=<chrome|vm|android|ios> The platform to run tests on. \n'
5050
' --report-on=<lib/> An optional file path to report coverage information to. This should be a path relative to the current working directory.\n'
5151
' --run-skipped Run skipped tests instead of skipping them.\n'
52+
' --flavor Build a custom app flavor as defined by platform-specific build setup. Supports the use of product flavors in Android Gradle scripts, and the use of custom Xcode schemes.\n'
5253
'\n'
5354
'Run "very_good help" to see global options.',
5455
];
@@ -131,6 +132,7 @@ void main() {
131132
when<dynamic>(() => argResults['platform']).thenReturn(null);
132133
when<dynamic>(() => argResults['report-on']).thenReturn(null);
133134
when<dynamic>(() => argResults['run-skipped']).thenReturn(false);
135+
when<dynamic>(() => argResults['flavor']).thenReturn(null);
134136
when<dynamic>(
135137
() => argResults['collect-coverage-from'],
136138
).thenReturn('imports');
@@ -795,6 +797,21 @@ void main() {
795797
},
796798
);
797799

800+
test('completes normally --flavor development', () async {
801+
when<dynamic>(() => argResults['flavor']).thenReturn('development');
802+
final result = await testCommand.run();
803+
expect(result, equals(ExitCode.success.code));
804+
verify(
805+
() => flutterTest(
806+
optimizePerformance: true,
807+
arguments: ['--flavor', 'development', ...defaultArguments],
808+
logger: logger,
809+
stdout: logger.write,
810+
stderr: logger.err,
811+
),
812+
).called(1);
813+
});
814+
798815
test('completes normally --run-skipped', () async {
799816
when<dynamic>(() => argResults['run-skipped']).thenReturn(true);
800817
final result = await testCommand.run();

0 commit comments

Comments
 (0)