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 !$@;
In reply to Re: Testing of exception during import
by haukex
in thread Testing of exception during import
by Dirk80
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |