updated the test
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_setup_home.t
1 #!/usr/bin/env perl
2 use warnings;
3 use strict;
4 use Test::More;
5 use Catalyst::IOC::Container;
6 use FindBin '$Bin';
7 use lib "$Bin/../lib";
8 use TestAppSetupHome;
9 use vars '%ENV';
10
11 my $lib = "$Bin/../lib";
12 my @homes_and_roots = (
13     [
14         "$lib/TestAppSetupHome",
15         "$lib/TestAppSetupHome/root",
16     ],
17     [
18         "$lib/TestAppSetupHomeENV",
19         "$lib/TestAppSetupHomeENV/root",
20     ],
21     [
22         "$lib/TestAppSetupHomeFLAG",
23         "$lib/TestAppSetupHomeFLAG/root",
24     ],
25 );
26
27 for my $home_and_root (@homes_and_roots) {
28     for (@$home_and_root) {
29         mkdir $_;
30     }
31 }
32
33 test_it(0, 0, 0);
34 test_it(0, 1, 1);
35 test_it(1, 0, 2);
36 test_it(1, 1, 1);
37
38
39 sub test_it {
40     my ($set_flag, $set_env, $expected_result) = @_;
41
42     my @home_flag;
43     delete $ENV{CATALYST_HOME} if exists $ENV{CATALYST_HOME};
44
45     if ($set_flag) {
46         @home_flag = ("-Home=$homes_and_roots[2][0]");
47     }
48     if ($set_env) {
49         $ENV{CATALYST_HOME} = $homes_and_roots[1][0];
50     }
51
52     my $c = Catalyst::IOC::Container->new(name => 'TestAppSetupHome', flags => \@home_flag);
53     ok(my $home = $c->resolve(service => 'home'), 'home service returns ok');
54     is($home, $homes_and_roots[$expected_result][0], 'home value is expected');
55     ok(my $root = $c->resolve(service => 'root_dir'), 'root_dir service returns ok');
56     is($root, $homes_and_roots[$expected_result][1], 'root value is expected');
57 }
58
59 for my $home_and_root (@homes_and_roots) {
60     for (@$home_and_root) {
61         rmdir $_;
62     }
63 }
64
65 done_testing;