Dirk80 has asked for the wisdom of the Perl Monks concerning the following question:
Let's assume I have a module which needs 3 import parameters.
package My::Test; use strict; use warnings; use Carp; sub import { my $class = shift; croak "Number of import parameters is wrong, stopped " unless @_ = += 3; # ... } 1;
The good case I can check with use_ok. But the bad cases are my problem, e.g. use this class with less than 3 parameters.
use My::Test "Param1", "Param2"; # dies because it are 2 params and no +t 3 as expected
I want to test that this exception was thrown and I also want to check its error message for correctness. Usually I use throws_ok for this. But in this case it doesn't work because the use command is at compile time. I have no idea how to test for this exception.
Thanks for your help!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing of exception during import
by LanX (Saint) on Jul 01, 2022 at 14:53 UTC | |
|
Re: Testing of exception during import
by Anonymous Monk on Jul 01, 2022 at 14:51 UTC | |
|
Re: Testing of exception during import
by haukex (Archbishop) on Jul 01, 2022 at 18:46 UTC | |
|
Re: Testing of exception during import
by kcott (Archbishop) on Jul 02, 2022 at 04:44 UTC | |
by Dirk80 (Pilgrim) on Jul 05, 2022 at 08:59 UTC |