From eda06c3bbfedfbc84a9a4d0e82dcd0da2d0f1cb0 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 16 Jul 2025 11:08:13 +0200 Subject: [PATCH] Bug 40404: Remove diag from t/Test/Mock/Logger.t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- t/Test/Mock/Logger.t | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/t/Test/Mock/Logger.t b/t/Test/Mock/Logger.t index 1563205f8c8..015cdcae347 100755 --- a/t/Test/Mock/Logger.t +++ b/t/Test/Mock/Logger.t @@ -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 -- 2.34.1