]> Dogcows Code - chaz/p5-CGI-Ex/blobdiff - t/3_conf_00_base.t
CGI::Ex 2.27
[chaz/p5-CGI-Ex] / t / 3_conf_00_base.t
index 31591c00d33cf26c1fb6a42b916b58ced1bb554c..e41d8977c40573ced63b545defebf20bd1a4760d 100644 (file)
@@ -1,69 +1,51 @@
 # -*- Mode: Perl; -*-
 
-use Test;
+=head1 NAME
 
-BEGIN {plan tests => 24};
+3_conf_00_base.t - Test for the basic functionality of CGI::Ex::Conf
 
-use CGI::Ex::Conf;
-ok(1);
+=cut
 
-my $dir = $0;
-$dir =~ tr|\\|/|; # should probably use File::Spec
-$dir =~ s|/[^/]+$||;
-$dir = '.' if ! length $dir;
-$dir .= '/samples';
-my $obj = CGI::Ex::Conf->new({
-  paths => ["$dir/conf_path_1", "$dir/conf_path_3"],
-});
+use strict;
+use Test::More tests => 8;
+use POSIX qw(tmpnam);
 
-### most test for the reading of files
-### are actually performed in the validation tests
+my $file = tmpnam;
+END { unlink $file };
 
-ok($obj);
-
-my $hash = $obj->read('apples.pl');
-ok($hash);
-ok($hash->{quantity});
-
-$hash = $obj->read('apples.pl');
-ok($hash);
-ok($hash->{quantity});
-
-
-local $CGI::Ex::Conf::DIRECTIVE = 'FIRST';
-$hash = $obj->read('apples.pl');
-ok($hash);
-ok($hash->{quantity} == 20);
-ok($hash->{foo} eq 'file1');
-
-local $CGI::Ex::Conf::DIRECTIVE = 'LAST';
-$hash = $obj->read('apples.pl');
-ok($hash);
-ok($hash->{quantity} == 30);
-ok($hash->{foo} eq 'file2');
-
-$hash = $obj->read('apples.pl', {directive => 'MERGE'});
-ok($hash);
-ok($hash->{quantity} == 30);
-ok($hash->{foo} eq 'file1'); # has immutable value
-
-
-local $obj->{directive} = 'FIRST';
-$hash = $obj->read('oranges.pl');
-ok($hash);
-ok($hash->{quantity} == 20);
-ok($hash->{foo} eq 'file1');
-
-local $obj->{directive} = 'LAST';
-$hash = $obj->read('oranges.pl');
-ok($hash);
-ok($hash->{quantity} == 30);
-ok($hash->{foo} eq 'file2');
-
-local $obj->{directive} = 'MERGE';
-$hash = $obj->read('oranges.pl');
-ok($hash);
-ok($hash->{quantity} == 20); # has immutable key so all values are immutable
-ok($hash->{foo} eq 'file1'); # has immutable key so all values are immutable
+use_ok('CGI::Ex::Conf');
 
+my $obj = CGI::Ex::Conf->new;
+ok($obj);
 
+### TODO - re-enable more fileside tests
+
+if (eval { require JSON }) {
+    ok(eval { CGI::Ex::Conf::conf_write($file, {foo => "bar"}, {file_type => 'json'}) }, "Could JSON write") || diag($@);
+    my $ref = eval { CGI::Ex::Conf::conf_read($file, {file_type => 'json'}) };
+    is(eval { $ref->{'foo'} }, 'bar', "Could JSON read");
+} else {
+    SKIP: {
+        skip("Can't test read/write of json", 2);
+    };
+}
+
+if (eval { require YAML }) {
+    ok(eval { CGI::Ex::Conf::conf_write($file, {foo => "bar2"}, {file_type => 'yaml'}) }, "Could YAML write") || diag($@);
+    my $ref = eval { CGI::Ex::Conf::conf_read($file, {file_type => 'yaml'}) };
+    is(eval { $ref->{'foo'} }, 'bar2', "Could YAML read");
+} else {
+    SKIP: {
+        skip("Can't test read/write of yaml", 2);
+    };
+}
+
+if (eval { require Data::Dumper }) {
+    ok(eval { CGI::Ex::Conf::conf_write($file, {foo => "bar2"}, {file_type => 'pl'}) }, "Could Perl write") || diag($@);
+    my $ref = eval { CGI::Ex::Conf::conf_read($file, {file_type => 'pl'}) };
+    is(eval { $ref->{'foo'} }, 'bar2', "Could perl read");
+} else {
+    SKIP: {
+        skip("Can't test read/write of pl", 2);
+    };
+}
This page took 0.022725 seconds and 4 git commands to generate.