Tests and fixes for conditional inclusion
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_utils_home.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use File::Temp qw/ tempdir /;
6 use Catalyst::Utils;
7 use File::Spec;
8 use Path::Class qw/ dir /;
9 use Cwd qw/ cwd /;
10
11 my @dists = Catalyst::Utils::dist_indicator_file_list();
12 is(scalar(@dists), 3, 'Makefile.PL Build.PL dist.ini');
13
14 my $cwd = cwd();
15 foreach my $inc ('', 'lib', 'blib'){
16     my $d = tempdir(CLEANUP => 1);
17     chdir($d);
18     local $INC{'MyApp.pm'} = File::Spec->catdir($d, $inc, 'MyApp.pm');
19     ok !Catalyst::Utils::home('MyApp'), "No files found inc $inc";
20     open(my $fh, '>', "Makefile.PL");
21     close($fh);
22     is Catalyst::Utils::home('MyApp'), dir($d)->absolute->cleanup, "Did find inc '$inc'";
23 }
24
25 {
26     my $d = tempdir(CLEANUP => 1);
27     local $INC{'MyApp.pm'} = File::Spec->catdir($d, 'MyApp.pm');
28     ok !Catalyst::Utils::home('MyApp'), 'No files found';
29     mkdir File::Spec->catdir($d, 'MyApp');
30     is Catalyst::Utils::home('MyApp'), dir($d, 'MyApp')->absolute->cleanup;
31 }
32
33 {
34     my $d = tempdir(CLEANUP => 1);
35     chdir($d);
36     ok !Catalyst::Utils::find_home_unloaded_in_checkout();
37     open(my $fh, '>', "Makefile.PL");
38     close($fh);
39     is Catalyst::Utils::find_home_unloaded_in_checkout(), cwd(), "Did find home_unloaded_in_checkout"
40 }
41
42 chdir($cwd);
43
44 done_testing;
45