Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Testing of exception during import

by haukex (Archbishop)
on Jul 01, 2022 at 18:46 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-25 15:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found