From: Graham Knop Date: Sun, 9 Apr 2017 13:09:06 +0000 (+0200) Subject: better diagnostics on test failures X-Git-Tag: v0.31~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e0186698ea45049a14a46eeffeb648a4b6092785;p=p5sagit%2FConfig-Any.git better diagnostics on test failures --- diff --git a/t/10-branches.t b/t/10-branches.t index 9041f09..eda0ae8 100644 --- a/t/10-branches.t +++ b/t/10-branches.t @@ -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 } ), diff --git a/t/20-parse.t b/t/20-parse.t index bd834ba..e1696a9 100644 --- a/t/20-parse.t +++ b/t/20-parse.t @@ -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; @@ -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 diff --git a/t/50-general.t b/t/50-general.t index 5361ca2..373e8e8 100644 --- a/t/50-general.t +++ b/t/50-general.t @@ -36,8 +36,8 @@ 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 @@ -45,6 +45,6 @@ else { 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'; } diff --git a/t/51-ini.t b/t/51-ini.t index c85ab27..9c81ca8 100644 --- a/t/51-ini.t +++ b/t/51-ini.t @@ -53,8 +53,8 @@ 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 @@ -62,6 +62,6 @@ else { 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'; } diff --git a/t/52-json.t b/t/52-json.t index 555e74e..c9e0967 100644 --- a/t/52-json.t +++ b/t/52-json.t @@ -23,8 +23,8 @@ 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 @@ -32,6 +32,6 @@ else { 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'; } diff --git a/t/53-perl.t b/t/53-perl.t index 1c26ff4..6952948 100644 --- a/t/53-perl.t +++ b/t/53-perl.t @@ -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 @@ -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 @@ -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'; } diff --git a/t/54-xml.t b/t/54-xml.t index 0d546cb..0fc6fd9 100644 --- a/t/54-xml.t +++ b/t/54-xml.t @@ -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 @@ -28,8 +39,8 @@ 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 @@ -37,8 +48,20 @@ SKIP: { 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 @@ -46,7 +69,7 @@ SKIP: { 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'; } diff --git a/t/55-yaml.t b/t/55-yaml.t index b6d1f9e..2b2c52d 100644 --- a/t/55-yaml.t +++ b/t/55-yaml.t @@ -24,8 +24,8 @@ 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 @@ -33,6 +33,6 @@ else { 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'; }