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

throws-like should die on Bool:D matchers #2364

zoffixznet opened this issue Oct 13, 2018 · 0 comments


None yet
2 participants
Copy link

commented Oct 13, 2018

This is following #2363 that got closed...

<Zoffix_> m: use Test; class X::Foo is Exception { has $.meow = 42 }; throws-like { die }, X::Foo, :meow
<camelia> rakudo-moar 2c43d2bf5: OUTPUT: «    1..3␤    ok 1 - code dies␤    ok 2 - right exception type (X::Foo)␤    ok 3 - .meow matches True␤ok 1 - did we throws-like X::Foo?␤»

Above, the test writer specified they expect $.meow to contain Bool:D value True. However, since we do smartmatching on these matchers, regardless of the value, the check will always succeed (or always fail, if we're testing for False).

Quoted from #2363:

The named matchers in throws-like are smartmatched against the received Exception's methods and smartmatch against False is always False. To properly test for a Bool:D value you'd use (for example) * === False or * === True WhateverCode.

I think the change that should be made is to watch for Bool:D matchers and throw, the same as how we do with .grep for example:

$ perl6 -e '().grep: True'
Cannot use Bool as Matcher with '.grep'. Did you mean to use $_ inside a block?
in block at -e line 1
and perhaps improve the message of that exception (X::Match::Bool) to mention * === True / * === False WhateverCodes as well.

(N.B.: I don't really want it to do === test automatically for Bool:D matchers, as that breaks expectations of how smartmatch works elsewhere; best to consistently re-enforce that message)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.