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

Check existence of cpanfile, Makefile.PL, Build.PL to detect root directory #44

Merged
merged 2 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/App/PRT/Collector/AllFiles.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ sub find_project_root_directory {

my $current = dir($directory);
while (1) {
if (-e $current->file('cpanfile')) {
return $current->stringify;
for my $file (qw(cpanfile Makefile.PL Build.PL)) {
if (-e $current->file($file)) {
return $current->stringify;
}
}

if ($current eq $current->parent) {
Expand Down
14 changes: 10 additions & 4 deletions t/App-PRT-Collector-AllFiles.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ sub find_project_root_directory: Tests {
};

subtest 'directory with cpanfile' => sub {
my $directory = t::test::prepare_test_code('contain_ignores');

is App::PRT::Collector::AllFiles->find_project_root_directory($directory), $directory, 'found from root directory';
is App::PRT::Collector::AllFiles->find_project_root_directory("$directory/lib"), $directory, 'found from sub directory';
for my $name (qw(with_cpanfile with_build_pl with_makefile_pl contain_ignores)) {
subtest $name => sub {
my $directory = t::test::prepare_test_code($name);

is App::PRT::Collector::AllFiles->find_project_root_directory($directory), $directory, 'found from root directory';
if (-e "$directory/lib") {
is App::PRT::Collector::AllFiles->find_project_root_directory("$directory/lib"), $directory, 'found from sub directory';
}
};
};
};

subtest 'not existing directory' => sub {
Expand Down
1 change: 1 addition & 0 deletions t/data/with_build_pl/Build.PL
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print "Hello, World!\n";
1 change: 1 addition & 0 deletions t/data/with_cpanfile/cpanfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requires 'perl', '5.010001';
1 change: 1 addition & 0 deletions t/data/with_makefile_pl/Makefile.PL
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print "Hello, World!\n";