<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Test2::Manual::Tooling::TestBuilder;

our $VERSION = '0.000162';

1;

__END__

=head1 NAME

Test2::Manual::Tooling::TestBuilder - This section maps Test::Builder methods
to Test2 concepts.

=head1 DESCRIPTION

With Test::Builder tools were encouraged to use methods on the Test::Builder
singleton object. Test2 has a different approach, every tool should get a new
L&lt;Test2::API::Context&gt; object, and call methods on that. This document maps
several concepts from Test::Builder to Test2.

=head1 CONTEXT

First thing to do, stop using the Test::Builder singleton, in fact stop using
or even loading Test::Builder. Instead of Test::Builder each tool you write
should follow this template:

    use Test2::API qw/context/;

    sub my_tool {
        my $ctx  = context();

        ... do work ...

        $ctx-&gt;ok(1, "a passing assertion");

        $ctx-&gt;release;

        return $whatever;
    }

The original Test::Builder style was this:

    use Test::Builder;
    my $tb = Test::Builder-&gt;new; # gets the singleton

    sub my_tool {
        ... do work ...

        $tb-&gt;ok(1, "a passing assertion");

        return $whatever;
    }

=head1 TEST BUILDER METHODS

=over 4

=item $tb-&gt;BAIL_OUT($reason)

The context object has a 'bail' method:

    $ctx-&gt;bail($reason)

=item $tb-&gt;diag($string)

=item $tb-&gt;note($string)

The context object has diag and note methods:

    $ctx-&gt;diag($string);
    $ctx-&gt;note($string);

=item $tb-&gt;done_testing

The context object has a done_testing method:

    $ctx-&gt;done_testing;

Unlike the Test::Builder version, no arguments are allowed.

=item $tb-&gt;like

=item $tb-&gt;unlike

These are not part of context, instead look at L&lt;Test2::Compare&gt; and
L&lt;Test2::Tools::Compare&gt;.

=item $tb-&gt;ok($bool, $name)

    # Preferred
    $ctx-&gt;pass($name);
    $ctx-&gt;fail($name, @diag);

    # Discouraged, but supported:
    $ctx-&gt;ok($bool, $name, \@failure_diags)

=item $tb-&gt;subtest

use the C&lt;Test2::API::run_subtest()&gt; function instead. See L&lt;Test2::API&gt; for documentation.

=item $tb-&gt;todo_start

=item $tb-&gt;todo_end

See L&lt;Test2::Tools::Todo&gt; instead.

=item $tb-&gt;output, $tb-&gt;failure_output, and $tb-&gt;todo_output

These are handled via formatters now. See L&lt;Test2::Formatter&gt; and
L&lt;Test2::Formatter::TAP&gt;.

=back

=head1 LEVEL

L&lt;Test::Builder&gt; had the C&lt;$Test::Builder::Level&gt; variable that you could
modify in order to set the stack depth. This was useful if you needed to nest
tools and wanted to make sure your file and line number were correct. It was
also frustrating and prone to errors. Some people never even discovered the
level variable and always had incorrect line numbers when their tools would
fail.

L&lt;Test2&gt; uses the context system, which solves the problem a better way. The
top-most tool get a context, and holds on to it until it is done. Any tool
nested under the first will find and use the original context instead of
generating a new one. This means the level problem is solved for free, no
variables to mess with.

L&lt;Test2&gt; is also smart enough to honor C&lt;$Test::Builder::Level&gt; if it is set.

=head1 TODO

L&lt;Test::Builder&gt; used the C&lt;$TODO&gt; package variable to set the TODO state. This
was confusing, and easy to get wrong. See L&lt;Test2::Tools::Todo&gt; for the modern
way to accomplish a TODO state.

=head1 SEE ALSO

L&lt;Test2::Manual&gt; - Primary index of the manual.

=head1 SOURCE

The source code repository for Test2-Manual can be found at
F&lt;https://github.com/Test-More/Test2-Suite/&gt;.

=head1 MAINTAINERS

=over 4

=item Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;

=back

=head1 AUTHORS

=over 4

=item Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;

=back

=head1 COPYRIGHT

Copyright 2018 Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;.

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

See F&lt;http://dev.perl.org/licenses/&gt;

=cut
</pre></body></html>