File: 23-report-warnings.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-- 1,052 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;

my $has_test_tester;
BEGIN { $has_test_tester = eval { require Test::Tester; Test::Tester->VERSION(0.108); 1 } }

use Test::More 0.88;
plan skip_all => 'These tests require Test::Tester 0.108' if not $has_test_tester;
plan tests => 6;

use if "$]" >= '5.008', lib => 't/lib';
use if "$]" >= '5.008', 'SilenceStderr';

use Test::Warnings qw(had_no_warnings :report_warnings :no_end_test);
Test::Warnings::_builder(my $capture = Test::Tester::capture());

warn 'this is a warning 1 2 3'; my $line = __LINE__;

my (undef, @results) = Test::Tester::run_tests(sub { had_no_warnings; });

Test::Tester::cmp_results(
    [ $capture->details ],
    [
        {
            actual_ok => 0,
            ok => 0,
            name => 'no (unexpected) warnings',
            diag => "Got the following unexpected warnings:\n  1: this is a warning 1 2 3 at ".__FILE__." line $line.",
            depth => 1,
        },
    ],
    'with :report_warnings enabled, had_no_warnings() tells about warnings that we may not have seen before',
);