Test::Unit::Assert - unit testing framework assertion class |
Test::Unit::Assert - unit testing framework assertion class
# this class is not intended to be used directly, # normally you get the functionality by subclassing from # Test::Unit::TestCase
use Test::Unit::TestCase;
# more code here ...
$self->assert($your_condition_here, $your_optional_message_here);
# or, for regular expression comparisons: $self->assert(qr/some_pattern/, $result);
# or, for functional style coderef tests: $self->assert(sub { $_[0] == $_[1] or $self->fail("Expected $_[0], got $_[1]"); }, 1, 2);
# or, for old style regular expression comparisons # (strongly deprecated; see warning below) $self->assert(scalar("foo" =~ /bar/), $your_optional_message_here);
# Or, if you don't mind us guessing $self->assert_equals('expected', $actual [, $optional_message]); $self->assert_equals(1,$actual); $self->assert_not_equals('not expected', $actual [, $optional_message]); $self->assert_not_equals(0,1);
# Or, if you want to force the comparator $self->assert_num_equals(1,1); $self->assert_num_not_equals(1,0); $self->assert_str_equals('string','string'); $self->assert_str_not_equals('stringA', 'stringB');
# assert defined/undefined status $self->assert_null(undef); $self->assert_not_null('');
This class contains the various standard assertions used within the
framework. With the exception of the assert(CODEREF, @ARGS)
, all
the assertion methods take an optional message after the mandatory
fields. The message can either be a single string, or a list, which
will get concatenated.
Although you can specify a message, it is hoped that the default error messages generated when an assertion fails will be good enough for most cases.
If the first argument is an object, we check to see if the '=='
operator has been overloaded and use that if it has, otherwise we do
the string test.
NOTE This is NOT well-tested on circular references. Nor am I quite sure what will happen with filehandles.
If you want to use the ``old'' style for testing regular expression
matching, please be aware of this: the arguments to assert()
are
evaluated in list context, e.g. making a failing regex ``pull'' the
message into the place of the first argument. Since this is usually
just plain wrong, please use scalar()
to force the regex comparison
to yield a useful boolean value.
ok(@ARGS)
Copyright (c) 2000-2002, 2005 the PerlUnit Development Team (see the Test::Unit manpage or the AUTHORS file included in this distribution).
All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Test::Unit::Assert - unit testing framework assertion class |