Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The assumed directory of t/etc/schema.pl is incorrect #48

Open
rkleemann opened this issue Dec 21, 2018 · 1 comment
Open

The assumed directory of t/etc/schema.pl is incorrect #48

rkleemann opened this issue Dec 21, 2018 · 1 comment

Comments

@rkleemann
Copy link

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

MyDBModule/
    lib/MyDBModule.pm
    t/MyDBModule.t
    t/etc/schema.pl

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.

@rkleemann
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant