Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(test): add --exclude-tags option
  • Loading branch information
felangel committed Mar 16, 2022
commit bfe8cd1ef384e90a2f22c532bdfb08be2bec2032
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ Run tests in a Dart or Flutter project.
# Run all tests
very_good test

# Run all tests and collect coverage
very_good test --coverage

# Run all tests and enforce 100% coverage
very_good test --coverage --min-coverage 100

# Run only tests in ./some/other/directory
very_good test ./some/other/directory

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

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

Run "very_good help <command>" for more information about a command.
```
Expand Down
11 changes: 10 additions & 1 deletion lib/src/commands/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class TestCommand extends Command<int> {
..addOption(
'min-coverage',
help: 'Whether to enforce a minimum coverage percentage.',
)
..addOption(
'exclude-tags',
abbr: 'x',
help: 'Run only tests that do not have the specified tags.',
);
}

Expand All @@ -52,6 +57,7 @@ class TestCommand extends Command<int> {
final minCoverage = double.tryParse(
_argResults['min-coverage'] as String? ?? '',
);
final excludeTags = _argResults['exclude-tags'] as String?;
final isFlutterInstalled = await Flutter.installed();
if (isFlutterInstalled) {
try {
Expand All @@ -61,7 +67,10 @@ class TestCommand extends Command<int> {
stderr: _logger.err,
collectCoverage: collectCoverage,
minCoverage: minCoverage,
arguments: argResults?.rest,
arguments: [
if (excludeTags != null) ...['-x', excludeTags],
..._argResults.rest,
],
);
} on PubspecNotFound catch (_) {
_logger.err(
Expand Down
39 changes: 39 additions & 0 deletions test/src/commands/test_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ void main() {
});
}''';

const testTagsContent = '''
import 'package:test/test.dart';
void main() {
test('example', () {
expect(true, isTrue);
});
test('...', () {
expect(true, isTrue);
}, tags: 'test-tag');
}''';

const expectedTestUsage = [
// ignore: no_adjacent_strings_in_list
'Run tests in a Dart or Flutter project.\n'
Expand All @@ -24,6 +36,7 @@ const expectedTestUsage = [
'-r, --recursive Run tests recursively for all nested packages.\n'
' --coverage Whether to collect coverage information.\n'
''' --min-coverage Whether to enforce a minimum coverage percentage.\n'''
'''-x, --exclude-tags Run only tests that do not have the specified tags.\n'''
'\n'
'Run "very_good help" to see global options.',
];
Expand Down Expand Up @@ -157,6 +170,32 @@ void main() {
}),
);

test(
'completes normally -x test-tag',
withRunner((commandRunner, logger, printLogs) async {
final directory = Directory.systemTemp.createTempSync();
Directory.current = directory.path;
final testDirectory = Directory(path.join(directory.path, 'test'))
..createSync();
File(
path.join(directory.path, 'pubspec.yaml'),
).writeAsStringSync(pubspecContent());
File(
path.join(testDirectory.path, 'example_test.dart'),
).writeAsStringSync(testTagsContent);
final result = await commandRunner.run(['test', '-x', 'test-tag']);
expect(result, equals(ExitCode.success.code));
verify(() {
logger.write(
any(that: contains('Running "flutter test" in')),
);
}).called(1);
verify(() {
logger.write(any(that: contains('+1: All tests passed!')));
}).called(1);
}),
);

test(
'completes normally --coverage --min-coverage 0',
withRunner((commandRunner, logger, printLogs) async {
Expand Down