NAME
Test::Lazy - A quick and easy way to compose and run tests with useful output.
VERSION
Version 0.050_1
SYNOPSIS
use Test::Lazy qw/check try/;
check(1 => is => 1);
check(0 => isnt => 1);
check(a => like => qr/[a-zA-Z]/);
check(0 => unlike => qr/a-zA-Z]/);
check(1 => '>' => 0);
check(0 => '<' => 1);
try('qw/a/' => eq => 'a');
try('qw/a/' => ne => 'b');
try('qw/a/' => is => ['a']);
EXPORTS
check( <got>, <cmpr>, <expected>, [ <msg> ] )
Compare <got> to <expected> using <cmpr>. Optionally provide a <msg> to display on failure. If <msg> is not given, then one will be automatically made from <got>, <cmpr>, and <expected>.
Note, if <got> or <expected> is an ARRAY or HASH, this function will convert them to their JSON representation before comparison.
check([qw/a b/] => is => [qw/a b c/]);
# This will produce the following output:
# Failed test '["a","b"] is ["a","b","c"]'
# at __FILE__ line __LINE__.
# got: '["a","b"]'
# expected: '["a","b","c"]'
try( <stmt>, <cmpr>, <expected>, [ <msg> ] )
Evaluate <stmt> and compare the result to <expected> using <cmpr>. Optionally provide a <msg> to display on failure. If <msg> is not given, then one will be automatically made from <stmt>, <cmpr>, and <expected>.
try
will also try to guess what representation is best for the result of the statement, whether that be single value, ARRAY, or HASH. It'll do this based on what is returned by the statement, and the type of <expected>. See `perldoc -m Test::Lazy` for more detail.
Note, if <expected> is an ARRAY or HASH, this function will convert it to it's JSON representation before comparison.
try("2 + 2" => '==' => 5);
# This will produce the following output:
# Failed test '2 + 2 == 5'
# at __FILE__ line __LINE__.
# got: '4'
# expected: '5'
template( ... )
Convenience function for creating a Test::Lazy::Template
. All arguments are directly passed to Test::Lazy::Template-
new>.
See Test::Lazy::Template
for more details.
Returns a new Test::Lazy::Template
object.
- try( <stmt>, <cmpr>, <expected>, [ <msg> ] )
-
Evaluate <stmt> and compare the result to <expected> using <cmpr>. Optionally provide a <msg> to display on failure. If <msg> is not given, then one will be automatically made from <stmt>, <cmpr>, and <expected>.
try
will also try to guess what representation is best for the result of the statement, whether that be single value, ARRAY, or HASH. It'll do this based on what is returned by the statement, and the type of <expected>. See `perldoc -m Test::Lazy` for more detail.Note, if <expected> is an ARRAY or HASH, this function will convert it to it's JSON representation before comparison.
try("2 + 2" => '==' => 5); # This will produce the following output: # Failed test '2 + 2 == 5' # at __FILE__ line __LINE__. # got: '4' # expected: '5'
- check( <got>, <cmpr>, <expected>, [ <msg> ] )
-
Compare <got> to <expected> using <cmpr>. Optionally provide a <msg> to display on failure. If <msg> is not given, then one will be automatically made from <got>, <cmpr>, and <expected>.
Note, if <got> or <expected> is an ARRAY or HASH, this function will convert them to their JSON representation before comparison.
check([qw/a b/] => is => [qw/a b c/]); # This will produce the following output: # Failed test '["a","b"] is ["a","b","c"]' # at __FILE__ line __LINE__. # got: '["a","b"]' # expected: '["a","b","c"]'
- template( ... )
-
Convenience function for creating a
Test::Lazy::Template
. All arguments are directly passed toTest::Lazy::Template-
new>.See
Test::Lazy::Template
for more details.Returns a new
Test::Lazy::Template
object.
cmpr
<cmpr> can be one of the following:
ok, not_ok, is, isnt, like, unlike,
<, >, <=, >=, lt, gt, le, ge, ==, !=, eq, ne,
AUTHOR
Robert Krimen, <rkrimen at cpan.org>
BUGS
Please report any bugs or feature requests to bug-test-lazy at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Lazy. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Test::Lazy
You can also look for information at:
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
RT: CPAN's request tracker
Search CPAN
ACKNOWLEDGEMENTS
COPYRIGHT & LICENSE
Copyright 2007 Robert Krimen, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.