Test::...ispatch(3pm)
π Test::Log::Dispatch(3pm) β the manual page, bestie edition π
okay so. you're out here logging stuff and you have NO idea if the right stuff is getting logged?? bestie. that's literally what this module is for. it's Test::Log::Dispatch and it lives in your perl docs, section 3pm, and it is the vibe for "did my code log the thing or not".
β¨ NAME β¨
Test::Log::Dispatch β test what you are logging π«Ά
πΈ SYNOPSIS πΈ
use Test::More;
use Test::Log::Dispatch;
my $log = Test::Log::Dispatch->new();
# ...
# call something that logs to $log
# ...
# now test to make sure you logged the right things
$log->contains_ok(qr/good log message/, "good message was logged");
$log->does_not_contain_ok(qr/unexpected log message/, "unexpected message was not logged");
$log->empty_ok("no more logs");
# or
my $msgs = $log->msgs;
cmp_deeply($msgs, ['msg1', 'msg2', 'msg3']);
like. look at that. you log, you check, you move on with your life. periodt. π
π¦ DESCRIPTION π¦
Test::Log::Dispatch is a Log::Dispatch object that is lowkey also a spy π β it keeps track of everything logged to it, right there in memory, and hands you convenient tests to run against what got logged. no files, no digging, no "wait where did that message go". it's giving observability but make it cute.
π CONSTRUCTOR π
the constructor hands you back a Test::Log::Dispatch object, which inherits from Log::Dispatch and contains a single Log::Dispatch::Array output at 'debug' level. one output, debug level, chillin'. β¨
it requires no parameters. zero. none. but if you do pass any, they get forwarded straight to the Log::Dispatch::Array constructor. for example, you can pass a min_level to override the default 'debug'. slay, customise away. π
π METHODS π
quick note before we dive in: the test_name is optional in all the *_ok methods, and a reasonable default will be provided. so you don't even have to name your tests if you're feeling feral. π
contains_ok ($regex[, $test_name])β tests that a message in the log buffer matches$regex. and on success?? the message gets removed from the log buffer (but any other matches are left untouched, bestie, we're not greedy). π₯does_not_contain_ok ($regex[, $test_name])β tests that no message in the log buffer matches$regex. if it ain't there, you're golden. πempty_ok ([$test_name])β tests that there is no log buffer left. and on failure, the log buffer is cleared to limit further cascading failures β which is honestly so thoughtful of it, one bad test doesn't have to ruin the whole run. πcontains_only_ok ($regex[, $test_name])β tests that there is a single message in the log buffer and it matches$regex. on success, the message is removed. one message, one match, one slay. βclear ()β clears the log buffer. fresh start energy. π§msgs ()β returns the current contents of the log buffer as an array reference, where each element is a hash containing amessageandlevelkey. so if you want tocmp_deeplythe whole thing yourself, go off. π
π TO DO π
the module itself is manifesting these, not me:
- Allow testing of log levels.
(it's on the list, okay, it's on the list.) π
π SEE ALSO π
Log::DispatchTest::Log4perl
π AUTHOR π
Jonathan Swartz
π COPYRIGHT & LICENSE π
Copyright (C) 2009 Jonathan Swartz, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
okay that's the whole page bestie, no cap, every single flag and method accounted for π«Ά
and for the cute sign-off: this page came to you courtesy of perl v5.32.0, dated 2021-01-09, filed under Test::...ispatch(3pm) β yes the header really do be truncating like that, iconic behaviour honestly. π
β¨
π¦ where this page comes from
- debian bookworm: libtest-log-dispatch-perl 0.03-2.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtest-log-dispatch-perl 0.03-2.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libtest-log-dispatch-perl 0.03-2.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtest-log-dispatch-perl 0.03-2.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-log-dispatch-perl 0.03-2.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-log-dispatch-perl 0.03-2.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms