Fix Catalyst::Utils::home() when application .pm is in the current dir (RT #34437)
[catagits/Catalyst-Runtime.git] / t / unit_utils_subdir.t
1 use Test::More tests => 8;
2
3 use strict;
4 use warnings;
5
6 # simulates an entire testapp rooted at t/something
7 # except without bothering creating it since its
8 # only the -e check on the Makefile.PL that matters
9
10 BEGIN { use_ok 'Catalyst::Utils' }
11 use FindBin;
12
13 {
14     $INC{'TestApp.pm'} = "$FindBin::Bin/something/script/foo/../../lib/TestApp.pm";
15     my $home = Catalyst::Utils::home('TestApp');
16     like($home, qr{t[\/\\]something}, "has path TestApp/t/something"); 
17     unlike($home, qr{[\/\\]script[\/\\]foo}, "doesn't have path /script/foo");
18 }
19
20 {
21     $INC{'TestApp.pm'} = "$FindBin::Bin/something/script/foo/bar/../../../lib/TestApp.pm";
22     my $home = Catalyst::Utils::home('TestApp');
23     like($home, qr{t[\/\\]something}, "has path TestApp/t/something"); 
24     unlike($home, qr{[\/\\]script[\/\\]foo[\/\\]bar}, "doesn't have path /script/foo/bar");
25 }
26
27 {
28     $INC{'TestApp.pm'} = "$FindBin::Bin/something/script/../lib/TestApp.pm";
29     my $home = Catalyst::Utils::home('TestApp');
30     like($home, qr{t[\/\\]something}, "has path TestApp/t/something"); 
31     unlike($home, qr{[\/\\]script[\/\\]foo}, "doesn't have path /script/foo");
32 }
33
34 {
35     $INC{'TestApp.pm'} = "TestApp.pm";
36     my $dir = "$FindBin::Bin/something";
37     chdir( $dir );
38   
39     my $home = Catalyst::Utils::home('TestApp');
40
41     is( $home, $dir, 'same dir loading' );
42 }