t/00-config.t
branchhs12
changeset 85 c47953192c5c
parent 80 fc2156761c29
child 86 dc8741bbad33
equal deleted inserted replaced
84:7c94598b7649 85:c47953192c5c
    10     use_ok "DNStools::Config", "get_config";
    10     use_ok "DNStools::Config", "get_config";
    11 }
    11 }
    12 
    12 
    13 can_ok("DNStools::Config" => "get_config");
    13 can_ok("DNStools::Config" => "get_config");
    14 
    14 
    15 # should die if there is no config
       
    16 eval { get_config() };
       
    17 ok($@, "dies on missing file names");
       
    18 
       
    19 eval { get_config("xxx|xxx", "yyy|yyy") };
    15 eval { get_config("xxx|xxx", "yyy|yyy") };
    20 ok($@, "dies on missing config");
    16 ok($@, "dies on missing config");
    21 
    17 
       
    18 my ($tmp, %cf);
       
    19 
    22 # prepare some simple sample config
    20 # prepare some simple sample config
    23 my $tmp = File::Temp->new();
    21 $tmp = File::Temp->new();
    24 print {$tmp} <<__EOF;
    22 print {$tmp} <<__EOF;
    25 # comment
    23 # comment
    26 abc = xyz
    24 abc = xyz
    27 other =    value with space
    25 other =    value with space
    28 __EOF
    26 __EOF
    29 close($tmp);
    27 close($tmp);
    30 
    28 
    31 my %cf = get_config($tmp->filename);
    29 # the files is specified, it should find the first 
       
    30 # existing
       
    31 %cf = get_config("xxx|xxx", $tmp->filename);
    32 ok(%cf, "got config");
    32 ok(%cf, "got config");
       
    33 is($cf{abc} => "xyz", "simple value");
       
    34 is($cf{other} => "valuewithspace", "spaced value");
    33 
    35 
       
    36 # it should find the file specified in $ENV{DNSTOOLS_CONF}
       
    37 $ENV{DNSTOOLS_CONF} = $tmp->filename;
       
    38 %cf = ();
       
    39 %cf = get_config("xxx|xxx", $tmp->filename);
       
    40 ok(%cf, "got config from env");
    34 is($cf{abc} => "xyz", "simple value");
    41 is($cf{abc} => "xyz", "simple value");
    35 is($cf{other} => "valuewithspace", "spaced value");
    42 is($cf{other} => "valuewithspace", "spaced value");
    36 
    43 
    37 
    44 
    38 done_testing();
    45 done_testing();