The Perl Advent Calendar needs more articles for 2022. Submit your idea today!

NAME

Test2::Tools::HarnessTester - Run events through a harness for a summary

DESCRIPTION

This tool allows you to process events through the Test2::Harness auditor. The main benefit here is to get a pass/fail result, as well as counts for assertions, failures, and errors.

SYNOPSIS

    use Test2::V0;
    use Test2::API qw/intercept/;
    use Test2::Tools::HarnessTester qw/summarize_events/;

    my $events = intercept {
        ok(1, "pass");
        ok(2, "pass gain");
        done_testing;
    };

    is(
        summarize_events($events),
        {
            # Each of these is the negation of the other, no need to check both
            pass       => 1,
            fail       => 0,

            # The plan facet, see Test2::EventFacet::Plan
            plan       => {count => 2},

            # Statistics
            assertions => 2,
            errors     => 0,
            failures   => 0,
        }
    );

EXPORTS

$summary = summarize_events($events)

This takes an arrayref of events, such as that produced by intercept {...} from Test2::API. The result is a hashref that summarizes the results of the events as processed by Test2::Harness, specifically the Test2::Harness::Auditor::Watcher module.

Fields in the summary hash:

pass => $BOOL
fail => $BOOL

These are negatives of eachother. These represent the pass/fail state after processing the events. When one is true the other should be false. These are normalized to 1 and 0.

plan => $HASHREF

If a plan was provided this will have the Test2::EventFacet::Plan facet, but as a hashref, not a blessed instance.

Note: This is reference to the original data, not a copy, if you modify it you will modify the event as well.

assertions => $INT

Count of assertions made.

errors => $INT

Count of errors seen.

failures => $INT

Count of failures seen.

$path = make_example_dir()

This will create a temporary directory with 't', 't2', and 'xt' subdirectories each of which will contain a single passing test.

This is re-exported from App::Yath::Tester.

SOURCE

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

MAINTAINERS

Chad Granum <exodist@cpan.org>

AUTHORS

Chad Granum <exodist@cpan.org>

COPYRIGHT

Copyright 2020 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/