]> Dogcows Code - chaz/p5-CGI-Ex/blob - t/3_conf_01_write.t
d77c83a92d493ad8e47ea8a7b15c61d8447e02fc
[chaz/p5-CGI-Ex] / t / 3_conf_01_write.t
1 # -*- Mode: Perl; -*-
2
3 use Test;
4
5 BEGIN {plan tests => 12};
6
7 use CGI::Ex::Conf;
8 ok(1);
9
10 my $dir = $0;
11 $dir =~ tr|\\|/|; # should probably use File::Spec
12 $dir =~ s|/[^/]+$||;
13 $dir = '.' if ! length $dir;
14 $dir .= '/samples';
15 my $obj = CGI::Ex::Conf->new({
16 paths => ["$dir/conf_path_1", "$dir/conf_path_3"],
17 });
18
19 my $tmpfile = "$obj->{paths}->[0]/write_test";
20 ### most test for the reading of files
21 ### are actually performed in the validation tests
22
23 ok($obj);
24
25 my $hash = {
26 one => 1,
27 two => 2,
28 three => {
29 foo => 'Foo',
30 bar => 'Bar',
31 },
32 };
33
34 my $file = $tmpfile .'.yaml';
35 ok( eval { $obj->write_ref($file, $hash) } );
36 my $in = $obj->read_ref($file);
37 ok($in->{'three'}->{'foo'} eq 'Foo');
38 unlink $file;
39
40 $file = $tmpfile .'.sto';
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 $file = $tmpfile .'.pl';
47 ok( eval { $obj->write_ref($file, $hash) } );
48 $in = $obj->read_ref($file);
49 ok($in->{'three'}->{'foo'} eq 'Foo');
50 unlink $file;
51
52 #$file = $tmpfile .'.xml';
53 #ok( eval { $obj->write_ref($file, $hash) } );
54 #$in = $obj->read_ref($file);
55 #ok($in->{'three'}->{'foo'} eq 'Foo');
56 #unlink $file;
57 #
58 #### ini likes hash O' hashes
59 #$hash->{'one'} = {};
60 #$hash->{'two'} = {};
61 #$file = $tmpfile .'.ini';
62 #ok( eval { $obj->write_ref($file, $hash) } );
63 #$in = $obj->read_ref($file);
64 #ok($in->{'three'}->{'foo'} eq 'Foo');
65 #unlink $file;
66
67 ok (eval { $obj->write('FooSpace', $hash) });
68 ok (unlink $obj->{'paths'}->[1] . '/FooSpace.conf');
69
70 ok (eval { $obj->write('FooSpace', $hash, {directive => 'FIRST'}) });
71 ok (unlink $obj->{'paths'}->[0] . '/FooSpace.conf');
This page took 0.033844 seconds and 3 git commands to generate.