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

My tests in my_module/t/001_load.t says
use Test::More tests => 5; use lib "../lib"; BEGIN { use_ok( 'Pod::Simple::Select' ); } my $p = Pod::Simple::Select->new (); isa_ok ($p, 'Pod::Simple::Select'); $p->select(["head1", ["NAME", "VERSION"]]); $p->output_hash(); my %h = $p->parse_file("../lib/Pod/Simple/Select.pm");
And this fails on Linux/Unix with file not found. On my windows box rundisttest path without problems. Pod::Simple::Select is a child class of Pod::Simple and parse_file begins with
sub parse_file { my ( $self, $file ) = @_; tie my @array, 'Tie::File', $file, mode => O_RDONLY; ... $token = $self->{doc}->next; $self->SUPER::parse_file($file); ...
Any clue ? Thanks frazap

Replies are listed 'Best First'.
Re: Test::More file not found on unix (updated)
by haukex (Archbishop) on Jun 02, 2017 at 14:31 UTC

    Another way to do it is with FindBin, i.e.

    use FindBin (); use File::Spec::Functions qw/catfile/; ... $p->parse_file(catfile($FindBin::Bin,qw/ .. lib Pod Simple Select.pm / +));

    I do this in the tests for several of my modules (example) and it's worked great so far across all of CPAN Testers*.

    The same thing goes for lib, e.g. use lib $FindBin::Bin;.

    * Update: Sorry, I should not have made that specific claim that that code works across all of CPAN Testers, I forgot that those are author tests that don't get run there. However, I do have a few very similar lines of code where I can make that claim instead (from here):

    use FindBin (); use lib $FindBin::Bin; ... my $script = catfile($FindBin::Bin, 'test_opts_usage.pl');
Re: Test::More file not found on unix
by stevieb (Canon) on Jun 02, 2017 at 11:26 UTC

    When running tests, the base location for relative paths is the directory the tests are run out of. If your directory structure follows the traditional distribution layout:

    dist_root_dir | |-lib/ |-t/ |-etc/

    ...and you run your tests while in the root directory of the dist, then remove the use lib '../lib', and change the path to: lib/Pod/Simple/Select.pm. As is, (again if you're running tests from the root dir), your path is going one level *above* your distribution's root directory, and looking for a lib/ dir, which almost certainly doesn't exist.

Re: Test::More file not found on unix
by Anonymous Monk on Jun 02, 2017 at 07:23 UTC

    What file is not found, Select.pm?

    Absolute paths are better than relative paths, get rid of use lib '../lib'; as use_ok will be able to find Pod::Simple::Select without it

    Then simply use $INC{'Pod/Simple/Select.pm'} for the absolute path to that file