Bug 40404: Remove diag from t/Test/Mock/Logger.t
t/Test/Mock/Logger.t .. 1/10 # trace:
# (No trace messages)
# debug:
# "Debug message" at /usr/share/perl/5.36/Test/Builder.pm line 374
# info:
# (No info messages)
# warn:
# (No warn messages)
# error:
# (No error messages)
# fatal:
# (No fatal messages)
t/Test/Mock/Logger.t .. ok
All tests successful.
Files=1, Tests=10, 0 wallclock secs ( 0.03 usr 0.00 sys + 0.40 cusr 0.07 csys = 0.50 CPU)
Result: PASS
This one is a bit tricky: we cannot use Test::Warn to capture the output because Test::Builder->diag does not write directly to STDERR.
It has its own failure_output handle (which defaults to STDERR) but bypasses Perl’s standard layers.
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 9d17ce951d)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
parent
c4f54429a7
commit
03beed51c5
|
|
@ -1,5 +1,6 @@
|
|||
use Modern::Perl;
|
||||
use Test::More tests => 10;
|
||||
use Test::More tests => 11;
|
||||
use Test::NoWarnings;
|
||||
use Test::Warn;
|
||||
|
||||
# Module under test
|
||||
|
|
@ -132,16 +133,25 @@ subtest 'Method chaining tests' => sub {
|
|||
isa_ok( $result, 't::lib::Mocks::Logger', 'Method chaining returns the logger object' );
|
||||
};
|
||||
|
||||
# Test diag method (output capture is complex, just verify it runs)
|
||||
subtest 'Diag method test' => sub {
|
||||
plan tests => 1;
|
||||
|
||||
$logger->clear();
|
||||
$mocked_logger->debug('Debug message');
|
||||
|
||||
# Just make sure it doesn't throw an exception
|
||||
eval { $logger->diag(); };
|
||||
is( $@, '', 'diag() method executed without errors' );
|
||||
# Capture Test::Builder diag output
|
||||
my $diag_output = '';
|
||||
open my $fake_fh, '>', \$diag_output or die "Can't open: $!";
|
||||
|
||||
my $tb = Test::More->builder;
|
||||
my $original_fh = $tb->failure_output;
|
||||
$tb->failure_output($fake_fh); # Redirect diag output
|
||||
|
||||
$logger->diag();
|
||||
|
||||
$tb->failure_output($original_fh);
|
||||
|
||||
like( $diag_output, qr/debug:\n#\s*"Debug message"/xms, 'Captured diag output' );
|
||||
};
|
||||
|
||||
# Test handling of empty log buffers
|
||||
|
|
|
|||
Loading…
Reference in New Issue