matcher icon indicating copy to clipboard operation
matcher copied to clipboard

`expect` functions should be typed

Open DetachHead opened this issue 3 years ago • 5 comments

expect(1, ""); // no compile error

it's annoying when my tests fail due to the expected and actual values being incompatible types. the compiler should be able to identify these issues before the tests are run

DetachHead avatar Jun 28 '22 12:06 DetachHead

You can try our work in progress new matching library which is type safe, https://github.com/dart-lang/test/tree/master/pkgs/checks

jakemac53 avatar Jun 28 '22 14:06 jakemac53

@jakemac53 thanks! is there an issue tracking the progress of the new library? if so i can close this issue

DetachHead avatar Jun 29 '22 09:06 DetachHead

cc @natebosch who is working on it

jakemac53 avatar Jun 29 '22 14:06 jakemac53

Also, for the record, very few types are strictly incompatible, to the point where no object can implement both, and also the == operator can accept objects of other types, so expect(v1, v2) isn't necessarily false when v1 and v2 have unrelated types.

lrhn avatar Jun 30 '22 09:06 lrhn

i get that, thought imo that's an edge case you can easily work around by explicitly specifying the generic:

checkThat<Object>(1).equals('');

DetachHead avatar Jun 30 '22 09:06 DetachHead