File: 09-warnings-contents.t

package info (click to toggle)
libtest-warnings-perl 0.016-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 352 kB
  • ctags: 8
  • sloc: perl: 339; makefile: 2
file content (89 lines) | stat: -rw-r--r-- 1,968 bytes parent folder | download
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use strict;
use warnings FATAL => 'all';

use Test::More 0.88;
use Test::Warnings ':all';

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

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

    my $warning = warning {
        warn 'testing 1 2 3';   push @lines, __LINE__;
    };
    is(
        $warning,
        "testing 1 2 3 at $file line $lines[1].\n",
        'warning() successfully the warning as a string',
    );
}

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

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

    my $warning = warning {
        warn 'testing 1 2 3';   push @lines, __LINE__;
        warn 'another warning'; push @lines, __LINE__;
    };
    is_deeply(
        $warning,
        [
            "testing 1 2 3 at $file line $lines[2].\n",
            "another warning at $file line $lines[3].\n",
        ],
        'warning() successfully captured all warnings as a scalar ref',
    );
}

{
    my @warnings = warnings {
        note 'no warning here';
        note 'nor here';
    };

    is_deeply(
        \@warnings,
        [ ],
        'warnings() successfully captured all warnings (none!)',
    );

    my $warning = warning {
        note 'no warning here';
        note 'nor here';
    };

    is_deeply(
        $warning,
        [ ],
        'warning() successfully captured all warnings (none!)',
    );

    is(@$warning, 0, 'warning() reports zero warnings caught');
}

done_testing;