5 3_conf_01_write.t - Test CGI::Ex::Conf's ability to write and read the various file types.
10 use Test::More tests => 18;
12 use_ok('CGI::Ex::Conf');
15 $dir =~ tr|\\|/|; # should probably use File::Spec
16 $dir =~ s|[^/]+$|../samples| || die "Couldn't determine dir";
17 $dir =~ s|^t/|./t/|; # to satisfy conf
19 my $obj = CGI::Ex::Conf->new({
20 paths => ["$dir/conf_path_1", "$dir/conf_path_3"],
23 my $tmpfile = "$obj->{paths}->[0]/write_test";
24 ### most test for the reading of files
25 ### are actually performed in the validation tests
40 $file = $tmpfile .'.pl';
41 ok( eval { $obj->write_ref($file, $hash) } );
42 $in = $obj->read_ref($file);
43 ok($in->{'three'}->{'foo'} eq 'Foo');
47 skip("YAML.pm not found", 2) if ! eval { require YAML };
48 my $file = $tmpfile .'.yaml';
49 ok( eval { $obj->write_ref($file, $hash) } );
50 my $in = $obj->read_ref($file);
51 ok($in->{'three'}->{'foo'} eq 'Foo');
56 skip("JSON.pm not found", 2) if ! eval { require JSON };
57 my $file = $tmpfile .'.json';
58 ok( eval { $obj->write_ref($file, $hash) } );
59 my $in = $obj->read_ref($file);
60 ok($in->{'three'}->{'foo'} eq 'Foo');
65 skip("Storable.pm not found", 2) if ! eval { require Storable };
66 $file = $tmpfile .'.sto';
67 ok( eval { $obj->write_ref($file, $hash) } );
68 $in = $obj->read_ref($file);
69 ok($in->{'three'}->{'foo'} eq 'Foo');
74 skip("XML::Simple not found", 2) if ! eval { require XML::Simple };
75 $file = $tmpfile .'.xml';
76 ok( eval { $obj->write_ref($file, $hash) } );
77 $in = $obj->read_ref($file);
78 ok($in->{'three'}->{'foo'} eq 'Foo');
83 skip("Config::IniHash not found", 2) if ! eval { require Config::IniHash };
84 ### ini likes hash O' hashes
87 $file = $tmpfile .'.ini';
88 ok( eval { $obj->write_ref($file, $hash) } );
89 $in = $obj->read_ref($file);
90 ok($in->{'three'}->{'foo'} eq 'Foo');
95 skip('YAML.pm still not found', 4) if ! eval { require YAML };
96 ok (eval { $obj->write('FooSpace', $hash) });
97 ok (unlink $obj->{'paths'}->[1] . '/FooSpace.conf');
99 ok (eval { $obj->write('FooSpace', $hash, {directive => 'FIRST'}) });
100 ok (unlink $obj->{'paths'}->[0] . '/FooSpace.conf');