You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-dev@httpd.apache.org by Stas Bekman <st...@stason.org> on 2001/08/31 09:12:23 UTC

expect_ok sub?

Many times we create subtests like this:

print comment
my $expect = ...
my $got    = ...
print expect
print got
ok $expect eq $got

and end up with lots of typing. I suggest expect_ok, or just eok():

sub expect_ok{
    my ($expect,$received,$comment) = @_;
    print "$comment\n" if defined $comment;
    print "expected: $expect\n";
    print "received: $received\n";
    ok($expect eq $received);
}

so for example here is a test from alias.t shrink-wrapped:

## with ScriptAliasMatch ##
eok(
   $string,
   GET_BODY("/aliascgi-script"),
   "verifying ScriptAliasMatch with /aliascgi-script",
   );

I think using 'eq' is safe enough for numerical and string comparisons. or
we could make e_num_ok and e_str_ok to use '==' and 'eq' respectively.

some people write tests without printing expect/received strings and when
the test fail, users have to go and do it themselves. Such a wrapper does
this job for the test writers for free.

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:stas@stason.org   http://localhost/      http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/