Test::Class and FindBin

I'm on a new team at the BBC and I was rather curious to note that I couldn't run the Test::Class tests by simply doing a prove -lv t/lib/Path/To/Test.pm. A bit of research reveals the culprit is FindBin, a module I've never been terribly happy with. Seems we have configuration information located relative to the $FindBin variable that module sets.

package Dynamite::Test::FindBin;

  # point it at the test directory if we're not there
  if ( $0 !~ m{^t/[^./]+\.t$} ) {

    # FindBin requires a real filename
    $0 = (glob('t/[^/]+.t'))[0];

  # In case something does a "use FindBin" before we get here
  FindBin->again if exists $INC{'FindBin.pm'};
use FindBin;


Seems FindBin uses $0 (not surprising) to do its magic. Regrettably, that assumption makes it hard to run a test class directly. This also explained why the test classes required driver *.t files, something which drives me up a wall. Now they're not longer needed, but I confess I feel like I need to take a shower and scrub myself really, really clean.

Leave a comment

About Ovid

user-pic Have Perl; Will Travel. Freelance Perl/Testing/Agile consultant. Photo by http://www.circle23.com/. Warning: that site is not safe for work. The photographer is a good friend of mine, though, and it's appropriate to credit his work.