hesco has asked for the wisdom of the Perl Monks concerning the following question:

I've encountered an interesting conundrum.

About a week ago, I finally published my work for the first time to the CPAN repository. As a result of that, my throw away little project is suddenly the subject of smoketests, from which I am learning quite a bit about the build process and a little about the challenges of writing portable code. (For instance, I had never used perl Build.PL to install a module. Being a creature of habit, I used make; make test; sudo make install; had it work and never moved past that. Apparently others do it differently.)

At any rate, to my conundrum.

Without use Test::More qw(no_plan);, trying to install my new module on a test box with a base Debian install throws an error reading: Undefined subroutine &skip called at t/perlcritic.t line __. If I use the module but fail to define a plan I get: You tried to run tests without a plan!  Gotta have a plan.. And if I provide a plan, I get, as hoped for:

ok 1 # skip because Test::Perl::Critic required for these tests.

However when I run this test on my development machine, I get:

You tried to plan twice at t/perlcritic.t line 9. # Looks like your test died before it could output anything.

unless I comment out the line required on my test box, in which case the tests run and I get:

1..1 ok 1 - Test::Perl::Critic for "blib/lib/GD/Graph/Thermometer.pm"
So my questions this evening are these:

And the problematic test script, reads:

#!/usr/bin/perl -w use Test::More qw(no_plan); SKIP: { eval 'use Test::Perl::Critic'; skip('because Test::Perl::Critic required for these tests.',1) if $@ +; Test::Perl::Critic::all_critic_ok(); }
Any insight would be appreciated. Thanks,

-- Hugh

UPDATE:

Thanks to jasonk and perrin for what turned out to be the portable working answer. My T::P::C enabled machine, running this test code, returns:

1..1 ok 1 - Test::Perl::Critic for "blib/lib/GD/Graph/Thermometer.pm"
And my base install machine without this dependency, returns:

1..0 # Skip because Test::Perl::Critic required for these tests
That having been resolved, I'll send version 0.05 up to the repository and see what the smoketesters have to say about it next. Thanks everyone for their input and feedback.

if( $lal && $lol ) { $life++; }

Replies are listed 'Best First'.
Re: Seeking advice for portable test suite
by jasonk (Parson) on Jan 13, 2007 at 14:07 UTC

    all_critic_ok provides it's own plan, so by providing a plan before calling it, you plan twice in the situation where it works. Instead you should do something like this:

    use Test::More; eval "use Test::Perl::Critic"; if ( $@ ) { plan skip_all => "because Test::Perl::Critic required for these te +sts"; } else { all_critic_ok(); }

    Even if you get your code working, the skip isn't going to work correctly because you are only skipping 1 test, and all_critic_ok() is going to run 1 test for each file returned by all_perl_files().


    We're not surrounded, we're in a target-rich environment!
      This is exactly how it should be done. I think people get confused by the magical "import is your plan" approach that Test::More provides and don't realize they can just call it separately from loading the module.
Re: Seeking advice for portable test suite
by gaal (Parson) on Jan 13, 2007 at 09:17 UTC
    What happens when you give an explicit plan? tests => 1 that is?

    The standard installations of Perl modules doesn't provide a good way for latter uninstall. But in your case you could put a fake Test::Perl::Critic in your PERL5LIB that intentionally fails to load.

      You could perhpas bundle the Test:: modules with your code as you roll it out too...

      Although I'll be told instantly why this is a bad idea... (i'm thinking size, risk of freezing the module at a fixed version, extra administration etc)

      @_=qw; ask f00li5h to appear and remain for a moment of pretend better than a lifetime;;s;;@_[map hex,split'',B204316D8C2A4516DE];;y/05/os/&print;
      Thanks, that sounds like a great idea, to load a broken T::P::C in my test environment, that is. I'll have to try that.

      Result on Test::Perl::Critic enabled machine, with "tests => 1".

      1..1 You tried to plan twice at t/perlcritic.t line 9. # Looks like your test died before it could output anything.
      if( $lal && $lol ) { $life++; }