Commit 3bf0b33a by Nils Goroll

better assertions with should(eq)

parent 048d14a9
......@@ -46,6 +46,22 @@ sub assert ($;$) {
return undef;
}
sub should ($$) {
unless($_[0] == $_[1]) {
require Carp;
Carp::confess( _fail_msg($_[0].' == '.$_[1]) );
}
return undef;
}
sub shouldeq ($$) {
unless($_[0] eq $_[1]) {
require Carp;
Carp::confess( _fail_msg($_[0].' == '.$_[1]) );
}
return undef;
}
sub _fail_msg {
my($name) = shift;
my $msg = 'Assertion';
......@@ -856,7 +872,8 @@ sub fixup_entry($$) {
if ($reorderref->[$entry->[ENTRY_ID]]) {
assert($reorderref->[$entry->[ENTRY_ID]]->[0] eq ${$entry->[ENTRY_KEY]});
shouldeq($reorderref->[$entry->[ENTRY_ID]]->[0],
${$entry->[ENTRY_KEY]});
$entry->[ENTRY_ORDER] = $reorderref->[$entry->[ENTRY_ID]]->[1];
warn 'reordered from fixup: id '.$entry->[ENTRY_ID].' order '.$entry->[ENTRY_ORDER];
}
......@@ -1153,7 +1170,7 @@ EOF
_VCL (F_CLASSIFIER_C, VCL_TOP,
join(",\n",
map {
assert($entries[$_]->[ENTRY_INDEX] == $_);
should($entries[$_]->[ENTRY_INDEX], $_);
"\t{ .magic\t= DCS_ENTRY_MAGIC, ".
(defined($entries[$_]->[ENTRY_COMMON_MATCHMASK])
? '.common_matchmask = 0x'.unpack("H*", pack("I>", $entries[$_]->[ENTRY_COMMON_MATCHMASK])). ', '
......@@ -1177,7 +1194,7 @@ _VCL (F_CLASSIFIER_C, VCL_TOP,
join(",\n",
map {
my $s = $subkeys_byid[$_];
assert ($_ == $subkeys_byid[$_]->[SUBKEY_ID]);
should ($_, $subkeys_byid[$_]->[SUBKEY_ID]);
"\t{ .magic = DCS_SUBKEY_MAGIC, ".
'.id = '.$_.', '.
'.common_matchmask = 0x'.unpack("H*", pack("I>", $subkeys_byid[$_]->[SUBKEY_COMMON_MATCHMASK])). ', '.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment