Skip to content

Commit 386ca6c

Browse files
authored
feat(test): add --exclude-tags option (#314)
1 parent 65428ae commit 386ca6c

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ Run tests in a Dart or Flutter project.
139139
# Run all tests
140140
very_good test
141141

142+
# Run all tests and collect coverage
143+
very_good test --coverage
144+
145+
# Run all tests and enforce 100% coverage
146+
very_good test --coverage --min-coverage 100
147+
142148
# Run only tests in ./some/other/directory
143149
very_good test ./some/other/directory
144150

@@ -159,6 +165,7 @@ Usage: very_good test [arguments]
159165
-r, --recursive Run tests recursively for all nested packages.
160166
--coverage Whether to collect coverage information.
161167
--min-coverage Whether to enforce a minimum coverage percentage.
168+
-x, --exclude-tags Run only tests that do not have the specified tags.
162169

163170
Run "very_good help" to see global options.
164171
```
@@ -184,6 +191,7 @@ Available commands:
184191
create very_good create <output directory>
185192
Creates a new very good project in the specified directory.
186193
packages Command for managing packages.
194+
test Run tests in a Dart or Flutter project.
187195

188196
Run "very_good help <command>" for more information about a command.
189197
```

lib/src/commands/test.dart

+10-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ class TestCommand extends Command<int> {
2727
..addOption(
2828
'min-coverage',
2929
help: 'Whether to enforce a minimum coverage percentage.',
30+
)
31+
..addOption(
32+
'exclude-tags',
33+
abbr: 'x',
34+
help: 'Run only tests that do not have the specified tags.',
3035
);
3136
}
3237

@@ -52,6 +57,7 @@ class TestCommand extends Command<int> {
5257
final minCoverage = double.tryParse(
5358
_argResults['min-coverage'] as String? ?? '',
5459
);
60+
final excludeTags = _argResults['exclude-tags'] as String?;
5561
final isFlutterInstalled = await Flutter.installed();
5662
if (isFlutterInstalled) {
5763
try {
@@ -61,7 +67,10 @@ class TestCommand extends Command<int> {
6167
stderr: _logger.err,
6268
collectCoverage: collectCoverage,
6369
minCoverage: minCoverage,
64-
arguments: argResults?.rest,
70+
arguments: [
71+
if (excludeTags != null) ...['-x', excludeTags],
72+
..._argResults.rest,
73+
],
6574
);
6675
} on PubspecNotFound catch (_) {
6776
_logger.err(

test/src/commands/test_test.dart

+39
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@ void main() {
1515
});
1616
}''';
1717

18+
const testTagsContent = '''
19+
import 'package:test/test.dart';
20+
void main() {
21+
test('example', () {
22+
expect(true, isTrue);
23+
});
24+
25+
test('...', () {
26+
expect(true, isTrue);
27+
}, tags: 'test-tag');
28+
}''';
29+
1830
const expectedTestUsage = [
1931
// ignore: no_adjacent_strings_in_list
2032
'Run tests in a Dart or Flutter project.\n'
@@ -24,6 +36,7 @@ const expectedTestUsage = [
2436
'-r, --recursive Run tests recursively for all nested packages.\n'
2537
' --coverage Whether to collect coverage information.\n'
2638
''' --min-coverage Whether to enforce a minimum coverage percentage.\n'''
39+
'''-x, --exclude-tags Run only tests that do not have the specified tags.\n'''
2740
'\n'
2841
'Run "very_good help" to see global options.',
2942
];
@@ -157,6 +170,32 @@ void main() {
157170
}),
158171
);
159172

173+
test(
174+
'completes normally -x test-tag',
175+
withRunner((commandRunner, logger, printLogs) async {
176+
final directory = Directory.systemTemp.createTempSync();
177+
Directory.current = directory.path;
178+
final testDirectory = Directory(path.join(directory.path, 'test'))
179+
..createSync();
180+
File(
181+
path.join(directory.path, 'pubspec.yaml'),
182+
).writeAsStringSync(pubspecContent());
183+
File(
184+
path.join(testDirectory.path, 'example_test.dart'),
185+
).writeAsStringSync(testTagsContent);
186+
final result = await commandRunner.run(['test', '-x', 'test-tag']);
187+
expect(result, equals(ExitCode.success.code));
188+
verify(() {
189+
logger.write(
190+
any(that: contains('Running "flutter test" in')),
191+
);
192+
}).called(1);
193+
verify(() {
194+
logger.write(any(that: contains('+1: All tests passed!')));
195+
}).called(1);
196+
}),
197+
);
198+
160199
test(
161200
'completes normally --coverage --min-coverage 0',
162201
withRunner((commandRunner, logger, printLogs) async {

0 commit comments

Comments
 (0)