Test::FailWarnings(3)

🌸 NAME 🌸

okay so, bestie, this is the manual page for Test::FailWarnings β€” yes, Test::FailWarnings(3), and it's a User Contributed Perl Documentation moment, iykyk. The whole point is Add test failures if warnings are caught. periodt.


πŸŽ€ VERSION πŸŽ€

version 0.008 β€” tiny number, big main-character energy.

✨ SYNOPSIS ✨

Test file:

use strict;
use warnings;
use Test::More;
use Test::FailWarnings;

ok( 1, "first test" );
ok( 1 + "lkadjaks", "add non-numeric" );

done_testing;

Output:

ok 1 - first test
not ok 2 - Test::FailWarnings should catch no warnings
#   Failed test 'Test::FailWarnings should catch no warnings'
#   at t/bin/main-warn.pl line 7.
# Warning was 'Argument "lkadjaks" isn't numeric in addition (+) at t/bin/main-warn.pl line 7.'
ok 3 - add non-numeric
1..3
# Looks like you failed 1 test of 3.

πŸ’– DESCRIPTION πŸ’–

This module hooks $SIG{__WARN__} and converts warnings to Test::More fail() calls. It is designed to be used with done_testing, when you don't need to know the test count in advance.

🫢 heads up bestie: just as with Test::NoWarnings, this does not catch warnings if other things localize $SIG{__WARN__}, as this is designed to catch unhandled warnings. no cap.

πŸ¦‹ USAGE πŸ¦‹

πŸ’… Overriding $SIG{__WARN__} πŸ’…

On import, $SIG{__WARN__} is replaced with Test::FailWarnings::handler.

use Test::FailWarnings;  # global

If you don't want global replacement, require the module instead and localize in whatever scope you want.

require Test::FailWarnings;

{
    local $SIG{__WARN__} = \&Test::FailWarnings::handler;
    # ... warnings will issue fail() here
}

When the handler reports on the source of the warning, it will look past any calling packages starting with Carp or warnings to try to detect the real origin of the warning.

πŸ“ Allowing warnings from dependencies πŸ“

If you want to ignore failures from outside your own code, you can set $Test::FailWarnings::ALLOW_DEPS to a true value. You can do that on the use line with -allow_deps.

  • -allow_deps β€” the use-line switch for setting $Test::FailWarnings::ALLOW_DEPS to a true value.
use Test::FailWarnings -allow_deps => 1;

When true, warnings will only be thrown if they appear to originate from a filename matching qr/^(?:t|xt|lib|blib)/.

🌈 Allowing warnings from specific modules 🌈

If you want to white-list specific modules only, you can add their package names to @Test::NoWarnings::ALLOW_FROM (yes, that exact array name β€” keep it exactly as written, bestie). You can do that on the use line with -allow_from.

  • -allow_from β€” the use-line switch for adding package names to @Test::NoWarnings::ALLOW_FROM.
use Test::FailWarnings -allow_from => [ qw/Annoying::Module/ ];

πŸ‘€ SEE ALSO πŸ‘€

  • Test::NoWarnings β€” catches warnings and reports in an END block. Not (yet) friendly with done_testing.
  • Test::Warnings β€” a replacement for Test::NoWarnings that works with done_testing
  • Test::Warn β€” test for warnings without triggering failures from this modules

🫢 SUPPORT 🫢

πŸ› Bugs / Feature Requests πŸ›

Please report any bugs or feature requests through the issue tracker at <https://github.com/dagolden/Test-FailWarnings/issues>. You will be notified automatically of any progress on your issue.

🧚 Source Code 🧚

This is open source software. The code repository is available for public review and contribution under the terms of the license.

<https://github.com/dagolden/Test-FailWarnings>

git clone https://github.com/dagolden/Test-FailWarnings.git

πŸ‘‘ AUTHOR πŸ‘‘

David Golden <dagolden@cpan.org>

This software is Copyright (c) 2013 by David Golden.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004

πŸ’– okay that's the whole page, bestie β€” footer vibe check: perl v5.42.0, date 2013-10-04, manual Test::FailWarnings(3). slay and goodbye πŸŽ€

πŸ“¦ where this page comes from