Skip to content

Commit

Permalink
better diagnostics on test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Apr 9, 2017
1 parent cb49d8a commit e018669
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 39 deletions.
4 changes: 2 additions & 2 deletions t/10-branches.t
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ eval {
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 } ),
Expand Down
5 changes: 2 additions & 3 deletions t/20-parse.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use strict;
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;
Expand Down Expand Up @@ -34,7 +33,7 @@ sub load_parser_for {

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
Expand Down
8 changes: 4 additions & 4 deletions t/50-general.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ else {
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';
}
8 changes: 4 additions & 4 deletions t/51-ini.t
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ else {
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';
}
8 changes: 4 additions & 4 deletions t/52-json.t
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ else {
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';
}
18 changes: 9 additions & 9 deletions t/53-perl.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ use Config::Any::Perl;
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
Expand All @@ -40,9 +40,9 @@ use Config::Any::Perl;
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
Expand All @@ -54,7 +54,7 @@ use Config::Any::Perl;
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';
}
41 changes: 32 additions & 9 deletions t/54-xml.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@ if ( !Config::Any::XML->is_supported ) {
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
Expand All @@ -28,25 +39,37 @@ SKIP: {
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';
}

8 changes: 4 additions & 4 deletions t/55-yaml.t
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ else {
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';
}

0 comments on commit e018669

Please sign in to comment.