in reply to Re^3: STDERR in Test Results
in thread STDERR in Test Results

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");

Replies are listed 'Best First'.
Re^5: STDERR in Test Results
by hippo (Archbishop) on Jun 19, 2023 at 15:43 UTC
    Could it be because I am generating the warnings by printing directly to STDERR

    Yes:

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

    So don't do that. :-)


    🦛

      I came across this very interesting thread which reminded me why I didn't use warn - I don't want line numbers in the warnings from the module!

      using warn instead or print STDERR?

      The module does have the option to suppress or override warnings. I could use that but wanted to include the error situations in the tests.

        I don't want line numbers in the warnings from the module

        All you need to do is append a newline:

        #!/usr/bin/env perl use strict; use warnings; warn "foo"; warn "bar\n";
        $ perl warns.pl foo at warns.pl line 5. bar $

        🦛

      So don't do that. :-)

      Too late...

      I've just sent the latest version off to CPAN to try to deal with the perplexing issue of Test failing during CPAN Testing, which is more urgent than suppressing output to STDERR. That will nave to wait for the next release!