]> Dogcows Code - chaz/p5-CGI-Ex/blob - t/3_conf_01_write.t
c31bfe4280f7ac89ea68458625fa78244d43f8a9
[chaz/p5-CGI-Ex] / t / 3_conf_01_write.t
1 # -*- Mode: Perl; -*-
2
3 =head1 NAME
4
5 3_conf_01_write.t - Test CGI::Ex::Conf's ability to write and read the various file types.
6
7 =cut
8
9 use strict;
10 use Test::More tests => 18;
11
12 use_ok('CGI::Ex::Conf');
13
14 my $dir = __FILE__;
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
18
19 my $obj = CGI::Ex::Conf->new({
20 paths => ["$dir/conf_path_1", "$dir/conf_path_3"],
21 });
22
23 my $tmpfile = "$obj->{paths}->[0]/write_test";
24 ### most test for the reading of files
25 ### are actually performed in the validation tests
26
27 ok($obj);
28
29 my $hash = {
30 one => 1,
31 two => 2,
32 three => {
33 foo => 'Foo',
34 bar => 'Bar',
35 },
36 };
37 my $file;
38 my $in;
39
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');
44 unlink $file;
45
46 SKIP: {
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');
52 unlink $file;
53 };
54
55 SKIP: {
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');
61 unlink $file;
62 };
63
64 SKIP: {
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');
70 unlink $file;
71 };
72
73 SKIP: {
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');
79 unlink $file;
80 };
81
82 SKIP: {
83 skip("Config::IniHash not found", 2) if ! eval { require Conifg::IniHash };
84 ### ini likes hash O' hashes
85 $hash->{'one'} = {};
86 $hash->{'two'} = {};
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');
91 unlink $file;
92 };
93
94 SKIP: {
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');
98
99 ok (eval { $obj->write('FooSpace', $hash, {directive => 'FIRST'}) });
100 ok (unlink $obj->{'paths'}->[0] . '/FooSpace.conf');
101 };
This page took 0.031426 seconds and 3 git commands to generate.