fixed bug: [rt.cpan.org #25143] make tests fails
[p5sagit/Config-Any.git] / t / 20-parse.t
index db7ccde..420b581 100644 (file)
@@ -1,5 +1,8 @@
 package MockApp;\r
+use strict;\r
+use warnings;\r
 \r
+$|++;\r
 use Test::More tests => 54;\r
 use Scalar::Util qw(blessed reftype);\r
 use Config::Any;\r
@@ -11,7 +14,7 @@ use Config::Any::XML;
 use Config::Any::YAML;\r
 \r
 \r
-my %ext_map = (\r
+our %ext_map = (\r
        conf => 'Config::Any::General',\r
        ini  => 'Config::Any::INI',\r
        json => 'Config::Any::JSON',\r
@@ -20,20 +23,24 @@ my %ext_map = (
        yml  => 'Config::Any::YAML'\r
 );\r
 \r
-my @files = map { "t/conf/$_" } \r
-       qw(conf.conf conf.ini conf.json conf.pl conf.xml conf.yml);\r
+sub load_parser_for {\r
+    my $f = shift;\r
+    return unless $f;\r
 \r
-for my $f (@files) {\r
        my ($ext) = $f =~ m{ \. ( [^\.]+ ) \z }xms;\r
        my $mod = $ext_map{$ext};\r
        my $mod_load_result;\r
        eval { $mod_load_result = $mod->load( $f ); delete $INC{$f} if $ext eq 'pl' };\r
+    return $@ ? (1,$mod) : (0,$mod);\r
+}\r
+\r
+for my $f (map { "t/conf/conf.$_" } keys %ext_map) {\r
+    my ($skip,$mod) = load_parser_for($f);\r
        SKIP: {\r
-               my $skip = !!$@;\r
                skip "File loading backend for $mod not found", 9 if $skip;\r
        \r
                ok(my $c_arr = Config::Any->load_files({files=>[$f], use_ext=>1}), \r
-                       "load_files with use_ext works");\r
+                       "load_files with use_ext works [$f]");\r
                ok(my $c = $c_arr->[0], "load_files returns an arrayref");\r
                \r
                ok(ref $c, "load_files arrayref contains a ref");\r