1use warnings;
2use strict;
3use Test::More;
4
5BEGIN {
6    $INC{'MyWarner.pm'} = 1;
7    package MyWarner;
8
9    sub import {
10        warnings::warnif('deprecated', "Deprecated! run for your lives!");
11    }
12}
13
14sub capture(&) {
15    my $warn;
16    local $SIG{__WARN__} = sub { $warn = shift };
17    $_[0]->();
18    return $warn || "";
19}
20
21{
22local $TODO = "known to fail on $]" if $] le "5.006002";
23my $file = __FILE__;
24my $line = __LINE__ + 4;
25like(
26    capture {
27        local $TODO; # localize $TODO to clear previous assignment, as following use_ok test is expected to pass
28        use_ok 'MyWarner';
29    },
30    qr/^Deprecated! run for your lives! at \Q$file\E line $line/,
31    "Got the warning"
32);
33}
34
35ok(!capture { no warnings 'deprecated'; use_ok 'MyWarner' }, "No warning");
36
37done_testing;
38