warnings - How can I catch the output from a carp in Perl? -


I am writing a Pearl module, and I am using carp so that non-fatal warning is returned to the calling program Could be brought. The carp's warning works fine - I'm checking that the input parameter matches a certain position - if it does not meet the condition, then a warning is sent with the carp, and the module instead of the default for the parameter Keeping the use of the calling program is the only warning that the default parameter is being used instead of passing in the parameter.

My problem with my test script is sending my test script module into bad parameters, and I am trying to capture the warning message that comes back and make sure I get the right warning Found messages.

My module looks something like this:

  else {carp "value should be numeric - using default value"; }  

and my test script looks like this:

  eval {#call my module}; Like ($ @, qr / value should be numeric, "non-numeric value should be aborted");  

When I run the trial, I can see the warning on the screen (it should go to STDERR), but $ @ variable's content '' - is empty.

Here is the output from my test script:

  t / 04bad_method_calls .... ok 10 / 12value should be numeric - using default value ... #failed The test should be stopped on line 'non-numeric value' # t / 04bad_method_calls.t 98. T / 04bad_method_calls .... NOK 12 # '' do not match '(? -xism: value should be numeric)' # If you change the carp in a hoarse, then my test script works - It captures the error message (but I only want to warn).  

Honestly, I do not have the best understanding of eval - perhaps it's not the best way to catch warning production from carp. I tried to use the $ SIG { warning }, but it was also empty.

Is there a way to capture output from the carp? This is not the biggest deal because it is only in my examination script, but I still like to work my test script properly.

Thanks in advance!

From this page, it seems that you have local $ SIG {__WARN __} to set the substrate in the warning that alerts the warning to fatal errors for their test scripts, giving examples:

  local $ SIG {__WARN__} = sub $ {$ die _ [0]}; Aval $ Copper;  

Comments