Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
More places where Function() is too strict
Browse files Browse the repository at this point in the history
  • Loading branch information
natebosch committed Nov 22, 2023
1 parent b362392 commit 1fa085a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/src/core_matchers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ class isInstanceOf<T> extends TypeMatcher<T> {
/// a wrapper will have to be created.
const Matcher returnsNormally = _ReturnsNormally();

class _ReturnsNormally extends FeatureMatcher<Function()> {
class _ReturnsNormally extends FeatureMatcher<Function> {
const _ReturnsNormally();

@override
bool typedMatches(Function() f, Map matchState) {
bool typedMatches(Function f, Map matchState) {
try {
// ignore: avoid_dynamic_calls
f();
return true;
} catch (e, s) {
Expand Down
3 changes: 2 additions & 1 deletion test/core_matchers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ void main() {

test('returnsNormally', () {
shouldPass(doesNotThrow, returnsNormally);
shouldPass(doesNotThrowGeneric, returnsNormally);
shouldFail(
doesThrow,
returnsNormally,
matches(r'Expected: return normally'
r' Actual: <Closure.*>'
r' Which: threw StateError:<Bad state: X>'));
shouldFail('not a function', returnsNormally,
contains('not an <Instance of \'() => dynamic\'>'));
contains('not an <Instance of \'Function\'>'));
});

test('hasLength', () {
Expand Down
1 change: 1 addition & 0 deletions test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void shouldPass(Object? value, Matcher matcher) {
}

void doesNotThrow() {}
void doesNotThrowGeneric<T>() {}
void doesThrow() {
throw StateError('X');
}
Expand Down

0 comments on commit 1fa085a

Please sign in to comment.