]> Dogcows Code - chaz/p5-CGI-Ex/blobdiff - t/3_conf_01_write.t
CGI::Ex 2.00
[chaz/p5-CGI-Ex] / t / 3_conf_01_write.t
index d77c83a92d493ad8e47ea8a7b15c61d8447e02fc..c31bfe4280f7ac89ea68458625fa78244d43f8a9 100644 (file)
@@ -1,17 +1,21 @@
 # -*- Mode: Perl; -*-
 
-use Test;
+=head1 NAME
 
-BEGIN {plan tests => 12};
+3_conf_01_write.t - Test CGI::Ex::Conf's ability to write and read the various file types.
 
-use CGI::Ex::Conf;
-ok(1);
+=cut
 
-my $dir = $0;
+use strict;
+use Test::More tests => 18;
+
+use_ok('CGI::Ex::Conf');
+
+my $dir = __FILE__;
 $dir =~ tr|\\|/|; # should probably use File::Spec
-$dir =~ s|/[^/]+$||;
-$dir = '.' if ! length $dir;
-$dir .= '/samples';
+$dir =~ s|[^/]+$|../samples| || die "Couldn't determine dir";
+$dir =~ s|^t/|./t/|; # to satisfy conf
+
 my $obj = CGI::Ex::Conf->new({
   paths => ["$dir/conf_path_1", "$dir/conf_path_3"],
 });
@@ -30,18 +34,8 @@ my $hash = {
     bar => 'Bar',
   },
 };
-
-my $file = $tmpfile .'.yaml';
-ok( eval { $obj->write_ref($file, $hash) } );
-my $in = $obj->read_ref($file);
-ok($in->{'three'}->{'foo'} eq 'Foo');
-unlink $file;
-
-$file = $tmpfile .'.sto';
-ok( eval { $obj->write_ref($file, $hash) } );
-$in = $obj->read_ref($file);
-ok($in->{'three'}->{'foo'} eq 'Foo');
-unlink $file;
+my $file;
+my $in;
 
 $file = $tmpfile .'.pl';
 ok( eval { $obj->write_ref($file, $hash) } );
@@ -49,23 +43,59 @@ $in = $obj->read_ref($file);
 ok($in->{'three'}->{'foo'} eq 'Foo');
 unlink $file;
 
-#$file = $tmpfile .'.xml';
-#ok( eval { $obj->write_ref($file, $hash) } );
-#$in = $obj->read_ref($file);
-#ok($in->{'three'}->{'foo'} eq 'Foo');
-#unlink $file;
-#
-#### ini likes hash O' hashes
-#$hash->{'one'} = {};
-#$hash->{'two'} = {};
-#$file = $tmpfile .'.ini';
-#ok( eval { $obj->write_ref($file, $hash) } );
-#$in = $obj->read_ref($file);
-#ok($in->{'three'}->{'foo'} eq 'Foo');
-#unlink $file;
-
-ok (eval { $obj->write('FooSpace', $hash) });
-ok (unlink $obj->{'paths'}->[1] . '/FooSpace.conf');
-
-ok (eval { $obj->write('FooSpace', $hash, {directive => 'FIRST'}) });
-ok (unlink $obj->{'paths'}->[0] . '/FooSpace.conf');
+SKIP: {
+    skip("YAML.pm not found", 2) if ! eval { require YAML };
+    my $file = $tmpfile .'.yaml';
+    ok( eval { $obj->write_ref($file, $hash) } );
+    my $in = $obj->read_ref($file);
+    ok($in->{'three'}->{'foo'} eq 'Foo');
+    unlink $file;
+};
+
+SKIP: {
+    skip("JSON.pm not found", 2) if ! eval { require JSON };
+    my $file = $tmpfile .'.json';
+    ok( eval { $obj->write_ref($file, $hash) } );
+    my $in = $obj->read_ref($file);
+    ok($in->{'three'}->{'foo'} eq 'Foo');
+    unlink $file;
+};
+
+SKIP: {
+    skip("Storable.pm not found", 2) if ! eval { require Storable };
+    $file = $tmpfile .'.sto';
+    ok( eval { $obj->write_ref($file, $hash) } );
+    $in = $obj->read_ref($file);
+    ok($in->{'three'}->{'foo'} eq 'Foo');
+    unlink $file;
+};
+
+SKIP: {
+    skip("XML::Simple not found", 2) if ! eval { require XML::Simple };
+    $file = $tmpfile .'.xml';
+    ok( eval { $obj->write_ref($file, $hash) } );
+    $in = $obj->read_ref($file);
+    ok($in->{'three'}->{'foo'} eq 'Foo');
+    unlink $file;
+};
+
+SKIP: {
+    skip("Config::IniHash not found", 2) if ! eval { require Conifg::IniHash };
+    ### ini likes hash O' hashes
+    $hash->{'one'} = {};
+    $hash->{'two'} = {};
+    $file = $tmpfile .'.ini';
+    ok( eval { $obj->write_ref($file, $hash) } );
+    $in = $obj->read_ref($file);
+    ok($in->{'three'}->{'foo'} eq 'Foo');
+    unlink $file;
+};
+
+SKIP: {
+    skip('YAML.pm still not found', 4) if ! eval { require YAML };
+    ok (eval { $obj->write('FooSpace', $hash) });
+    ok (unlink $obj->{'paths'}->[1] . '/FooSpace.conf');
+
+    ok (eval { $obj->write('FooSpace', $hash, {directive => 'FIRST'}) });
+    ok (unlink $obj->{'paths'}->[0] . '/FooSpace.conf');
+};
This page took 0.018754 seconds and 4 git commands to generate.