From 6840c41d0eab6d65b8e4faf5e17fa5389b4087bb Mon Sep 17 00:00:00 2001 From: Yasuharu Iida Date: Fri, 7 Feb 2025 12:26:00 +0900 Subject: [PATCH] test: surpress warning/warnings is called in void context --- t/modules/Plugin/SRand.t | 8 ++++---- t/modules/Tools/ClassicCompare.t | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/t/modules/Plugin/SRand.t b/t/modules/Plugin/SRand.t index 7856c09bd..857a3fa2e 100644 --- a/t/modules/Plugin/SRand.t +++ b/t/modules/Plugin/SRand.t @@ -85,16 +85,16 @@ sub intercept_2(&) { ); ok($CLASS->seed && $CLASS->seed != 1234, "set seed"); is($CLASS->from, 'local date', "set from"); - like($warning, $reseed_qr, $reseed_name); + $warning = like($warning, $reseed_qr, $reseed_name); my $hooks = Test2::API::test2_list_exit_callbacks(); delete $ENV{HARNESS_IS_VERBOSE}; $ENV{HARNESS_ACTIVE} = 1; - warning { $events = intercept { $CLASS->import() } }; - warning { $events = intercept { $CLASS->import() } }; + $warning = warning { $events = intercept { $CLASS->import() } }; + $warning = warning { $events = intercept { $CLASS->import() } }; is(Test2::API::test2_list_exit_callbacks, $hooks + 1, "added hook, but only once"); - warning { $CLASS->import(undef) }; + $warning = warning { $CLASS->import(undef) }; is($CLASS->seed, 0 , "set seed"); is($CLASS->from, 'import arg', "set from"); } diff --git a/t/modules/Tools/ClassicCompare.t b/t/modules/Tools/ClassicCompare.t index e221a8189..97bd09eb5 100644 --- a/t/modules/Tools/ClassicCompare.t +++ b/t/modules/Tools/ClassicCompare.t @@ -257,7 +257,7 @@ $line = __LINE__ + 2; like( intercept { local $ENV{TS_TERM_SIZE} = 10000; - main::warning { + $warning = main::warning { cmp_ok($foo, '&& die', $foo, 'overload exception', 'extra diag') } }, @@ -312,12 +312,13 @@ note "cmp_ok() displaying good numbers"; { } +my $warnings; note "cmp_ok() displaying bad numbers"; { my $have = "zero"; my $want = "3point5"; like( intercept { - warnings { cmp_ok($have, '>', $want) }; + $warnings = warnings { cmp_ok($have, '>', $want) }; }, array { fail_events Ok => sub {