updated the test
[catagits/Catalyst-Runtime.git] / t / aggregate / unit_core_setup_home.t
CommitLineData
f84ac410 1#!/usr/bin/env perl
2use warnings;
3use strict;
4use Test::More;
5use Catalyst::IOC::Container;
6use FindBin '$Bin';
7use lib "$Bin/../lib";
8use TestAppSetupHome;
9use vars '%ENV';
10
11my $lib = "$Bin/../lib";
12my @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
27for my $home_and_root (@homes_and_roots) {
28 for (@$home_and_root) {
29 mkdir $_;
30 }
31}
32
b98f6eaf 33test_it(0, 0, 0);
34test_it(0, 1, 1);
35test_it(1, 0, 2);
36test_it(1, 1, 1);
f84ac410 37
f84ac410 38
b98f6eaf 39sub test_it {
40 my ($set_flag, $set_env, $expected_result) = @_;
f84ac410 41
b98f6eaf 42 my @home_flag;
f84ac410 43 delete $ENV{CATALYST_HOME} if exists $ENV{CATALYST_HOME};
44
b98f6eaf 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 }
f84ac410 51
b98f6eaf 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');
f84ac410 57}
58
59for my $home_and_root (@homes_and_roots) {
60 for (@$home_and_root) {
61 rmdir $_;
62 }
63}
64
65done_testing;