Blame xt/author/examples_test_warning_contents.t

Packit e94139
# generated from examples/test_warning_contents.t
Packit e94139
use strict;
Packit e94139
use warnings;
Packit e94139
Packit e94139
# this test demonstrates that warnings can be captured and tested, and other
Packit e94139
# expected warnings can be whitelisted, to allow the had-no-warnings test not
Packit e94139
# to fail
Packit e94139
Packit e94139
use Test::More tests => 2;
Packit e94139
use Test::Warnings ':all';
Packit e94139
use Test::Deep;
Packit e94139
Packit e94139
my @lines;
Packit e94139
my @warnings = warnings {
Packit e94139
    warn 'testing 1 2 3';   push @lines, __LINE__;
Packit e94139
    warn 'another warning'; push @lines, __LINE__;
Packit e94139
};
Packit e94139
Packit e94139
my $file = __FILE__;
Packit e94139
cmp_deeply(
Packit e94139
    \@warnings,
Packit e94139
    [
Packit e94139
        "testing 1 2 3 at $file line $lines[0].\n",
Packit e94139
        "another warning at $file line $lines[1].\n",
Packit e94139
    ],
Packit e94139
    'successfully captured all warnings',
Packit e94139
);
Packit e94139
Packit e94139
# make these warnings visible
Packit e94139
allow_warnings;
Packit e94139
warn $_ foreach @warnings;
Packit e94139
allow_warnings(0);
Packit e94139