Skip to content

Commit f84d488

Browse files
authored
feat(test): support --tags option (#421)
1 parent 0daf130 commit f84d488

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/src/commands/test/test.dart

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ class TestCommand extends Command<int> {
5050
help: 'Run tests recursively for all nested packages.',
5151
negatable: false,
5252
)
53+
..addOption(
54+
'tags',
55+
abbr: 't',
56+
help: 'Run only tests associated with the specified tags.',
57+
)
5358
..addFlag(
5459
'optimization',
5560
defaultsTo: true,
@@ -125,6 +130,7 @@ This command should be run from the root of your Flutter project.''',
125130
_argResults['min-coverage'] as String? ?? '',
126131
);
127132
final excludeTags = _argResults['exclude-tags'] as String?;
133+
final tags = _argResults['tags'] as String?;
128134
final isFlutterInstalled = await _flutterInstalled();
129135
final excludeFromCoverage = _argResults['exclude-coverage'] as String?;
130136
final randomOrderingSeed =
@@ -150,6 +156,7 @@ This command should be run from the root of your Flutter project.''',
150156
randomSeed: randomSeed,
151157
arguments: [
152158
if (excludeTags != null) ...['-x', excludeTags],
159+
if (tags != null) ...['-t', tags],
153160
if (updateGoldens) '--update-goldens',
154161
...['-j', concurrency],
155162
'--no-pub',

test/src/commands/test/test_test.dart

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const expectedTestUsage = [
1717
'-h, --help Print this usage information.\n'
1818
''' --coverage Whether to collect coverage information.\n'''
1919
'''-r, --recursive Run tests recursively for all nested packages.\n'''
20+
'''-t, --tags Run only tests associated with the specified tags.\n'''
2021
''' --[no-]optimization Whether to apply optimizations for test performance.\n'''
2122
' (defaults to on)\n'
2223
'''-j, --concurrency The number of concurrent test suites run.\n'''
@@ -290,6 +291,21 @@ void main() {
290291
).called(1);
291292
});
292293

294+
test('completes normally -t test-tag', () async {
295+
when<dynamic>(() => argResults['tags']).thenReturn('test-tag');
296+
final result = await testCommand.run();
297+
expect(result, equals(ExitCode.success.code));
298+
verify(
299+
() => flutterTest(
300+
optimizePerformance: true,
301+
arguments: ['-t', 'test-tag', ...defaultArguments],
302+
progress: logger.progress,
303+
stdout: logger.write,
304+
stderr: logger.err,
305+
),
306+
).called(1);
307+
});
308+
293309
test('completes normally -x test-tag', () async {
294310
when<dynamic>(() => argResults['exclude-tags']).thenReturn('test-tag');
295311
final result = await testCommand.run();

0 commit comments

Comments
 (0)