Skip to content

Commit 96ed242

Browse files
committed
Add error for empty groups
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.
1 parent 0b306dd commit 96ed242

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

pkgs/test/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 1.24.3-wip
22

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

56
## 1.24.2
67

pkgs/test_api/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.5.3-wip
22

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

56
## 0.5.2
67

pkgs/test_api/lib/src/backend/declarer.dart

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'group_entry.dart';
1313
import 'invoker.dart';
1414
import 'metadata.dart';
1515
import 'test.dart';
16+
import 'test_failure.dart';
1617

1718
/// A class that manages the state of tests as they're declared.
1819
///
@@ -327,6 +328,11 @@ class Declarer {
327328
}
328329
return entry;
329330
}).toList();
331+
if (entries.isEmpty) {
332+
entries.add(LocalTest(_name ?? 'Empty group', _metadata, () {
333+
throw TestFailure('No tests declared in group');
334+
}));
335+
}
330336

331337
return Group(_name ?? '', entries,
332338
metadata: _metadata,

pkgs/test_api/test/backend/declarer_test.dart

+11
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,17 @@ void main() {
410410
});
411411
});
412412

413+
test('disallows empty groups', () async {
414+
var entries = declare(() {
415+
group('group', () {});
416+
});
417+
418+
expect(entries, hasLength(1));
419+
var testGroup = entries.single as Group;
420+
expect(testGroup.entries, hasLength(1));
421+
await _runTest(testGroup.entries.single as Test, shouldFail: true);
422+
});
423+
413424
group('.setUp()', () {
414425
test('is scoped to the group', () async {
415426
var setUpRun = false;

pkgs/test_core/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 0.5.3-wip
22

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

56
## 0.5.2
67

0 commit comments

Comments
 (0)