Skip to content

Commit

Permalink
Add error for empty groups
Browse files Browse the repository at this point in the history
Closes #1961

After declaring a group check for declared tests, if there were none add
a synthetic test that fails with an error about the empty group.
  • Loading branch information
natebosch committed May 10, 2023
1 parent 0b306dd commit 96ed242
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkgs/test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.24.3-wip

* Fix compatibility with wasm number semantics.
* Consider empty `group` to be test failures.

## 1.24.2

Expand Down
1 change: 1 addition & 0 deletions pkgs/test_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.5.3-wip

* Fix compatibility with wasm number semantics.
* Consider empty `group` to be test failures.

## 0.5.2

Expand Down
6 changes: 6 additions & 0 deletions pkgs/test_api/lib/src/backend/declarer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'group_entry.dart';
import 'invoker.dart';
import 'metadata.dart';
import 'test.dart';
import 'test_failure.dart';

/// A class that manages the state of tests as they're declared.
///
Expand Down Expand Up @@ -327,6 +328,11 @@ class Declarer {
}
return entry;
}).toList();
if (entries.isEmpty) {
entries.add(LocalTest(_name ?? 'Empty group', _metadata, () {
throw TestFailure('No tests declared in group');
}));
}

return Group(_name ?? '', entries,
metadata: _metadata,
Expand Down
11 changes: 11 additions & 0 deletions pkgs/test_api/test/backend/declarer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,17 @@ void main() {
});
});

test('disallows empty groups', () async {
var entries = declare(() {
group('group', () {});
});

expect(entries, hasLength(1));
var testGroup = entries.single as Group;
expect(testGroup.entries, hasLength(1));
await _runTest(testGroup.entries.single as Test, shouldFail: true);
});

group('.setUp()', () {
test('is scoped to the group', () async {
var setUpRun = false;
Expand Down
1 change: 1 addition & 0 deletions pkgs/test_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 0.5.3-wip

* Fix compatibility with wasm number semantics.
* Consider empty `group` to be test failures.

## 0.5.2

Expand Down

0 comments on commit 96ed242

Please sign in to comment.