t/00-config.t
changeset 150 3db363880766
parent 143 c26b5fa3f646
equal deleted inserted replaced
146:a3860111db49 150:3db363880766
     8 
     8 
     9 BEGIN {
     9 BEGIN {
    10     use_ok "DNStools::Config" => qw(get_config);
    10     use_ok "DNStools::Config" => qw(get_config);
    11 }
    11 }
    12 
    12 
    13 can_ok("DNStools::Config" => "get_config");
    13 can_ok( "DNStools::Config" => "get_config" );
    14 
    14 
    15 eval { get_config("xxx|xxx", "yyy|yyy") };
    15 eval { get_config( "xxx|xxx", "yyy|yyy" ) };
    16 ok($@, "dies on missing config");
    16 ok( $@, "dies on missing config" );
    17 
    17 
    18 my ($tmp, %cf);
    18 my ( $tmp, %cf );
    19 
    19 
    20 # prepare some simple sample config
    20 # prepare some simple sample config
    21 my $c = <<EOF;
    21 my $c = <<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 $tmp = Aux::make_config $c;
    27 close($tmp);
    27 close($tmp);
    28 
    28 
    29 # the files is specified, it should find the first 
    29 # the files is specified, it should find the first
    30 # existing
    30 # existing
    31 %cf = get_config("xxx|xxx", $tmp->filename);
    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");
    33 is( $cf{abc}   => "xyz",            "simple value" );
    34 is($cf{other} => "valuewithspace", "spaced value");
    34 is( $cf{other} => "valuewithspace", "spaced value" );
    35 
    35 
    36 # it should find the file specified in $ENV{DNSTOOLS_CONF}
    36 # it should find the file specified in $ENV{DNSTOOLS_CONF}
    37 $ENV{DNSTOOLS_CONF} = $tmp->filename;
    37 $ENV{DNSTOOLS_CONF} = $tmp->filename;
    38 %cf = ();
    38 %cf                 = ();
    39 %cf = get_config();
    39 %cf                 = get_config();
    40 ok(%cf, "got config from \$DNSTOOLS_CONF");
    40 ok( %cf, "got config from \$DNSTOOLS_CONF" );
    41 is($cf{abc} => "xyz", "simple value");
    41 is( $cf{abc}   => "xyz",            "simple value" );
    42 is($cf{other} => "valuewithspace", "spaced value");
    42 is( $cf{other} => "valuewithspace", "spaced value" );