You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Testing within a directory other than the root of the code produces test failures because the schema.pl file cannot be found. Rather than assuming that the executing directory (AKA, CWD) is the root of the code, the correct directory should be searched relative to the .t file, or relative to the directories in @INC.
When perl -I lib t/MyDBModule.t is run from the MyDBModule directory, everything works as expected. When it's run from t/ as perl -I ../lib MyDBModule.t, it fails because it cannot find and load the schema.pl file.
The text was updated successfully, but these errors were encountered:
As mentioned in the original issue, In order to find the proper schema.pl file, one would need to search relative to the paths in either $FindBin::Bin or @INC.
my $tdir = undef;
OUTER:
for my $dir ( $FindBin::Bin, @INC ) {
my $fulldir = Path::Tiny::path($dir)->realpath;
while ( !$fulldir->is_rootdir ) {
my $file = Path::Tiny::path( $fulldir, $reldir );
if ( $file->exists ) {
$tdir = $file->dirname;
last OUTER;
}
}
}
Include some error checking and other details, and you now know where to look for the schema.pl file.
Testing within a directory other than the root of the code produces test failures because the schema.pl file cannot be found. Rather than assuming that the executing directory (AKA, CWD) is the root of the code, the correct directory should be searched relative to the
.t
file, or relative to the directories in@INC
.As an example, in a normal code layout
When
perl -I lib t/MyDBModule.t
is run from theMyDBModule
directory, everything works as expected. When it's run fromt/
asperl -I ../lib MyDBModule.t
, it fails because it cannot find and load theschema.pl
file.The text was updated successfully, but these errors were encountered: