From: Russell Jenkins Date: Wed, 29 Apr 2015 00:48:45 +0000 (+1000) Subject: Test load_files throws parse errors when use_ext=1 X-Git-Tag: v0.26~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=commitdiff_plain;h=67a1cd509bfc3f77a4fcaf42710de01597987bb0 Test load_files throws parse errors when use_ext=1 Piggyback off existing tests for invalid config files to verify a parse error is thrown when the config is invalid and use_ext => 1. Signed-off-by: Brian Cassidy --- diff --git a/t/50-general.t b/t/50-general.t index cc7d6f8..5361ca2 100644 --- a/t/50-general.t +++ b/t/50-general.t @@ -2,13 +2,14 @@ use strict; use warnings; use Test::More; +use Config::Any; use Config::Any::General; if ( !Config::Any::General->is_supported ) { plan skip_all => 'Config::General format not supported'; } else { - plan tests => 7; + plan tests => 9; } { @@ -38,3 +39,12 @@ else { ok( !$config, 'config load failed' ); ok( $@, "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 ($@)" ); +} diff --git a/t/51-ini.t b/t/51-ini.t index 1fea544..c85ab27 100644 --- a/t/51-ini.t +++ b/t/51-ini.t @@ -2,13 +2,14 @@ use strict; use warnings; use Test::More; +use Config::Any; use Config::Any::INI; if ( !Config::Any::INI->is_supported ) { plan skip_all => 'INI format not supported'; } else { - plan tests => 13; + plan tests => 15; } { @@ -55,3 +56,12 @@ else { ok( !$config, 'config load failed' ); ok( $@, "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 ($@)" ); +} diff --git a/t/52-json.t b/t/52-json.t index 65c6099..555e74e 100644 --- a/t/52-json.t +++ b/t/52-json.t @@ -2,13 +2,14 @@ use strict; use warnings; use Test::More; +use Config::Any; use Config::Any::JSON; if ( !Config::Any::JSON->is_supported ) { plan skip_all => 'JSON format not supported'; } else { - plan tests => 4; + plan tests => 6; } { @@ -25,3 +26,12 @@ else { ok( !$config, 'config load failed' ); ok( $@, "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 ($@)" ); +} diff --git a/t/53-perl.t b/t/53-perl.t index 5ad0468..1a749a1 100644 --- a/t/53-perl.t +++ b/t/53-perl.t @@ -1,8 +1,8 @@ use strict; use warnings; -use Test::More tests => 5; - +use Test::More tests => 7; +use Config::Any; use Config::Any::Perl; { @@ -24,3 +24,12 @@ use Config::Any::Perl; ok( !$config, 'config load failed' ); ok( $@, "error thrown ($@)" ); } + +# parse error generated on invalid config +{ + my $file = 't/invalid/conf.pl'; + my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) }; + + ok( !$config, 'config load failed' ); + ok( $@, "error thrown ($@)" ); +} diff --git a/t/54-xml.t b/t/54-xml.t index 45fd66e..0d546cb 100644 --- a/t/54-xml.t +++ b/t/54-xml.t @@ -2,13 +2,14 @@ use strict; use warnings; use Test::More; +use Config::Any; use Config::Any::XML; if ( !Config::Any::XML->is_supported ) { plan skip_all => 'XML format not supported'; } else { - plan tests => 6; + plan tests => 8; } { @@ -39,3 +40,13 @@ SKIP: { ok( $config, 'config loaded' ); ok( !$@, '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 ($@)" ); +} + diff --git a/t/55-yaml.t b/t/55-yaml.t index 7b7b5bc..b6d1f9e 100644 --- a/t/55-yaml.t +++ b/t/55-yaml.t @@ -3,13 +3,14 @@ use warnings; no warnings 'once'; use Test::More; +use Config::Any; use Config::Any::YAML; if ( !Config::Any::YAML->is_supported ) { plan skip_all => 'YAML format not supported'; } else { - plan tests => 4; + plan tests => 6; } { @@ -26,3 +27,12 @@ else { ok( !$config, 'config load failed' ); ok( $@, "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 ($@)" ); +}