File: examples_test_warning_contents.t

package info (click to toggle)
libtest-warnings-perl 0.038-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 472 kB
  • sloc: perl: 375; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 764 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# generated from examples/test_warning_contents.t
use strict;
use warnings;

# this test demonstrates that warnings can be captured and tested, and other
# expected warnings can be whitelisted, to allow the had-no-warnings test not
# to fail

use Test::More tests => 2;
use Test::Warnings ':all';
use Test::Deep;

my @lines;
my @warnings = warnings {
    warn 'testing 1 2 3';   push @lines, __LINE__;
    warn 'another warning'; push @lines, __LINE__;
};

my $file = __FILE__;
cmp_deeply(
    \@warnings,
    [
        "testing 1 2 3 at $file line $lines[0].\n",
        "another warning at $file line $lines[1].\n",
    ],
    'successfully captured all warnings',
);

# make these warnings visible
allow_warnings;
warn $_ foreach @warnings;
allow_warnings(0);