GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Test::Lazy(3) User Contributed Perl Documentation Test::Lazy(3)

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

Version 0.061

        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

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.

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:

    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}

    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)

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"]'

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'

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.

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.

Robert Krimen, "<rkrimen at cpan.org>"

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.

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

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

  • CPAN Ratings

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

  • RT: CPAN's request tracker

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

  • Search CPAN

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

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.

2007-11-05 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.