Skip to content
New issue

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

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

Already on GitHub? # to your account

Improve matcher isInstanceOf now that Dart has first class types. #15381

Closed
DartBot opened this issue Nov 29, 2013 · 9 comments
Closed

Improve matcher isInstanceOf now that Dart has first class types. #15381

DartBot opened this issue Nov 29, 2013 · 9 comments
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Nov 29, 2013

This issue was originally filed by greg...@gmail.com


Current: new isInstanceOf<T>(T t)

New: isInstanceOf2(Type t). // But with a better name.

Consider adding:
  throwsType(Type t)

Also worth updating these docs:

"As types are not first class objects in Dart we can only approximate this test by using a generic wrapper class."

"Note that this does not currently work in dart2js; it will match any type, and isNot(new isInstanceof<T>()) will always fail. This is because dart2js currently ignores template type parameters."

https://api.dartlang.org/docs/channels/stable/latest/matcher/isInstanceOf.html

https://www.dartlang.org/articles/writing-unit-tests-for-pub-packages/

@sethladd
Copy link
Contributor

sethladd commented Dec 2, 2013

Removed Type-Defect label.
Added Type-Enhancement, Area-UnitTest, Triaged labels.

@kevmoo
Copy link
Member

kevmoo commented Feb 12, 2014

Removed Area-UnitTest label.
Added Area-Pkg, Pkg-Unittest labels.

@kevmoo
Copy link
Member

kevmoo commented May 9, 2014

Removed Pkg-Unittest label.
Added Pkg-matcher label.

@DartBot
Copy link
Author

DartBot commented May 26, 2014

This comment was originally written by @vicb


This is something I have implemented in Guinness as:

    bool matches(obj, Map matchState) =>
        mirrors.reflect(obj).type.isSubtypeOf(mirrors.reflectClass(_type));

see https://github.com/vsavkin/guinness/blob/5f9e291f9c0937a19ab278b0afe7c377bfae25fe/lib/src/common/unittest_backend.dart#L191 for the full Matcher

We have started to discuss this with Kevin: https://plus.google.com/u/0/+VictorBerchet/posts/bdDgAfUB9bW?cfem=1

I'm not clear on how this would affect the generated code size:

  • we don't need more info as what the current impl (isInstanceOf<T>(T t)) uses, would there be a way to prevent the JS size to sky rocket ?
  • even if there is no way to limit the JS size, would that be a pb - considering we are running tests ?

(I've not really considered JS & its code size for my use case. The reasoning being that if the tests pass with Dart, they should pass after dart2js, if not then this is a dart2js and not your own code issue. The tests are supposed to test your own code, not dart2js - still I'm all for testing with dart2js to help stabilize the tools as long as there is no constraint on my development flow).

@DartBot
Copy link
Author

DartBot commented May 27, 2014

This comment was originally written by greg...@gmail.com


I was under the impression that this was already possible:

  bool isInstance(obj, Type type) => obj is type;
  
But it looks like this is possible - yet?

"malformed type: line 5 pos 18: using 't' in this context is invalid"

I wonder if there is a bug for implementing this - or if it is not possible. In the VM it must just be an int check. Not sure about dart2js.

@DartBot
Copy link
Author

DartBot commented May 27, 2014

This comment was originally written by greg.lo...@gmail.com


Erm - "But it looks like this is NOT possible - yet?"

@DartBot
Copy link
Author

DartBot commented Nov 25, 2014

This comment was originally written by @seaneagan


In issue #10406 gbracha indicates that this will only be possible via mirrors. Matchers that use mirrors are currently put here:

http://www.dartdocs.org/documentation/matcher/0.11.1/index.html#matcher/matcher-mirror_matchers

Also this issue is a duplicate of issue #10407 which was wrongly merged with issue #8138.

@DartBot
Copy link
Author

DartBot commented Nov 25, 2014

This comment was originally written by @seaneagan


Once this is fixed, all the custom throwsArgumentError etc. matchers could easily be removed / cleaned up, since you could just do throwsA(ArgumentError).

@DartBot DartBot added Type-Enhancement area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. labels Nov 25, 2014
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

This issue has been moved to dart-lang/test#2334.

@DartBot DartBot closed this as completed Jun 5, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed triaged labels Mar 1, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants