Test2:...sTester(3pm)

πŸ’– Test2::Tools::HarnessTester β€” perl manual page, section 3pm πŸŽ€

okay bestie, this one's a 3pm page out of the User Contributed Perl Documentation, and it's genuinely so useful, come sit with me 🫢


✨ NAME ✨

Test2::Tools::HarnessTester β€” run events through a harness for a summary πŸ’…


🌸 DESCRIPTION 🌸

So this tool lets you process events through the Test2::Harness auditor. The whole point, the main character benefit, is that you get a pass/fail result, plus counts for assertions, failures, and errors. That's it, that's the vibe. ✨


πŸ¦‹ 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, like the one you get out of "intercept {...}" from Test2::API. What you get back is a hashref that summarizes the results of those events as processed by Test2::Harness, specifically the Test2::Harness::Auditor::Watcher module. no cap πŸ”₯

Fields in the summary hash:

  • pass => $BOOL
  • fail => $BOOL

These are negatives of eachother, fr fr. They're the pass/fail state after processing the events. When one is true the other should be false. They get 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. πŸ‘€ so like, be careful bestie, it's giving shared state.
  • 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. iconic tbh πŸŽ€

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/. go look, it's right there πŸ’–


⭐ MAINTAINERS ⭐

Chad Granum <exodist@cpan.org>


🌸 AUTHORS 🌸

Chad Granum <exodist@cpan.org>


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/


and that's the whole page, bestie 🫢 this lil doc shipped as perl v5.40.1, dated 2026-05-10 β€” periodt βœ¨πŸ’œ

πŸ“¦ where this page comes from