Simulating module load failure
I did a bit of hacking on JSON::Any today and added a new program to the test suite in the process. Since I have all the backend JSON handlers installed on my development machine (JSON, JSON::XS, JSON::DWIW, and the deprecated JSON::Syck), I needed a way to ensure some tests are skipped when one or more of those backends aren’t available.
A surprisingly simple solution came to mind:
That created an empty file in the project which of course doesn’t return the
requisite true value when
require-ed. So, it simulated the need quite
The only thing simpler was the fix required to make sure tests are skipped when a backend can’t be loaded:
- diag "$backend: $@" and skip("backend failed to load", 8) if $@; + diag("$backend: $@"), skip("backend failed to load", 8) if $@;
diag doesn’t return true. (Should it?)
diag through its call chain, we find our way to
Test::Builder::_print_comment, which explicitly calls
return 0. I wonder
This site is the personal weblog of Marc Mims. You can contact Marc
by sending e-mail to:
Marc writes here about cycling, programming, Linux, and other items of personal interest.
This site is syndicated with RSS.
CSS stolen from Tom Coates who didn't even complain.