Re: Local library for module test script
by syphilis (Archbishop) on Dec 03, 2014 at 03:31 UTC
|
During 'make test' the current working directory is the top-level folder ... so I'm thinking you want require './t/lib.pm';.
Best to check that on your own machine before uploading to CPAN.
Cheers, Rob | [reply] [d/l] |
|
cwd can change, best not to rely on it at all ... I'm frequently inside cwd() of "t" when trying to fix/debug some module, so relying on require "./t/..." would fail
I also often do perl dist-name-version/t/foo.t :) relying on cwd is weak sauce, it can work very often, but its weak practice
| [reply] |
|
cwd can change
Sure, and I have no objection to the approach you suggested.
However, I write my test suites under the assumption that they're going to be run from "one directory up". If someone complained that they couldn't be run from the 't' directory then I'd likely suggest "stop doing that".
Cheers, Rob
| [reply] |
|
|
|
|
Re: Local library for module test script (updated FindBin)
by LanX (Saint) on Dec 03, 2014 at 03:55 UTC
|
use lib ".";
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
update
see FindBin, it's core.
use FindBin qw($Bin);
use lib "$Bin";
or
use FindBin qw($Bin);
require $Bin.'/lib.pm';
| [reply] [d/l] [select] |
|
LanX :) a relative path is relative, with cwd() usually being dist-name-version, and the "module.pm" living in dist-name-version/t/ adding "." wouldn't change anything , require lib.pm would still fail
| [reply] |
|
Anonymous Monk, I tested use lib '.'!
(at least I thought :)
I supposed that lib takes the file's path as base.
The perldoc wasn't clear¹, so I tested by changing the working directory with chdir before use and it seemed to work fine.
But now I am realizing that I should have put the chdir into a BEGIN block, otherwise it happens too late.
So your point is valid!!!
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
¹) but led me now to FindBin
| [reply] [d/l] |
Re: Local library for module test script ( @INC cwd pwd chdir )
by Anonymous Monk on Dec 03, 2014 at 03:27 UTC
|
relative paths are relative, and unless you use chdir, they're often wrong
Also, @INC is @INC
Also, lib is a core module
So don't rely on cwd() being "t" or "..\t" because thats weak sauce, one way
BEGIN {
use File::Spec;
use File::Basename();
our $thisf = File::Spec->rel2abs( $0 );
our $thisd = File::Basename::dirname($thisf);
}
then you can require "$thisd/lib.pm" or chdir $thisd; ... | [reply] [d/l] [select] |
|
That worked very nicely. Thanks!
| [reply] |
Re: Local library for module test script
by Khen1950fx (Canon) on Dec 04, 2014 at 04:36 UTC
|
The require is the least of your problems. More importantly, the
slurp() keeps popping up as undefined.
Update: Solved. My bad, it was my system. I used require "t/test-lib.pm".
Passed all tests.
| [reply] [d/l] |