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


Manual Reference Pages  -  TEST2::TOOLS::BASIC (3)

.ds Aq ’

NAME

Test2::Tools::Basic - Test2 implementation of the basic testing tools.

CONTENTS

DESCRIPTION

This is an Test2 based implementation of the more basic tools originally provided by Test::More. Not all Test::More tools are provided by this package, only the basic/simple ones. Some tools have been modified for better diagnistics capabilities.

SYNOPSIS



    use Test2::Tools::Basic;

    ok($x, "simple test");

    if ($passing) {
        pass(a passing test);
    }
    else {
        fail(a failing test);
    }

    diag "This is a diagnostics message on STDERR";
    note "This is a diagnostics message on STDOUT";

    {
        my $todo = todo "Reason for todo";
        ok(0, "this test is todo");
    }

    ok(1, "this test is not todo");

    todo "reason" => sub {
        ok(0, "this test is todo");
    };

    ok(1, "this test is not todo");

    SKIP: {
        skip "This will wipe your drive";

        # This never gets run:
        ok(!system(sudo rm -rf /), "Wipe drive");
    }

    done_testing;



EXPORTS

All subs are exported by default.

    PLANNING

plan($num) Set the number of tests that are expected. This must be done first or last, never in the middle of testing.
skip_all($reason) Set the plan to 0 with a reason, then exit true. This should be used before any tests are run.
done_testing Used to mark the end of testing. This is a safe way to have a dynamic or unknown number of tests.
bail_out($reason) Something has gone horribly wrong, stop everything, kill all threads and processes, end the process with a false exit status.

    ASSERTIONS

ok($bool)
ok($bool, $name)
ok($bool, $name, @diag) Simple assertion. If $bool is true the test passes, if it is false the test fails. The test name is optional, and all arguments after the name are added as diagnostics message if and only if the test fails. If the test passes all the diagnostics arguments will be ignored.
pass()
pass($name) Fire off a passing test (a single Ok event). The name is optional
fail()
fail($name)
fail($name, @diag) Fire off a failing test (a single Ok event). The name and diagnostics are optional.

    DIAGNOSTICS

diag(@messages) Write diagnostics messages. All items in @messages will be joined into a single string with no seperator. When using TAP diagnostics are sent to STDERR.
note(@messages) Write note-diagnostics messages. All items in @messages will be joined into a single string with no seperator. When using TAP note-diagnostics are sent to STDOUT.

    META

$todo = todo($reason)
todo $reason => sub { ... } This is used to mark some results as TODO. TODO means that the test may fail, but will not cause the overall test suite to fail.

There are 2 ways to use this, the first is to use a codeblock, the TODO will only apply to the codeblock.



    ok(1, "before"); # Not TODO

    todo this will fail => sub {
        # This is TODO, as is any other test in this block.
        ok(0, "blah");
    };

    ok(1, "after"); # Not TODO



The other way is to use a scoped variable, TODO will end when the variable is destroyed or set to undef.



    ok(1, "before"); # Not TODO

    {
        my $todo = todo this will fail;

        # This is TODO, as is any other test in this block.
        ok(0, "blah");
    };

    ok(1, "after"); # Not TODO



This is the same thing, but without the {...} scope.



    ok(1, "before"); # Not TODO

    my $todo = todo this will fail;

    ok(0, "blah"); # TODO

    $todo = undef;

    ok(1, "after"); # Not TODO



skip($why)
skip($why, $count) This is used to skip some tests. This requires you to wrap your tests in a block labeled SKIP:, this is somewhat magical. If no $count is specified then it will issue a single result. If you specify $count it will issue that many results.



    SKIP: {
        skip "This will wipe your drive";

        # This never gets run:
        ok(!system(sudo rm -rf /), "Wipe drive");
    }



SOURCE

The source code repository for Test2-Suite can be found at http://github.com/Test-More/Test2-Suite/.

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

Copyright 2015 Chad Granum <exodist7@gmail.com>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://dev.perl.org/licenses/

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


perl v5.20.3 TEST2::TOOLS::BASIC (3) 2016-03-20

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