[sf-perl] conditional "no warnings 'threads'"

David Christensen dpchrist at holgerdanske.com
Sun Aug 2 16:40:14 PDT 2020


On 2020-08-02 09:24, yary wrote:

> This is reminding me of modules to help test warnings, looks like
> https://metacpan.org/pod/Test::Warnings is the one to use these days.
> 
> Wonder what is out there to ease the eval/die testing, maybe
> https://metacpan.org/pod/Test::Exception ?

Please "reply to list".


Yes, I tried both.  They do not seem to be designed for test scripts 
running in the main thread and the unit under test (UUT) running in a 
different thread.


I thought about moving the test scripts into the same thread as the UUT, 
or vice-versa.  Some test cases can be done entirely in the main thread, 
so I did that.  But other test cases are testing multi-threaded 
behavior, so I needed new ideas.


threads::error() provides the child exception message to the test 
script, so I could test my UUT exceptions.  But, the exception messages 
were leaking to the console.  The conditional "no warnings 'threads'" 
was a hack to stop the leaks.  The subsequent eval-apply idea is better. 
  (It should probably be called "eval-catch".)


For warnings, I implemented a shim function.  threads::create() calls 
the shim.  The shim installs a $SIG{__WARN__} handler and calls the 
child entry function.  The handler saves any child warning messages into 
a shared variable.  The test script examines the shared variable.


I am now adding the eval-catch idea to the shim.  I also plan to change 
the shim from fixed handlers and shared variables to callbacks.


David


More information about the SanFrancisco-pm mailing list