Config::Any->load_files(
{ files => \@files,
use_ext => 1,
- filter => sub { die }
+ filter => sub { die "reject" }
}
);
};
-ok( $@, "filter breaks" );
+like $@, qr/reject/, "filter breaks";
my @stems = qw(t/supported/conf);
ok( Config::Any->load_stems( { stems => \@stems, use_ext => 1 } ),
use warnings;
no warnings 'once';
-$|++;
-use Test::More tests => 54;
+use Test::More tests => 6*9;
use Scalar::Util qw(blessed reftype);
use Config::Any;
use Config::Any::General;
for my $f ( map { "t/conf/conf.$_" } keys %ext_map ) {
my ( $skip, $mod ) = load_parser_for( $f );
-SKIP: {
+ SKIP: {
skip "File loading backend for $mod not found", 9 if $skip;
ok( my $c_arr
my $file = 't/invalid/conf.conf';
my $config = eval { Config::Any::General->load( $file ) };
- ok( !$config, 'config load failed' );
- ok( $@, "error thrown ($@)" );
+ is $config, undef, 'config load failed';
+ isnt $@, '', 'error thrown';
}
# parse error generated on invalid config
my $file = 't/invalid/conf.conf';
my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) };
- ok( !$config, 'config load failed' );
- ok( $@, "error thrown ($@)" );
+ is $config, undef, 'config load failed';
+ isnt $@, '', 'error thrown';
}
my $file = 't/invalid/conf.ini';
my $config = eval { Config::Any::INI->load( $file ) };
- ok( !$config, 'config load failed' );
- ok( $@, "error thrown ($@)" );
+ is $config, undef, 'config load failed';
+ isnt $@, '', 'error thrown';
}
# parse error generated on invalid config
my $file = 't/invalid/conf.ini';
my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) };
- ok( !$config, 'config load failed' );
- ok( $@, "error thrown ($@)" );
+ is $config, undef, 'config load failed';
+ isnt $@, '', 'error thrown';
}
my $file = 't/invalid/conf.json';
my $config = eval { Config::Any::JSON->load( $file ) };
- ok( !$config, 'config load failed' );
- ok( $@, "error thrown ($@)" );
+ is $config, undef, 'config load failed';
+ isnt $@, '', 'error thrown';
}
# parse error generated on invalid config
my $file = 't/invalid/conf.json';
my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) };
- ok( !$config, 'config load failed' );
- ok( $@, "error thrown ($@)" );
+ is $config, undef, 'config load failed';
+ isnt $@, '', 'error thrown';
}
1;
};
- ok( !$loaded, 'config load failed' );
- ok( !$config, 'config load failed' );
- ok( $@, "error thrown ($@)" );
+ ok !$loaded, 'config load failed';
+ is $config, undef, 'config load failed';
+ like $@, qr/syntax error/, 'error thrown';
}
# parse error generated on invalid config
1;
};
- ok( !$loaded, 'config load failed' );
- ok( !$config, 'config load failed' );
- ok( $@, "error thrown ($@)" );
+ ok !$loaded, 'config load failed';
+ is $config, undef, 'config load failed';
+ like $@, qr/syntax error/, 'error thrown';
}
# test missing config
1;
};
- ok( !$loaded, 'config load failed' );
- ok( !$config, 'config load failed' );
- ok( $@, "error thrown ($@)" );
+ ok !$loaded, 'config load failed';
+ is $config, undef, 'config load failed';
+ like $@, qr/No such file or directory/, 'error thrown';
}
plan skip_all => 'XML format not supported';
}
else {
- plan tests => 8;
+ plan tests => 7;
}
{
my $config = Config::Any::XML->load( 't/conf/conf.xml' );
- ok( $config );
- is( $config->{ name }, 'TestApp' );
+ is_deeply $config, {
+ 'Component' => {
+ 'Controller::Foo' => {
+ 'foo' => 'bar'
+ },
+ },
+ 'name' => 'TestApp',
+ 'Model' => {
+ 'Model::Baz' => {
+ 'qux' => 'xyzzy',
+ },
+ },
+ }, 'config loaded';
}
# test invalid config
my $file = 't/invalid/conf.xml';
my $config = eval { Config::Any::XML->load( $file ) };
- ok( !$config, 'config load failed' );
- ok( $@, "error thrown ($@)" );
+ is $config, undef, 'config load failed';
+ isnt $@, '', 'error thrown';
}
# test conf file with array ref
my $file = 't/conf/conf_arrayref.xml';
my $config = eval { Config::Any::XML->load( $file ) };
- ok( $config, 'config loaded' );
- ok( !$@, 'no error thrown' );
+ is_deeply $config, {
+ 'indicator' => 'submit',
+ 'elements' => [
+ {
+ 'label' => 'Label1',
+ 'type' => 'Text',
+ },
+ {
+ 'label' => 'Label2',
+ 'type' => 'Text',
+ },
+ ],
+ }, 'config loaded';
+ is $@, '', 'no error thrown';
}
# parse error generated on invalid config
my $file = 't/invalid/conf.xml';
my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) };
- ok( !$config, 'config load failed' );
- ok( $@, "error thrown ($@)" );
+ is $config, undef, 'config load failed';
+ isnt $@, '', 'error thrown';
}
my $file = 't/invalid/conf.yml';
my $config = eval { Config::Any::YAML->load( $file ) };
- ok( !$config, 'config load failed' );
- ok( $@, "error thrown ($@)" );
+ is $config, undef, 'config load failed';
+ isnt $@, '', 'error thrown';
}
# parse error generated on invalid config
my $file = 't/invalid/conf.yml';
my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) };
- ok( !$config, 'config load failed' );
- ok( $@, "error thrown ($@)" );
+ is $config, undef, 'config load failed';
+ isnt $@, '', 'error thrown';
}