Fri, 03 Jul 2009

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:

touch lib/JSON/DWIW.pm

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 nicely.

The sheer joy this simple hack gave me probably marks me a geek more surely the mouseless Debian Linux, Xmonad-tiled-window-manager system I typed it on.

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 $@;

Apparently, diag doesn’t return true. (Should it?)

Hmmm…following diag through its call chain, we find our way to Test::Builder::_print_comment, which explicitly calls return 0. I wonder why?

[/perl] [link]

About this weblog

This site is the personal weblog of Marc Mims. You can contact Marc by sending e-mail to:
[email protected].

Marc writes here about cycling, programming, Linux, and other items of personal interest.

This site is syndicated with RSS.

Archives

Credits

CSS stolen from Tom Coates who didn't even complain.