equal
deleted
inserted
replaced
1 #! /usr/bin/perl |
1 #! /usr/bin/perl |
2 |
2 |
3 use strict; |
3 use strict; |
4 use warnings; |
4 use warnings; |
|
5 use lib 't/lib'; |
5 use Test::More qw(no_plan); |
6 use Test::More qw(no_plan); |
6 use File::Temp; |
7 use Aux; |
7 |
8 |
8 BEGIN { |
9 BEGIN { |
9 use_ok "DNStools::Config" => qw(get_config); |
10 use_ok "DNStools::Config" => qw(get_config); |
10 } |
11 } |
11 |
12 |
15 ok($@, "dies on missing config"); |
16 ok($@, "dies on missing config"); |
16 |
17 |
17 my ($tmp, %cf); |
18 my ($tmp, %cf); |
18 |
19 |
19 # prepare some simple sample config |
20 # prepare some simple sample config |
20 $tmp = File::Temp->new(); |
21 my $c = <<EOF; |
21 print {$tmp} <<__EOF; |
|
22 # comment |
22 # comment |
23 abc = xyz |
23 abc = xyz |
24 other = value with space |
24 other = value with space |
25 __EOF |
25 EOF |
|
26 $tmp = Aux::make_config $c; |
26 close($tmp); |
27 close($tmp); |
27 |
28 |
28 # the files is specified, it should find the first |
29 # the files is specified, it should find the first |
29 # existing |
30 # existing |
30 %cf = get_config("xxx|xxx", $tmp->filename); |
31 %cf = get_config("xxx|xxx", $tmp->filename); |
33 is($cf{other} => "valuewithspace", "spaced value"); |
34 is($cf{other} => "valuewithspace", "spaced value"); |
34 |
35 |
35 # it should find the file specified in $ENV{DNSTOOLS_CONF} |
36 # it should find the file specified in $ENV{DNSTOOLS_CONF} |
36 $ENV{DNSTOOLS_CONF} = $tmp->filename; |
37 $ENV{DNSTOOLS_CONF} = $tmp->filename; |
37 %cf = (); |
38 %cf = (); |
38 %cf = get_config("xxx|xxx", $tmp->filename); |
39 %cf = get_config(); |
39 ok(%cf, "got config from \$DNSTOOLS_CONF"); |
40 ok(%cf, "got config from \$DNSTOOLS_CONF"); |
40 is($cf{abc} => "xyz", "simple value"); |
41 is($cf{abc} => "xyz", "simple value"); |
41 is($cf{other} => "valuewithspace", "spaced value"); |
42 is($cf{other} => "valuewithspace", "spaced value"); |