NAME

TB2::Module - Write a test module

SYNOPSIS

use TB2::Module;
our @EXPORT = qw(is);

# is( $have, $want, $name );
install_test( is => sub ($$;$) {
    my($have, $want, $name) = @_;

    my $result = Builder->ok($have eq $want, $name);
    $result->diag([
        have => $have,
        want => $want
    ]);

    return $result;
});

DESCRIPTION

A module to declare test functions to make writing a test library easier.

FUNCTIONS

install_test

install_test( $name => $code );

Declares a new test function (aka an "assert") or method. Similar to writing sub name { ... } with two differences.

1. Declaring the test in this manner enables the assert_start and assert_end hooks, such as aborting the test on failure. 2. It takes care of displaying the test result for you. 3. The Builder object is available inside your $code which is just a shortcut for Test::Builder2->default.

The prototype of the $code is honored.

$code must return a single TB2::Result::Base object, usually the result from Test::Builder2->ok() or any other test function.