Advanced-Config
view release on metacpan or search on metacpan
t/10-validate_simple_cfg.t view on Meta::CPAN
}
dbug_is ($cnt, 0, "All tags were accounted for in the validation hash!");
DBUG_PRINT ("----", "%s", "-"x50);
foreach ( sort keys %{$validate} ) {
my $val1 = $validate->{$_};
my $val2 = $cfg->get_value ( $_ );
my $val3 = (defined $val2) ? $val2 : "";
my $chk = (defined $val2) && $val1 eq $val2;
dbug_ok ( $chk, "Validating tag \"$_\" matches config file. ($val3)" );
unless ( $chk ) {
DBUG_PRINT ("ERROR", "Value should have been: %s", $val1);
}
}
# Since I didn't count the test cases, must end my program
# with a call to this method. Can't do tests in END anymore!
done_testing ();
DBUG_LEAVE (0);
}
# ====================================================================
# All tags defined in the config file must be initialized below!
# The config file is: t/config/10-simple.cfg
# And it's a very basic one without sections or sourcing in of other files!
# NOTE: No tag may have undef as a value!
# This can't happen in this module if a tag is defined!
# Undef means the tag doesn't exist instead!
sub init_validation_hash
{
DBUG_ENTER_FUNC (@_);
my $opts = shift;
my $dopts = shift;
my $sep = "";
my ($a, $b) = ("one", "two");
my $p = File::Spec->catfile ($a, $b);
if ( $p =~ m/^${a}(.+)${b}$/ ) {
$sep = $1;
}
my %dates;
Advanced::Config::Options::set_special_date_vars ($dopts, \%dates);
my %values = ( "a" => "A is for Apple!",
"b" => "B is for Bat!",
"c" => "C is for Cat!",
"d" => "D is for Dog!",
"e" => "E is for Elephant!",
"f" => "'F is for Frog!" . '"',
"g" => '$fooled you',
"h_pwd" => 'Hello World!',
"one" => "ONE", "two" => "TWO", "three" => "THREE",
"number 1" => "ONE TWO THREE",
"rule5_pid" => $$, "rule5_prog" => $0, "rule5_os" => $^O,
"rule6_host" => hostname(),
# "rule6_user" => getlogin () || getpwuid ($<) || "??",
"rule6_user" => Advanced::Config::Options::_get_user_id (),
"rule6_pid" => $$,
"rule6_p" => basename ($0, ".t"),
"rule6_sep" => $sep,
"cmt" => $opts->{comment},
"empty_1" => '',
"empty_2" => '',
"empty_3" => 'abc xyz',
"empty_4" => 'abc xyz',
"rule8 missing" => ""
);
$values{"number 2"} = $values{"number 1"};
$values{"number 3"} = $values{"number 1"};
$values{"number 4"} = $values{"number 1"};
$values{"number 5"} = $values{"number 1"};
$values{"number 6"} = $values{"number 1"};
$values{"number 8"} = $values{"number 1"};
$values{cmt2} = $values{cmt} . $values{cmt};
$values{cmt3} = $values{cmt} . $values{cmt} . $values{cmt};
# Handles rules 6 & 7 combined ...
$values{log1} = File::Spec->catfile ("t", "logs", $values{rule6_p} . ".");
$values{log3} = $values{log1} . $dates{tomorrow} . ".txt";
$values{log2} = $values{log1} . $dates{yesterday} . ".txt";
$values{log1} .= $dates{today} . ".txt";
eval {
$values{rule6_ppid} = getppid ();
};
if ( $@ ) {
$values{rule6_ppid} = "-1";
}
my $total = keys %values;
DBUG_RETURN ($total, \%values);
}
( run in 1.809 second using v1.01-cache-2.11-cpan-39bf76dae61 )