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
# more code here ...
# or, for regular expression comparisons:
# or, for functional style coderef tests:
$_ == $_
or $self->fail("Expected $_, got $_");
}, 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_not_equals('not expected', $actual [, $optional_message]);
# Or, if you want to force the comparator
# assert defined/undefined status
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.
The catch all assertions of (in)equality. We make a guess about whether to test for numeric or string (in)equality based on the first argument. If it looks like a number then we do a numeric test, if it looks like a string, we do a string test.
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.
Force numeric comparison with these two.
Force string comparison
Assert that STRING does or does not match the PATTERN regex.
Assert that reference A is a deep copy of reference B. The references can be complex, deep structures. If they are different, the default message will display the place where they start differing.
NOTE This is NOT well-tested on circular references. Nor am I quite sure what will happen with filehandles.
Assert that ARG is defined or not defined.
Checks if the BOOLEAN expression returns a true value that is neither a CODE ref nor a REGEXP. Note that MESSAGE is almost non optional in this case, otherwise all the assertion has to go on is the truth or otherwise of the boolean.
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.
Matches ACTUAL against the PATTERN regex. If you omit MESSAGE, you should get a sensible error message.
Calls CODEREF->(@ARGS). Assertion fails if this returns false (or throws Test::Unit::Failure)
Calls CODEREF->(). Assertion fails unless an exception of class EXCEPTION_CLASS is raised.
Calls $self->assert(ASSERTION, @$ARGSET) for each $ARGSET in @ARGSETS.
Simulates the behaviour of the Test module. Deprecated.
Copyright (c) 2000-2002, 2005 the PerlUnit Development Team (see Test::Unit 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.
The framework self-testing suite (t::tlib::AllTests)
To install Test::Unit, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.