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

Use runtimeType in expect/throwsA #8138

Closed
DartBot opened this issue Jan 26, 2013 · 11 comments
Closed

Use runtimeType in expect/throwsA #8138

DartBot opened this issue Jan 26, 2013 · 11 comments
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. closed-obsolete Closed as the reported issue is no longer relevant

Comments

@DartBot
Copy link

DartBot commented Jan 26, 2013

This issue was originally filed by @sethladd


This doc is what the docs recommends:

expect(() => store.keys(), throwsA(new isInstanceOf<StateError>()));

However, we now have .runtimeType. Can we instead make the matcher more simple?

This works:

test(obj, Type type) {
  return (obj.runtimeType == type);
}

void main() {
  print(test(new StateError('foo'), StateError));
}

I'd love to see:

expect(() => store.keys(), throwsA(StateError));

Thoughts?

@DartBot
Copy link
Author

DartBot commented Jan 26, 2013

This comment was originally written by @sethladd


Drat. Title should be something like: "Add a match to match against type"

@lrhn
Copy link
Member

lrhn commented Jan 26, 2013

Notice that this only tests for type equality, not subtype relation.
If the StateError thrown is actually an internal subtype of StateError, the test will fail, event though it is a StateError.

It really needs to be a subtype test in order to maintain the substitution principle.
A workaround is to always override runtimeType on internal classes, but I don't think it's feasible in practice.

In the longer run, we might want to allow type objects as the right-hand operand of the "is" operator.


Added Area-Pkg, Package-Unittest, Triaged labels.
Changed the title to: "Use runtimeType in expect/throwsA".

@DartBot
Copy link
Author

DartBot commented Jan 28, 2013

This comment was originally written by @butlermatt


I'm curious why this error does not have a pre-set matcher similar to 'throwsArgumentError' or 'throwsRangeError' etc. I realize not all errors are represented here but I would think stateError to be used enough to warrant its inclusion.

@munificent
Copy link
Member

It should be. I think it's just that the pre-set matchers were created before the Great Exception Type Cleanup of 2013. File a separate bug for this?

@DartBot
Copy link
Author

DartBot commented Jan 29, 2013

This comment was originally written by @sethladd


One step ahead: http://code.google.com/p/dart/issues/detail?id=8137 :)

@DartBot
Copy link
Author

DartBot commented Jan 29, 2013

This comment was originally written by @sethladd


Lasse, you're right. I poorly worded the title. Instead, a better title should be: "Add a matcher that tests an object's type and that works in dart2js"

Thanks for the clarification!

@gramster
Copy link

I'm not sure now whether you still want this, Seth. It seems without subtype support it isn't very useful.

@scheglov
Copy link
Contributor

Yes.
Can we have subtype support in language please? :-)

@gramster
Copy link

Issue #10407 has been merged into this issue.

@DartBot
Copy link
Author

DartBot commented Nov 1, 2013

This comment was originally written by @seaneagan


This should be marked as blocked on issue #10406.

@sethladd
Copy link
Contributor

Added AssumedStale label.

@DartBot DartBot added Type-Defect area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. closed-obsolete Closed as the reported issue is no longer relevant labels Jul 16, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. closed-obsolete Closed as the reported issue is no longer relevant
Projects
None yet
Development

No branches or pull requests

7 participants