Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
Test::Lazy(3)	      User Contributed Perl Documentation	 Test::Lazy(3)

NAME
       Test::Lazy - A quick and	easy way to compose and	run tests with useful
       output.

VERSION
       Version 0.061

SYNOPSIS
	       use Test::Lazy qw/check try/;

	   # Will evaluate the code and	check it:
	       try('qw/a/' => eq => 'a');
	       try('qw/a/' => ne => 'b');
	       try('qw/a/' => is => ['a']);

	   # Don't evaluate, but still compare:
	       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);

	   # A failure example:

	       check([qw/a b/] => is =>	[qw/a b	c/]);

	   # Failed test '['a','b'] is ['a','b','c']'
	   # Compared array length of $data
	   #	got : array with 2 element(s)
	   # expect : array with 3 element(s)

	   # Custom test explanation:

	       try('2 +	2' => '==' => 5, "Math is hard:	%?");

	   # Failed test 'Math is hard:	2 + 2 == 5'
	   #	  got: 4
	   # expected: 5

DESCRIPTION
       Ever get	tired of coming	up with	a witty	test message? Think that the
       best explanation	for a test is the code behind it? Test::Lazy is	for
       you.  Test::Lazy	will take a stringified	piece of code, evaluate	it,
       and use a comparator to match the result	to an expectation. If the test
       fails, then Test::Lazy will use the code	as the test explanation	so you
       can exactly what	went wrong.

       You can even put	in your	own amendment to Test::Lazy's response,	just
       use the '%?' marker in your explanation.

COMPARISON
       If <expect> is an ARRAY or HASH reference, then Test::Lazy will do a
       structure comparison, using cmp_structure as opposed to cmp_scalar.
       Generally, this means using Test::Deep to do the	comparison.

       For try or check, <compare> should be one of the	below:

   Scalar
	   ok: Test::More::ok

	   not_ok: ! Test::More::ok

	   < > <= >= lt	gt le ge == != eq ne: Test::More::cmp_ok

	   is isnt like	unlike:	Test::More::{is,isnt,like,unlike}

   Structural
	   ok: Test::More::ok

	   not_ok: ! Test::More::ok

	   bag same_bag	samebag: Test::Deep::cmp_bag

	   set same_set	sameset: Test::Deep::cmp_set

	   same	is like	eq ==: Test::Deep::cmp_deeply

	   isnt	unlink ne !=: Test::More::ok(!Test::Deep::eq_deeply)

EXPORTS
   check( <got>, <compare>, <expect>, [	<notice> ] )
       Compare <got> to	<expect> using <compare>.  Optionally provide a
       <notice>	to display on failure. If <notice> is not given, then one will
       be automatically	made from <got>, <compare>, and	<expect>.

       Note, if	<expect> is an ARRAY or	HASH, try will do structural
       comparison instead of scalar 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(	<statement>, <compare>,	<expect>, [ <notice> ] )
       Evaluate	<statement> and	compare	the result to <expect> using
       <compare>.  Optionally provide a	<notice> to display on failure.	If
       <notice>	is not given, then one will be automatically made from
       <statement>, <compare>, and <expect>.

       "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
       <expect>.  See `perldoc -m Test::Lazy` for more detail.

       Note, if	<expect> is an ARRAY or	HASH, try will do structural
       comparison instead of scalar 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.

METHODS
   Test::Lazy->singleton
       Access the underlying Test::Lazy::Tester	object to customize
       comparators or renderers.

	   Test::Lazy->singleton->cmp_scalar->{xyzzy} =	sub {
	       Test::More::cmp_ok($_[0]	=> eq => "xyzzy", $_[2]);
	   };

	   # ... meanwhile ...

	       check("xyzy" => "is_xyzzy");

	   # Failed test 'xyzy is_xyzzy'
	   #	  got: 'xyzy'
	   # expected: 'xyzzy'

       Returns a Test::Lazy::Tester object.

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:

       o   AnnoCPAN: Annotated CPAN documentation

	   <http://annocpan.org/dist/Test-Lazy>

       o   CPAN	Ratings

	   <http://cpanratings.perl.org/d/Test-Lazy>

       o   RT: CPAN's request tracker

	   <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Lazy>

       o   Search CPAN

	   <http://search.cpan.org/dist/Test-Lazy>

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.

perl v5.32.1			  2007-11-05			 Test::Lazy(3)

NAME | VERSION | SYNOPSIS | DESCRIPTION | COMPARISON | EXPORTS | METHODS | AUTHOR | BUGS | SUPPORT | ACKNOWLEDGEMENTS | COPYRIGHT & LICENSE

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=Test::Lazy&sektion=3&manpath=FreeBSD+13.0-RELEASE+and+Ports>

home | help