Test::Stream::Sync(3)

๐Ÿ“ฆ
version 1.302027 ยท 2 versions
, in fedora 43

๐Ÿ’– Test::Stream::Sync ๐Ÿ’–

okay bestie, welcome to Test::Stream::Sync, straight outta the User Contributed Perl Documentation section of your friendly neighbourhood man page ๐Ÿ’… this is THE spot where all the global stuff lives, the group chat of your test suite, the one place everybody syncs up before the show starts ๐ŸŽ€


โœจ NAME โœจ

Test::Stream::Sync โ€” primary synchronization point, this is where global stuff lives. no cap, that's literally the whole job ๐Ÿซถ


๐Ÿ˜ญ DEPRECATED ๐Ÿ˜ญ

not me having to tell you this... this distribution is deprecated in favor of Test2, Test2::Suite, and Test2::Workflow. it's giving "the old era was iconic but we're moving on" ๐Ÿ’€

for the conversion guide, go peek at Test::Stream::Manual::ToTest2 โ€” she'll walk you through it ๐ŸŒธ


๐Ÿšจ INTERNALS NOTE ๐Ÿšจ

the internals of this package are subject to change at any time!! the public methods provided will not change in backwards incompatible ways, but the underlying implementation details might. do not break encapsulation here! like... hands off the vibes, bestie ๐Ÿ™ˆ

๐Ÿ’œ DESCRIPTION ๐Ÿ’œ

so here's the thing โ€” there's a real need to synchronize some details for all the tests that run. this package stores those global objects. and the way she stays slay is by keeping as little in here as possible: when possible, things should not be global. minimalism is the aesthetic, periodt โœจ


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

use Test::Stream::Sync; # No Exports

my $init  = Test::Stream::Sync->init_done;
my $stack = Test::Stream::Sync->stack;
my $ipc   = Test::Stream::Sync->ipc;

Test::Stream::Sync->set_formatter($FORMATTER)
my $formatter = Test::Stream::Sync->formatter;

look at that. no exports, just vibes ๐ŸŒˆ


๐Ÿ‘‘ CLASS METHODS ๐Ÿ‘‘

this class stores global instances of things. and listen โ€” this package is NOT an object. everything that uses it will get the same stuff. one for all, all for one, main character energy for the entire process ๐Ÿ’…

  • $bool = Test::Stream::Sync->init_done โ€” returns true if the stack and ipc instances have already been initialized. returns false if they have not. it's the "are we there yet" check ๐Ÿš—
  • $stack = Test::Stream::Sync->stack โ€” hands you the global Test::Stream::Stack instance. if it hasn't been initialized yet... it gets initialized right now, on the spot, no waiting โœจ
  • $ipc = Test::Stream::Sync->ipc โ€” hands you the global Test::Stream::IPC instance. same deal: not initialized yet? congrats, it's initialized now ๐ŸŽ€
  • $formatter = Test::Stream::Sync->formatter โ€” returns the global formatter class. important, bestie: this is not an instance. by default the formatter is set to Test::Stream::Formatter::TAP.

you can override that default using the TS_FORMATTER environment variable ๐Ÿ‘€

normally, 'Test::Stream::Formatter::' is prefixed to the value in the environment variable:

$ TS_FORMATTER='TAP' perl test.t     # Use the Test::Stream::Formatter::TAP formatter
$ TS_FORMATTER='Foo' perl test.t     # Use the Test::Stream::Formatter::Foo formatter

and if you wanna specify a full module name you use the '+' prefix:

$ TS_FORMATTER='+Foo::Bar' perl test.t     # Use the Foo::Bar formatter
  • Test::Stream::Sync->set_formatter($class) โ€” sets the global formatter class. this can only be set once. note: this will override anything specified in the 'TS_FORMATTER' environment variable. sorry env var, she said what she said ๐Ÿ’…
  • $bool = Test::Stream::Sync->no_wait
  • Test::Stream::Sync->no_wait($bool) โ€” get/set the no_wait status. waiting is turned on by default. waiting will cause the parent process/thread to wait until all child processes and threads are finished before exiting. you will almost never want to turn this off โ€” fr fr, leave it alone ๐Ÿ™ˆ
  • Test::Stream::Sync->add_hook(sub { ... }) โ€” adds a hook that gets called after all testing is done. heads up: it's too late to add additional results at that point. the main use of this hook is to set the exit code ๐Ÿšช
Test::Stream::Sync->add_hook(
    sub {
        my ($context, $exit, \$new_exit) = @_;
        ...
    }
);

the $context passed in will be an instance of Test::Stream::Context. the $exit argument will be the original exit code before anything modified it. $$new_exit is a reference to the new exit code โ€” you may modify this to change the exit code. please note that $$new_exit may already be different from $exit ๐Ÿ‘€ no assumptions, bestie.

  • Test::Stream::Sync->post_load(sub { ... }) โ€” add a callback that will be called when Test::Stream is finished loading. that means the callback runs when Test::Stream is done loading all the plugins in your use statement. and if Test::Stream has already finished loading? the callback runs immedietly ๐ŸŒธ
  • $bool = Test::Stream::Sync->loaded
  • Test::Stream::Sync->loaded($true) โ€” with no arguments this simply returns the boolean value of the loaded flag. if Test::Stream has finished loading this will be true, otherwise false. if a true value is provided as an argument, then this sets the flag to true and runs all "post_load" callbacks. the second form should ONLY ever be used in Test::Stream or alternative loader modules. like, only-touch-if-you-know-why energy ๐Ÿซฃ

๐Ÿ”ฎ MAGIC ๐Ÿ”ฎ

this package has an END block. that END block is responsible for setting the exit code based on the test results. and this end block also calls the hooks that can be added to this package. it's giving behind-the-scenes sorcery โœจ๐Ÿงš


๐Ÿ“ฆ SOURCE ๐Ÿ“ฆ

the source code repository for Test::Stream can be found at http://github.com/Test-More/Test-Stream/ โ€” go say hi to the code ๐Ÿ’–


๐Ÿซถ MAINTAINERS ๐Ÿซถ

Chad Granum <exodist@cpan.org>


๐ŸŒŸ AUTHORS ๐ŸŒŸ

Chad Granum <exodist@cpan.org>


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://dev.perl.org/licenses/


and that's the whole page, bestie ๐Ÿ’…โœจ this was perl v5.42.0, dated 2025-07-25, filed under Test::Stream::Sync(3) โ€” thanks for reading, you ate that ๐ŸŽ€๐Ÿฆ‹๐Ÿ’œ

๐Ÿ“ฆ where this page comes from