Skip Menu |

This queue is for tickets about the Test-Portability-Files CPAN distribution.

Report information
The Basics
Id: 43948
Status: resolved
Priority: 0/
Queue: Test-Portability-Files

People
Owner: abraxxa [...] cpan.org
Requestors:
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.05
Fixed in: 0.06



Subject: Error when used in conjunction with skip_all.
Hello and thanks for Test::Portability::Files, Often when running a test such as this I'd like it to be developer-only, or requested by setting an environment variable. For example: use Test::More; eval "use Test::Portability::Files"; plan skip_all => "Test::Portability::Files required for testing filenames portability" if $@; plan skip_all => 'Set TEST_PORTABILITY_FILES env var to enable test' unless $ENV{'TEST_PORTABILITY_FILES'}; options(all_tests => 1); # to be hyper-strict run_tests(); However, if the perl instance has Test::Portability::Files then Test::Portability::Files::import is run and this calls plan() setting tests to 1. This results in: 1..1 You tried to plan twice at test.t line X. # Looks like your test died before it could output anything. I'm not familiar with Test::Builder but I was wondering if the call to plan() could be delayed by moving it inside run_tests() ? (The skip_all usage as seen in the synopsis avoids this problem because skip_all is only called if Test::Portability::Files is not available) Cheers, Peter (Stig) Edwards
On Sun Mar 08 18:07:36 2009, cpan@pjedwards.co.uk wrote: Show quoted text
> Hello and thanks for Test::Portability::Files, > > Often when running a test such as this I'd like it to be > developer-only, or requested by setting an environment variable. > For example: > > use Test::More; > eval "use Test::Portability::Files"; > plan skip_all => "Test::Portability::Files required for testing > filenames portability" if $@; > plan skip_all => 'Set TEST_PORTABILITY_FILES env var to enable test' > unless $ENV{'TEST_PORTABILITY_FILES'}; > options(all_tests => 1); # to be hyper-strict > run_tests(); > > However, if the perl instance has Test::Portability::Files then > Test::Portability::Files::import is run and this calls plan() setting > tests to 1. This results in: > > 1..1 > You tried to plan twice at test.t line X. > # Looks like your test died before it could output anything. > > I'm not familiar with Test::Builder but I was wondering if the > call to plan() could be delayed by moving it inside run_tests() ? > > (The skip_all usage as seen in the synopsis avoids this problem > because skip_all is only called if Test::Portability::Files is > not available) > > Cheers, > Peter (Stig) Edwards
A workaround is to use "require" and not "use" in the eval, and then call import after planning, thanks to Tim Bunce. use Test::More; eval "require Test::Portability::Files"; plan skip_all => "Test::Portability::Files required for testing filenames portability" if $@; plan skip_all => 'Set TEST_PORTABILITY_FILES env var to enable test' unless $ENV{'TEST_PORTABILITY_FILES'}; Test::Portability::Files->import(); # calls plan(); options(all_tests => 1); # to be hyper-strict run_tests();
Subject: Re: [rt.cpan.org #43948] Error when used in conjunction with skip_all.
Date: Tue, 10 Mar 2009 02:06:22 +0100
To: bug-Test-Portability-Files [...] rt.cpan.org
From: Sébastien Aperghis-Tramoni <saper [...] cpan.org>
Peter John Edwards wrote via RT: Show quoted text
> A workaround is to use "require" and not "use" in the eval, and then > call import after planning, thanks to Tim Bunce.
Why not simply use the more modern way to load-or-skip, and reverse the calls to plan()? use Test::More; plan skip_all => "Only for the module maintainer" unless $ENV {AUTHOR_TESTS}; plan skip_all => "Test::Portability::Files required for testing filenames portability" unless eval "use Test::Portability::Files; 1"; # run the selected tests run_tests(); This way, you also avoid loading the module at all if the test is to be skipped. I'll update the documentation to reflect this use case. -- Sébastien Aperghis-Tramoni Close the world, txEn eht nepO.
fixed in 0.06