[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] BEGIN block for Test::More



Stumbled into this one today...

I had to add BEGIN {} around my if test to catch clients that aren't configured correctly to run tests like the one below.

Without BEGIN, they'd get down to use OTA2::Skeletons, which would blow up (not skip) because that package wasn't in their PERL5LIB path...

Ahh, the magic of BEGIN...

j



$ cat j2.t
use Test::More;
BEGIN {
  if( -d "$ENV{OTA2_PATH}/skeletons" ) {
     plan tests => 4;
  } else {
     plan skip_all => 'Looks like your $ENV{OTA2_PATH} is not set';
  }
}

use strict;
use OTA2::Skeleton;
# ...

$ perl j2.t
1..0 # Skip Looks like your $ENV{OTA2_PATH} is not set