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