in reply to STDERR in Test Results

I am getting an expected error

Why not test for it in that case? Pick one of Test::Warnings, Test::Warn, Test::Trap, etc.


🦛

Replies are listed 'Best First'.
Re^2: STDERR in Test Results
by Bod (Parson) on Jun 18, 2023 at 20:45 UTC
    Why not test for it in that case?

    Simply because I didn't know about those Test modules...

      In that case may I suggest starting with Test::Warn? I find it the simplest of the three (and these are not the only three of course) as it has a very logically straightforward approach. Simply:

      use strict; use warnings; use Test::More tests => 1; use Test::Warn; # Your code which gives an expected warning sub foo { warn "Stripe Webhook Error: Invalid Stripe Signature\n"; } # Test your code warning_is { foo (); } "Stripe Webhook Error: Invalid Stripe Signature +\n", 'Invalid sig warning issued';

      Task::Kensho recommends Test::Warnings which is fine but a little more abstract. Both modules are widely used in other dists. I have found Test::Trap useful on occasion but it can take a bit of wrangling to set up properly.


      🦛

        In that case may I suggest starting with Test::Warn?

        I am now getting quite a few fails which are caused by the tester not having Test::Warn installed and it not being a required dependency.

        Is it not bad practice to force the user to install a module just for the tests?

        Thanks for that...Test::Warn looks like just what I need.

        Except I cannot get it to work :(

        Could it be because I am generating the warnings by printing directly to STDERR like so:

        STDERR->print("Stripe Webhook Warning: $message\n");