The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Stream::Hub - The conduit through which all events flow.

SYNOPSIS

    use Test::Stream;
    my $hub = Test::Stream->shared;
    $hub->send($event);

or

    use Test::Stream::Hub;
    my $hub = Test::Stream::Hub->new();
    $hub->send($event);

TOGGLES AND CONTROLS

$hub->use_fork

Turn on forking support (it cannot be turned off).

$hub->set_subtest_tap_instant($bool)
$bool = $hub->subtest_tap_instant

Render subtest events as they happen.

$hub->set_subtest_tap_delayed($bool)
$bool = $hub->subtest_tap_delayed

Render subtest events when printing the result of the subtest

$hub->set_exit_on_disruption($bool)
$bool = $hub->exit_on_disruption

When true, skip_all and bailout will call exit. When false the bailout and skip_all events will be thrown as exceptions.

$hub->set_use_tap($bool)
$bool = $hub->use_tap

Turn TAP rendering on or off.

$hub->set_use_legacy($bool)
$bool = $hub->use_legacy

Turn legacy result storing on and off.

$hub->set_use_numbers($bool)
$bool = $hub->use_numbers

Turn test numbers on and off.

$stash = $hub->subtest_start($name, %params)
$stash = $hub->subtest_stop($name)

These will push/pop new states and subtest stashes.

Using these directly is not recommended. Also see the wrapper methods in Test::Stream::Context.

SENDING EVENTS

    $hub->send($event)

The send() method is used to issue an event to the hub. This method will handle thread/fork sych, mungers, listeners, TAP output, etc.

ALTERING EVENTS

    $hub->munge(sub {
        my ($hub, $event) = @_;

        ... Modify the event object ...

        # return is ignored.
    });

Mungers can never be removed once added. The return from a munger is ignored. Any changes you wish to make to the object must be done directly by altering it in place. The munger is called before the event is rendered as TAP, and AFTER the event has made any necessary state changes.

LISTENING FOR EVENTS

    $hub->listen(sub {
        my ($hub, $event) = @_;

        ... do whatever you want with the event ...

        # return is ignored
    });

Listeners can never be removed once added. The return from a listener is ignored. Changing an event in a listener is not something you should ever do, though no protections are in place to prevent it (this may change!). The listeners are called AFTER the event has been rendered as TAP.

POST-TEST BEHAVIORS

    $hub->follow_up(sub {
        my ($context) = @_;

        ... do whatever you need to ...

        # Return is ignored
    });

follow_up subs are called only once, when the hub recieves a finish event. There are 2 ways a finish event can occur:

$hub->done_testing

A finish event is generated when you call done_testing. The finish event occurs before the plan is output.

EXIT MAGIC

A finish event is generated when the Test::Stream END block is called, just before cleanup. This event will not happen if it was already geenerated by a call to done_testing.

STATE METHODS

$hub->states

Get the states arrayref, which holds all the active state objects.

$hub->state

Get the current state. The state is an instance of Test::Stream::State which represents the state of the test run.

$hub->plan

Get the plan event, if a plan has been issued.

$hub->count

Get the test count so far.

$hub->failed

Get the number of failed tests so far.

$hub->ended

Get the context in which the tests ended, if they have ended.

$hub->legacy

Used internally to store events for legacy support.

$hub->is_passing

Check if the test is passing its plan.

$hub->fork_cull

Gather events from other threads/processes.

SOURCE

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

MAINTAINER

Chad Granum <exodist@cpan.org>

AUTHORS

The following people have all contributed to the Test-More dist (sorted using VIM's sort function).

Chad Granum <exodist@cpan.org>
Fergal Daly <fergal@esatclear.ie>>
Mark Fowler <mark@twoshortplanks.com>
Michael G Schwern <schwern@pobox.com>
唐鳳

COPYRIGHT

There has been a lot of code migration between modules, here are all the original copyrights together:

Test::Stream
Test::Stream::Tester

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://www.perl.com/perl/misc/Artistic.html

Test::Simple
Test::More
Test::Builder

Originally authored by Michael G Schwern <schwern@pobox.com> with much inspiration from Joshua Pritikin's Test module and lots of help from Barrie Slaymaker, Tony Bowden, blackstar.co.uk, chromatic, Fergal Daly and the perl-qa gang.

Idea by Tony Bowden and Paul Johnson, code by Michael G Schwern <schwern@pobox.com>, wardrobe by Calvin Klein.

Copyright 2001-2008 by Michael G Schwern <schwern@pobox.com>.

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

See http://www.perl.com/perl/misc/Artistic.html

Test::use::ok

To the extent possible under law, 唐鳳 has waived all copyright and related or neighboring rights to Test-use-ok.

This work is published from Taiwan.

http://creativecommons.org/publicdomain/zero/1.0

Test::Tester

This module is copyright 2005 Fergal Daly <fergal@esatclear.ie>, some parts are based on other people's work.

Under the same license as Perl itself

See http://www.perl.com/perl/misc/Artistic.html

Test::Builder::Tester

Copyright Mark Fowler <mark@twoshortplanks.com> 2002, 2004.

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