Karen, Thanks for the reply. The Test::Needs module looks like what I want, except it's not installed by default in my distro, which suggests it probably not available in many of the tester's environments either, especially the older version pools. The modules I'm trying to test the presence of are installed by default in my distro, so at least in my case, Test::Needs ironically increases rather than decreases the problem of test failures due to missing dependencies.
I've recoded my module to no longer depend on Rexexp::Common -- that module was causing a lot of dependency trouble. I may put this version out and see what shows up next. Meanwhile, if you could provide a specific example of how to make a test script immune to missing dependencies used by the module under test using BEGIN blocks or other means that are portable among a wide range of perl versions, I'd appreciate it. It's probably obvious already, but just to be clear on the problem I'm trying to solve, it has to handle the following problem: Module being tested (ModuleUnderTest.pm): package ModuleUnderTest; our $VERSION = 'v1.0.0'; use strict; use warnings; use NonExistentModule; 1; Test script (mytest.t): use Test::More; [ test for NonExistentModule and exit cleanly before the use directive below is executed -- I see that a simple unconditional exit 0 at this point runs *after* the use below ] use ModuleUnderTest; # objective is not to blow up here Thanks,Scott From: Karen Etheridge <p...@froods.org> To: Scott Guthridge <pdx_scoo...@yahoo.com> Cc: Slaven Rezic <sla...@rezic.de>; Scott Guthridge via cpan-testers-discuss <cpan-testers-discuss@perl.org> Sent: Thursday, June 22, 2017 11:20 AM Subject: Re: tests failing due to dependency on Regexp::Common A BEGIN block around the checks should work, if it was constructed properly. But you can also use Test::Needs to do this check for you, with much less fuss. use strict; use warnings; use Test::More; use Test::Needs qw(Regexp::Common Image::Info); use Graphics::Fig; ... On Mon, Jun 19, 2017 at 9:40 PM, Scott Guthridge via cpan-testers-discuss <cpan-testers-discuss@perl.org> wrote: Slaven, I tried to do what you suggested, but without success: use strict; use warnings; use Test::More; # # Skip tests if required modules are not available. # if (!eval { require Regexp::Common; 1 }) { plan skip_all => "Regexp::Common moduled required"; } if (!eval { require Image::Info; 1 }) { plan skip_all => "Image::Info moduled required"; } plan tests => 1; # # Load module under test. # use Graphics::Fig; # uses the modules checked above .... When "plan skip_all" is executed, it exits the script without allowing control to continue after the statement. So my expectation was that the "use Graphics::Fig" below would not be executed if one of the tests above failed. But it seems that perl looks ahead and processes all "use" directives before starting execution of the script; therefore, if Graphics::Fig has unsatisfied dependencies, the script blows up before executing the module check code at the top. I tried to force the execution order by putting the module tests inside a BEGIN block. That also didn't work. Scott From: Slaven Rezic <sla...@rezic.de> To: Scott Guthridge via cpan-testers-discuss <cpan-testers-discuss@perl.org >; Scott Guthridge <pdx_scoo...@yahoo.com> Sent: Wednesday, June 14, 2017 10:37 AM Subject: Re: tests failing due to dependency on Regexp::Common Something like this could work: use Test::More; plan skip_all => "Regexp::Common required for test" if !eval { require Regexp::Common; 1 }; plan tests => ...; > Scott Guthridge via cpan-testers-discuss <cpan-testers-discuss@perl.org > hat > am 14. Juni 2017 um 01:16 geschrieben: > > In Graphics::Fig v1.0.1, several runs are failing due to a missing dependency > on the Regexp::Common module: > > # Tried to use 'Graphics::Fig'. > # Error: Can't locate Regexp/Common.pm in @INC (you may need to install > the Regexp::Common module) (@INC contains: /home/cpan/pit/bare/conf/perl- > 5.18.2/.cpanplus/5.18.2/build/ NYePZvq91K/Graphics-Fig-v1.0. 1/blib/lib > /home/cpan/pit/bare/conf/perl- 5.18.2/.cpanplus/5.18.2/build/ > NYePZvq91K/Graphics-Fig-v1.0. 1/blib/arch /home/cpan/pit/bare/conf/perl- > 5.18.2/.cpanplus/5.18.2/build/ NYePZvq91K/Graphics-Fig-v1.0. 1/blib/lib > /home/cpan/pit/bare/conf/perl- 5.18.2/.cpanplus/5.18.2/build/ > NYePZvq91K/Graphics-Fig-v1.0. 1/blib/arch /home/cpan/pit/bare/perl-5.18. > 2/lib/site_perl/5.18.2/x86_64- linux /home/cpan/pit/bare/perl-5.18. > 2/lib/site_perl/5.18.2 /home/cpan/pit/bare/perl-5.18. > 2/lib/5.18.2/x86_64-linux /home/cpan/pit/bare/perl-5.18. 2/lib/5.18.2 .) at > /home/cpan/pit/bare/conf/perl- 5.18.2/.cpanplus/5.18.2/build/ > NYePZvq91K/Graphics-Fig-v1.0. 1/blib/lib/Graphics/Fig/ Parameters.pm line 23. > # BEGIN failed--compilation aborted at /home/cpan/pit/bare/conf/perl- > 5.18.2/.cpanplus/5.18.2/build/ NYePZvq91K/Graphics-Fig-v1.0. > 1/blib/lib/Graphics/Fig/ Parameters.pm line 23. > # Compilation failed in require at /home/cpan/pit/bare/conf/perl- > 5.18.2/.cpanplus/5.18.2/build/ NYePZvq91K/Graphics-Fig-v1.0. > 1/blib/lib/Graphics/Fig.pm line 25. > # BEGIN failed--compilation aborted at /home/cpan/pit/bare/conf/perl- > 5.18.2/.cpanplus/5.18.2/build/ NYePZvq91K/Graphics-Fig-v1.0. > 1/blib/lib/Graphics/Fig.pm line 25. > # Compilation failed in require at t/arc.t line 15 > > Is there a way to list specific module dependencies in the test > configuration? Or should I recode my module to not depend on that module? > > Thanks, > Scott