fixed parser test to skip tests when dependent modules are not installed
[p5sagit/Config-Any.git] / t / 20-parse.t
CommitLineData
e967a60f 1package MockApp;\r
2\r
3use Test::More tests => 54;\r
4use Scalar::Util qw(blessed reftype);\r
5use Config::Any;\r
61994c33 6use Config::Any::General;\r
7use Config::Any::INI;\r
8use Config::Any::JSON;\r
9use Config::Any::Perl;\r
10use Config::Any::XML;\r
11use Config::Any::YAML;\r
12\r
13\r
14my %ext_map = (\r
15 conf => 'Config::Any::General',\r
16 ini => 'Config::Any::INI',\r
17 json => 'Config::Any::JSON',\r
18 pl => 'Config::Any::Perl',\r
19 xml => 'Config::Any::XML',\r
20 yml => 'Config::Any::YAML'\r
21);\r
e967a60f 22\r
23my @files = map { "t/conf/$_" } \r
24 qw(conf.conf conf.ini conf.json conf.pl conf.xml conf.yml);\r
25\r
26for my $f (@files) {\r
61994c33 27 my ($ext) = $f =~ m{ \. ( [^\.]+ ) \z }xms;\r
28 my $mod = $ext_map{$ext};\r
29 my $mod_load_result;\r
30 eval { $mod_load_result = $mod->load( $f ); delete $INC{$f} if $ext eq 'pl' };\r
31 SKIP: {\r
32 my $skip = !!$@;\r
33 skip "File loading backend for $mod not found", 9 if $skip;\r
34 \r
35 ok(my $c_arr = Config::Any->load_files({files=>[$f], use_ext=>1}), \r
36 "load_files with use_ext works");\r
37 ok(my $c = $c_arr->[0], "load_files returns an arrayref");\r
38 \r
39 ok(ref $c, "load_files arrayref contains a ref");\r
40 my $ref = blessed $c ? reftype $c : ref $c;\r
41 is(substr($ref,0,4), "HASH", "hashref");\r
42\r
43 my ($name, $cfg) = each %$c;\r
44 is($name, $f, "filename matches");\r
45 \r
46 my $cfgref = blessed $cfg ? reftype $cfg : ref $cfg;\r
47 is(substr($cfgref,0,4), "HASH", "hashref cfg");\r
48\r
49 is( $cfg->{name}, 'TestApp', "appname parses" );\r
50 is( $cfg->{Component}{ "Controller::Foo" }->{ foo }, 'bar', \r
51 "component->cntrlr->foo = bar" );\r
52 is( $cfg->{Model}{ "Model::Baz" }->{ qux }, 'xyzzy', \r
53 "model->model::baz->qux = xyzzy" );\r
54 }\r
e967a60f 55}\r
56\r