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->enable_concurrency()
- $hub->enable_concurrency(wait => $bool, join => $bool, driver => $driver, fallback => $driver)
-
Turns forking support on. This turns on a synchronization method that *just works* when you fork inside a test. This must be turned on prior to any forking.
Normally Test::Stream will wait on all child processes and join all remaining threads before ending the parent process/thread. You can disable these behaviors by setting
wait
and/or c<join> to false. The default for these is true.If you wish to use a specific concurrency driver module you may specify it with the c<driver> key. You may also specify 1 or more fallback drivers using the
fallback
key, which may be specified multiple times.If no driver is specified the default is Test::Stream::Concurrency::Files, but this can change at any time in the future, so if you care you should specify one.
If no fallback is specified the default is Test::Stream::Concurrency::Files, but this can change at any time in the future, so if you care you should specify one.
- $hub->subtest_buffering($bool)
- $bool = $hub->subtest_buffering()
-
When true, subtest results are buffered until the subtest is complete, then all subtest results are rendered at once.
- $hub->subtest_spec($spec)
- $spec = $hub->subtest_spec()
-
Can be set to
legacy
,block
.The 'legacy' spec is the default, it uses indentation for subtest results:
ok 1 - a result # Starting subtest X ok 1 - subtest X result 1 ok 2 - subtest X result 2 1..2 ok 2 - subtest X final result
The 'block' spec forces buffering, it wraps results in a block:
ok 1 - a result ok 2 - subtest X final result { ok 1 - subtest X result 1 ok 2 - subtest X result 2 1..2 # }
- $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.
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.
OTHER METHODS
- $hub->ipc_cull
-
Gather events from other threads/processes.
- $d = $sub->concurrency_driver()
-
Get the instance of the concurrency driver, if concurrency is enabled.
SOURCE
The source code repository for Test::More can be found at http://github.com/Test-More/test-more/.
MAINTAINER
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.
- 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.