How to check "use" * crash *?

Test :: More provides a commonly used test use_okto verify module loading. But how can I verify that the module is not loading? Test :: Exception also offers dies_okcousins ​​for similar crashes, but not during use.

This is useful when a module requires certain parameters or a specific environment to load correctly, and I want to check these conditions. As an example, perhaps my “Foo” module requires a configuration parameter, and otherwise it should not load:

use Foo 'eat my hat';  # This should work
use Foo; # This should die

I can easily check the first case with Test :: More:

BEGIN { use_ok('Foo','eat my hat') }

But how can I check something else?

BEGIN { use_not_ok('Foo') }  # use_not_ok doesn't exist
+4
1
use Foo;

BEGIN { require Foo; import Foo; }

BEGIN { ok(!eval { require Foo; import Foo; 1 }); }

BEGIN { ok(!eval('use Foo; 1')); }
+5

All Articles