From df089e827cb48d64099b75e08acd5a2a7bbeb7e4 Mon Sep 17 00:00:00 2001 From: Chad Granum Date: Tue, 17 Jul 2018 12:35:53 -0700 Subject: [PATCH] Mask warning from IPC init block. The init block was added to help solve some problems when using IPC. It is not critical that it run, specially when someone does something clever, which is the usual cause of the warning. See https://rt.perl.org/Ticket/Display.html?id=133382 --- Changes | 2 ++ lib/Test2/IPC.pm | 9 ++++++++- t/Legacy_And_Test2/thread_init_warning.t | 22 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 t/Legacy_And_Test2/thread_init_warning.t diff --git a/Changes b/Changes index 3c2b4f1a2..71698bf53 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ {{$NEXT}} + - Mask warning from the recent IPC fix generated when threaded Test tools are loaded at run-time + 1.302138 2018-07-11 09:29:51-07:00 America/Los_Angeles - No changes since trial diff --git a/lib/Test2/IPC.pm b/lib/Test2/IPC.pm index eba789bb3..80e399d4e 100644 --- a/lib/Test2/IPC.pm +++ b/lib/Test2/IPC.pm @@ -19,7 +19,14 @@ use Test2::API qw{ }; # Make sure stuff is finalized before anyone tried to fork or start a new thread. -INIT { context()->release() } +{ + # Avoid warnings if things are loaded at run-time + no warnings 'void'; + INIT { + use warnings 'void'; + context()->release(); + } +} use Carp qw/confess/; diff --git a/t/Legacy_And_Test2/thread_init_warning.t b/t/Legacy_And_Test2/thread_init_warning.t new file mode 100644 index 000000000..23254c618 --- /dev/null +++ b/t/Legacy_And_Test2/thread_init_warning.t @@ -0,0 +1,22 @@ +use strict; +use warnings; + +use Test2::Util qw/CAN_THREAD/; +BEGIN { + unless(CAN_THREAD) { + require Test::More; + Test::More->import(skip_all => "threads are not supported"); + } +} + +use threads; + +my @warns; +{ + local $SIG{__WARN__} = sub { push @warns => @_ }; + require Test::More; +} + +Test::More::is_deeply(\@warns, [], "No init warning"); + +Test::More::done_testing();