Test::FailWarnings(3) User Contributed Perl Documentation Test::FailWarnings(3)

# [SYNOPSIS](#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](#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.

Just as with Test::NoWarnings, this does not catch warnings if other things localize $SIG{\_\_WARN\_\_}, as this is designed to catch *unhandled* warnings.

# [USAGE](#USAGE)

## [Overriding $SIG{\_\_WARN\_\_}](#Overriding_$SIG__)

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](#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".

```
    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](#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. You can do that on the "use" line with "-allow\_from".

```
    use Test::FailWarnings -allow_from => [ qw/Annoying::Module/ ];
```

# [SEE ALSO](#SEE_ALSO)

2026-08-26 perl v5.44.0

---

Document: Test::FailWarnings(3pm) from perl-test-failwarnings 0.008-r2 (Chainguard OS)
Source: https://github.com/dagolden/Test-FailWarnings
