Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Testing of exception during import

by haukex (Archbishop)
on Jul 01, 2022 at 18:46 UTC ( #11145230=note: print w/replies, xml ) Need Help??


in reply to Testing of exception during import

IMHO testing is one of those places where you can break some of the "rules" like "don't use stringy eval" or "don't check the boolean status of $@ to see if the eval failed or not". The following works on your example code:

use warnings; use strict; use Test::More tests=>12; ok ! defined eval "use My::Test; 1"; like $@, qr/\bNumber of import parameters is wrong\b/i; ok ! defined eval "use My::Test qw/foo/; 1"; like $@, qr/\bNumber of import parameters is wrong\b/i; ok ! defined eval "use My::Test qw/foo bar/; 1"; like $@, qr/\bNumber of import parameters is wrong\b/i; ok ! defined eval "use My::Test qw/foo bar quz baz/; 1"; like $@, qr/\bNumber of import parameters is wrong\b/i; ok ! defined eval "use My::Test qw/foo bar quz baz blah/; 1"; like $@, qr/\bNumber of import parameters is wrong\b/i; ok defined eval "use My::Test qw/foo bar quz/; 1"; ok !$@;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11145230]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2022-08-08 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?