Commit | Line | Data |
---|---|---|
eaa79d3d | 1 | #!perl -w |
c0f08d2c RB |
2 | use strict; |
3 | ||
4 | BEGIN { | |
eaa79d3d | 5 | require './test.pl'; |
c0f08d2c RB |
6 | } |
7 | use File::Copy (); | |
8 | use File::Path (); | |
6b913759 | 9 | use File::Spec (); |
eaa79d3d | 10 | plan(tests => 10); |
c0f08d2c | 11 | |
6b913759 RB |
12 | my $test_dir = File::Spec->catdir(qw(lib deprecate)); |
13 | chdir $test_dir or die "Can't chdir $test_dir"; | |
14 | @INC = ( File::Spec->catdir( (File::Spec->updir)x3, qw(lib)) ); | |
15 | ||
c0f08d2c | 16 | my %libdir = ( |
6b913759 RB |
17 | privlibexp => File::Spec->catdir(qw(lib perl)), |
18 | sitelibexp => File::Spec->catdir(qw(lib site)), | |
19 | archlibexp => File::Spec->catdir(qw(lib perl arch)), | |
20 | sitearchexp => File::Spec->catdir(qw(lib site arch)), | |
c0f08d2c RB |
21 | ); |
22 | ||
6b913759 RB |
23 | File::Path::make_path(values %libdir); |
24 | ||
25 | push @INC, @libdir{qw(archlibexp privlibexp sitearchexp sitelibexp)}; | |
c0f08d2c RB |
26 | |
27 | our %tests = ( | |
28 | privlibexp => 1, | |
29 | sitelibexp => 0, | |
30 | archlibexp => 1, | |
31 | sitearchexp => 0, | |
32 | ); | |
33 | ||
eaa79d3d | 34 | no warnings 'once'; |
c0f08d2c RB |
35 | local %deprecate::Config = (%libdir); |
36 | ||
6b913759 | 37 | my $module = 'Deprecated.pm'; |
c0f08d2c RB |
38 | for my $lib (sort keys %tests) { |
39 | my $dir = $libdir{$lib}; | |
6b913759 RB |
40 | my $pm = File::Spec->catfile($dir, $module); |
41 | File::Copy::copy($module, $pm); | |
c0f08d2c | 42 | |
6b913759 | 43 | my $warn = ''; |
c0f08d2c RB |
44 | { local $SIG{__WARN__} = sub { $warn .= $_[0]; }; |
45 | use warnings qw(deprecated); | |
46 | #line 1001 | |
47 | require Deprecated; | |
48 | #line | |
49 | } | |
50 | if( $tests{$lib} ) { | |
51 | like($warn, qr/^Deprecated\s+will\s+be\s+removed\b/, "$lib - message"); | |
096fcbb8 CB |
52 | my $me = quotemeta($0); |
53 | like($warn, qr/$me,?\s+line\s+1001\.?\n*$/, "$lib - location"); | |
c0f08d2c RB |
54 | } |
55 | else { | |
56 | ok( !$warn, "$lib - no message" ); | |
57 | } | |
58 | ||
6b913759 | 59 | delete $INC{$module}; |
ab679d05 | 60 | unlink_all $pm; |
c0f08d2c RB |
61 | } |
62 | ||
6b913759 RB |
63 | my $sub_dir = 'Optionally'; |
64 | my $opt_mod = $sub_dir .'.pm'; | |
c0f08d2c | 65 | for my $lib (sort keys %tests) { |
6b913759 RB |
66 | my $dir = File::Spec->catdir($libdir{$lib}, $sub_dir); |
67 | File::Path::make_path($dir); | |
c0f08d2c | 68 | |
6b913759 RB |
69 | my $pm = File::Spec->catfile($dir, $module); |
70 | File::Copy::copy($opt_mod, $pm); | |
71 | ||
72 | my $warn = ''; | |
c0f08d2c RB |
73 | { local $SIG{__WARN__} = sub { $warn .= $_[0]; }; |
74 | use warnings qw(deprecated); | |
75 | require Optionally::Deprecated; | |
76 | } | |
77 | if( $tests{$lib} ) { | |
78 | like($warn, qr/^Optionally::Deprecated\s+will\s+be\s+removed\b/, | |
79 | "$lib - use if - message"); | |
80 | } | |
81 | else { | |
82 | ok( !$warn, "$lib - use if - no message" ); | |
83 | } | |
84 | ||
6b913759 | 85 | delete $INC{"$sub_dir/$module"}; |
ab679d05 | 86 | unlink_all $pm; |
c0f08d2c | 87 | } |
6b913759 RB |
88 | |
89 | END { File::Path::remove_tree('lib') } |