From 18d1d4fea34619d92a9b7812527494d655bbe833 Mon Sep 17 00:00:00 2001 From: bernhard Date: Tue, 30 Jun 2020 17:42:26 +0200 Subject: [PATCH] Issue #87: make the END block a closure Less action at a distance. --- Kernel/System/UnitTest/RegisterDriver.pm | 36 ++++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Kernel/System/UnitTest/RegisterDriver.pm b/Kernel/System/UnitTest/RegisterDriver.pm index d1bf3b6727..50c4bf27cd 100644 --- a/Kernel/System/UnitTest/RegisterDriver.pm +++ b/Kernel/System/UnitTest/RegisterDriver.pm @@ -40,13 +40,8 @@ use warnings; # OTOBO modules use Kernel::System::ObjectManager; -my $OriginalPID; # see the END block - sub import { - # remember the id of the process that loaded this module. - $OriginalPID = $$; - # RegisterDriver is meant for test scripts, # meaning that each sript has it's own process. # This means that we don't have to localize $Kernel::OM. @@ -72,19 +67,24 @@ sub import { return; } -END { - # Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker, and maybe other modules, is forking processes. - # But we want no cleanup in the child processes. - if ( $$ == $OriginalPID ) { - # trigger Kernel::System::UnitTest::Helper::DESTROY() - # perform cleanup actions, including some tests, in Kernel::System::UnitTest::Helper::DESTROY - $Kernel::OM->ObjectsDiscard( - Objects => ['Kernel::System::UnitTest::Helper'], - ); - - # print the plan - my $Driver = $Kernel::OM->Get( 'Kernel::System::UnitTest::Driver' ); - $Driver->DoneTesting(); +{ + # remember the id of the process that loaded this module. + my $OriginalPID = $$; + + END { + # Kernel::System::Daemon::DaemonModules::SchedulerTaskWorker, and maybe other modules, is forking processes. + # But we want no cleanup in the child processes. + if ( $$ == $OriginalPID ) { + # trigger Kernel::System::UnitTest::Helper::DESTROY() + # perform cleanup actions, including some tests, in Kernel::System::UnitTest::Helper::DESTROY + $Kernel::OM->ObjectsDiscard( + Objects => ['Kernel::System::UnitTest::Helper'], + ); + + # print the test plan + my $Driver = $Kernel::OM->Get( 'Kernel::System::UnitTest::Driver' ); + $Driver->DoneTesting(); + } } }