From: Brian Cassidy <bricas@cpan.org>
Date: Tue, 5 Aug 2008 12:03:26 +0000 (+0000)
Subject: add parse error tests. ensure INI errors are trapped. bumped version.
X-Git-Tag: v0.13~4
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5770ffc01feb6998b8a7e23d66b52d33e4a62b35;p=p5sagit%2FConfig-Any.git

add parse error tests. ensure INI errors are trapped. bumped version.
---

diff --git a/Changes b/Changes
index b61b057..939f975 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,9 @@
 Revision history for Config-Any
 
-    - Show actual parse error when parse fails (Marcus Ramberg).
+0.13 XXX
+    - show actual parse error when parse fails (Marcus Ramberg)
+    - ensure Config::Tiny parse errors are trapped
+    - added tests for each format to ensure they throw parse errors
 
 0.12 Mon 07 Apr 2008
     - ensure Perl loader dies on a failed require() (RT #32995)
diff --git a/lib/Config/Any.pm b/lib/Config/Any.pm
index d0d789c..1b056e1 100644
--- a/lib/Config/Any.pm
+++ b/lib/Config/Any.pm
@@ -6,7 +6,7 @@ use warnings;
 use Carp;
 use Module::Pluggable::Object ();
 
-our $VERSION = '0.12';
+our $VERSION = '0.13';
 
 =head1 NAME
 
diff --git a/lib/Config/Any/INI.pm b/lib/Config/Any/INI.pm
index 68e3f06..e0d7215 100644
--- a/lib/Config/Any/INI.pm
+++ b/lib/Config/Any/INI.pm
@@ -45,6 +45,9 @@ sub load {
 
     require Config::Tiny;
     my $config = Config::Tiny->read( $file );
+
+    die $Config::Tiny::errstr if not defined $config;
+
     my $out = delete $config->{ _ } || {};
 
     for my $k ( keys %$config ) {
diff --git a/t/50-general.t b/t/50-general.t
index ec0dc53..e173624 100644
--- a/t/50-general.t
+++ b/t/50-general.t
@@ -8,7 +8,7 @@ if ( !Config::Any::General->is_supported ) {
     plan skip_all => 'Config::General format not supported';
 }
 else {
-    plan tests => 4;
+    plan tests => 6;
 }
 
 {
@@ -23,3 +23,12 @@ else {
         { -LowerCaseNames => 1 } );
     ok( exists $config->{ component } );
 }
+
+# test invalid config
+{
+    my $file   = 't/invalid/conf.conf';
+    my $config = eval { Config::Any::General->load( $file ) };
+
+    ok( !$config, 'config load failed' );
+    ok( $@, "error thrown ($@)" ); 
+}
diff --git a/t/51-ini.t b/t/51-ini.t
index 8040d5b..6848004 100644
--- a/t/51-ini.t
+++ b/t/51-ini.t
@@ -8,7 +8,7 @@ if ( !Config::Any::INI->is_supported ) {
     plan skip_all => 'INI format not supported';
 }
 else {
-    plan tests => 11;
+    plan tests => 13;
 }
 
 {
@@ -46,3 +46,12 @@ else {
     ok( $config, 'config loaded' );
     is_deeply( $config, \%expected, 'subsections parsed properly' );
 }
+
+# test invalid config
+{
+    my $file   = 't/invalid/conf.ini';
+    my $config = eval { Config::Any::INI->load( $file ) };
+
+    ok( !$config, 'config load failed' );
+    ok( $@, "error thrown ($@)" ); 
+}
diff --git a/t/52-json.t b/t/52-json.t
index 5467ebe..23eb920 100644
--- a/t/52-json.t
+++ b/t/52-json.t
@@ -8,7 +8,7 @@ if ( !Config::Any::JSON->is_supported ) {
     plan skip_all => 'JSON format not supported';
 }
 else {
-    plan tests => 2;
+    plan tests => 4;
 }
 
 {
@@ -16,3 +16,12 @@ else {
     ok( $config );
     is( $config->{ name }, 'TestApp' );
 }
+
+# test invalid config
+{
+    my $file   = 't/invalid/conf.json';
+    my $config = eval { Config::Any::JSON->load( $file ) };
+
+    ok( !$config, 'config load failed' );
+    ok( $@, "error thrown ($@)" ); 
+}
diff --git a/t/53-perl.t b/t/53-perl.t
index 6d2d5ca..b11a60c 100644
--- a/t/53-perl.t
+++ b/t/53-perl.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 3;
+use Test::More tests => 5;
 
 use Config::Any::Perl;
 
@@ -16,3 +16,11 @@ use Config::Any::Perl;
     is_deeply( $config_load2, $config, 'multiple loads of the same file' );
 }
 
+# test invalid config
+{
+    my $file   = 't/invalid/conf.pl';
+    my $config = eval { Config::Any::Perl->load( $file ) };
+
+    ok( !$config, 'config load failed' );
+    ok( $@, "error thrown ($@)" ); 
+}
diff --git a/t/54-xml.t b/t/54-xml.t
index fb52d51..02fd793 100644
--- a/t/54-xml.t
+++ b/t/54-xml.t
@@ -8,7 +8,7 @@ if ( !Config::Any::XML->is_supported ) {
     plan skip_all => 'XML format not supported';
 }
 else {
-    plan tests => 2;
+    plan tests => 4;
 }
 
 {
@@ -16,3 +16,12 @@ else {
     ok( $config );
     is( $config->{ name }, 'TestApp' );
 }
+
+# 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 ($@)" ); 
+}
diff --git a/t/55-yaml.t b/t/55-yaml.t
index 3c95831..d042cc4 100644
--- a/t/55-yaml.t
+++ b/t/55-yaml.t
@@ -8,7 +8,7 @@ if ( !Config::Any::YAML->is_supported ) {
     plan skip_all => 'YAML format not supported';
 }
 else {
-    plan tests => 2;
+    plan tests => 4;
 }
 
 {
@@ -16,3 +16,12 @@ else {
     ok( $config );
     is( $config->{ name }, 'TestApp' );
 }
+
+# test invalid config
+{
+    my $file   = 't/invalid/conf.yml';
+    my $config = eval { Config::Any::YAML->load( $file ) };
+
+    ok( !$config, 'config load failed' );
+    ok( $@, "error thrown ($@)" ); 
+}
diff --git a/t/63-invalid.t b/t/63-invalid.t
deleted file mode 100644
index 932e93d..0000000
--- a/t/63-invalid.t
+++ /dev/null
@@ -1,14 +0,0 @@
-use strict;
-use warnings;
-
-use Test::More tests => 2;
-
-use Config::Any::Perl;
-
-{
-    my $file   = 't/conf/conf_invalid.pl';
-    my $config = eval { Config::Any::Perl->load( $file ) };
-
-    ok( !$config, 'config load failed' );
-    ok( $@, "error thrown ($@)" ); 
-}
diff --git a/t/conf/conf_invalid.pl b/t/conf/conf_invalid.pl
deleted file mode 100644
index fdbc936..0000000
--- a/t/conf/conf_invalid.pl
+++ /dev/null
@@ -1 +0,0 @@
-this is not valid perl.
diff --git a/t/invalid/conf.conf b/t/invalid/conf.conf
new file mode 100644
index 0000000..f0f55b4
--- /dev/null
+++ b/t/invalid/conf.conf
@@ -0,0 +1,7 @@
+name = TestApp
+<Component Controller::Foo
+    foo bar
+</Component>
+<Model Model::Baz>
+    qux xyzzy
+</Model>
diff --git a/t/invalid/conf.ini b/t/invalid/conf.ini
new file mode 100644
index 0000000..3323d75
--- /dev/null
+++ b/t/invalid/conf.ini
@@ -0,0 +1,7 @@
+name=TestApp
+    
+[Component Controller::Foo
+foo=bar
+
+[Model Model::Baz]
+qux=xyzzy
diff --git a/t/invalid/conf.json b/t/invalid/conf.json
new file mode 100644
index 0000000..eb6497c
--- /dev/null
+++ b/t/invalid/conf.json
@@ -0,0 +1,13 @@
+{
+    "name": "TestApp",
+    "Component": {
+        "Controller::Foo": {
+            "foo": "bar"
+        }
+    },
+    "Model": {
+        "Model::Baz": {
+            "qux": "xyzzy"
+        }
+    }
+
diff --git a/t/invalid/conf.pl b/t/invalid/conf.pl
new file mode 100644
index 0000000..d7fcbf6
--- /dev/null
+++ b/t/invalid/conf.pl
@@ -0,0 +1,4 @@
+{   name      => 'TestApp'
+    Component => { 'Controller::Foo' => { foo => 'bar' } },
+    Model     => { 'Model::Baz' => { qux => 'xyzzy' } }
+}
diff --git a/t/invalid/conf.xml b/t/invalid/conf.xml
new file mode 100644
index 0000000..8a6b109
--- /dev/null
+++ b/t/invalid/conf.xml
@@ -0,0 +1,9 @@
+<config>
+    <name>TestApp</name
+    <Component name="Controller::Foo">
+        <foo>bar</foo>
+    </Component>
+    <Model name="Model::Baz">
+        <qux>xyzzy</qux>
+    </Model>
+</config>
diff --git a/t/invalid/conf.yml b/t/invalid/conf.yml
new file mode 100644
index 0000000..93db559
--- /dev/null
+++ b/t/invalid/conf.yml
@@ -0,0 +1,8 @@
+---
+name: TestApp
+Component:
+	Controller::Foo:
+        foo: bar
+Model:
+    Model::Baz:
+        qux: xyzzy