Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change test function to detect when it is called with a Matcher Function() instead of a Matcher #222

Open
whesse opened this issue Apr 20, 2022 · 3 comments
Labels
type-enhancement A request for a change that isn't a bug

Comments

@whesse
Copy link

whesse commented Apr 20, 2022

With instantiated constructor tearoffs, the dynamic argument to test(actual, dynamic matcher) can accidentally be IsA instead of IsA().

It would be nice to detect that, and give a useful error, or automatically generate the Matcher in that case.

Reported as issue dart-lang/sdk#48842

@lrhn

@jakemac53
Copy link
Contributor

Hmm, that does seem like something that is easy to do accidentally. But at the same time I am worried about false positives (similar to the concern raised in the original issue).

It seems to me that the experience we really want is that of a lint, it shows up early (in the IDE), and you can ignore false positives fairly easily. But you also have to explicitly enable it, which is less good, and the code for it ends up very disconnected from this package, which is also not ideal.

I don't particularly like the idea of a runtime error or warning here (we actually have no notion of warnings at all in this package). Many matchers themselves take matchers or objects, and it would probably be difficult to make sure we had good consistent coverage everywhere.

@whesse
Copy link
Author

whesse commented Apr 20, 2022

One thing that might avoid false positives is that the case here (forgetting the parentheses after a matcher constructor) would return a function that takes no arguments. Can that be checked in a type-check? I think no valid use of matcher would actually want to match a concrete object of that function type.

@jakemac53
Copy link
Contributor

jakemac53 commented Apr 20, 2022

I think no valid use of matcher would actually want to match a concrete object of that function type.

Tests of matchers (or utility code that returns matchers) are an example potentially valid use case :).

@devoncarew devoncarew added the type-enhancement A request for a change that isn't a bug label Apr 26, 2022
@natebosch natebosch transferred this issue from dart-lang/test May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants