Commit | Line | Data |
c0f08d2c |
1 | use strict; |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | chdir 'lib/deprecate' or die "Can't see lib/deprecate"; |
6 | @INC = qw(../../../lib |
7 | lib/perl/arch |
8 | lib/perl |
9 | lib/site/arch |
10 | lib/site |
11 | ); |
12 | } |
13 | use File::Copy (); |
14 | use File::Path (); |
15 | use Test::More tests => 10; |
16 | |
17 | my %libdir = ( |
18 | privlibexp => 'lib/perl', |
19 | sitelibexp => 'lib/site', |
20 | archlibexp => 'lib/perl/arch', |
21 | sitearchexp => 'lib/site/arch', |
22 | ); |
23 | |
24 | mkdir for 'lib', sort values %libdir; |
25 | |
26 | our %tests = ( |
27 | privlibexp => 1, |
28 | sitelibexp => 0, |
29 | archlibexp => 1, |
30 | sitearchexp => 0, |
31 | ); |
32 | |
33 | local %deprecate::Config = (%libdir); |
34 | |
35 | for my $lib (sort keys %tests) { |
36 | my $dir = $libdir{$lib}; |
37 | File::Copy::copy 'Deprecated.pm', "$dir/Deprecated.pm"; |
38 | |
39 | my $warn; |
40 | { local $SIG{__WARN__} = sub { $warn .= $_[0]; }; |
41 | use warnings qw(deprecated); |
42 | #line 1001 |
43 | require Deprecated; |
44 | #line |
45 | } |
46 | if( $tests{$lib} ) { |
47 | like($warn, qr/^Deprecated\s+will\s+be\s+removed\b/, "$lib - message"); |
48 | like($warn, qr/$0,?\s+line\s+1001\.?\n*$/, "$lib - location"); |
49 | } |
50 | else { |
51 | ok( !$warn, "$lib - no message" ); |
52 | } |
53 | |
54 | delete $INC{'Deprecated.pm'}; |
55 | unlink "$dir/Deprecated.pm"; |
56 | } |
57 | |
58 | for my $lib (sort keys %tests) { |
59 | my $dir = $libdir{$lib}; |
60 | mkdir "$dir/Optionally"; |
61 | File::Copy::copy 'Optionally.pm', "$dir/Optionally/Deprecated.pm"; |
62 | |
63 | my $warn; |
64 | { local $SIG{__WARN__} = sub { $warn .= $_[0]; }; |
65 | use warnings qw(deprecated); |
66 | require Optionally::Deprecated; |
67 | } |
68 | if( $tests{$lib} ) { |
69 | like($warn, qr/^Optionally::Deprecated\s+will\s+be\s+removed\b/, |
70 | "$lib - use if - message"); |
71 | } |
72 | else { |
73 | ok( !$warn, "$lib - use if - no message" ); |
74 | } |
75 | |
76 | delete $INC{'Optionally/Deprecated.pm'}; |
77 | unlink "$dir/Optionally/Deprecated.pm"; |
78 | } |
79 | # END { File::Path::rmtree 'lib' } |