This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move File::Fetch from lib to ext
[perl5.git] / t / lib / deprecate.t
CommitLineData
c0f08d2c
RB
1use strict;
2
3BEGIN {
4 chdir 't' if -d 't';
6b913759 5 @INC = qw(../lib);
c0f08d2c
RB
6}
7use File::Copy ();
8use File::Path ();
6b913759 9use File::Spec ();
c0f08d2c
RB
10use Test::More tests => 10;
11
6b913759
RB
12my $test_dir = File::Spec->catdir(qw(lib deprecate));
13chdir $test_dir or die "Can't chdir $test_dir";
14@INC = ( File::Spec->catdir( (File::Spec->updir)x3, qw(lib)) );
15
c0f08d2c 16my %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
23File::Path::make_path(values %libdir);
24
25push @INC, @libdir{qw(archlibexp privlibexp sitearchexp sitelibexp)};
c0f08d2c
RB
26
27our %tests = (
28 privlibexp => 1,
29 sitelibexp => 0,
30 archlibexp => 1,
31 sitearchexp => 0,
32);
33
34local %deprecate::Config = (%libdir);
35
6b913759 36my $module = 'Deprecated.pm';
c0f08d2c
RB
37for my $lib (sort keys %tests) {
38 my $dir = $libdir{$lib};
6b913759
RB
39 my $pm = File::Spec->catfile($dir, $module);
40 File::Copy::copy($module, $pm);
c0f08d2c 41
6b913759 42 my $warn = '';
c0f08d2c
RB
43 { local $SIG{__WARN__} = sub { $warn .= $_[0]; };
44 use warnings qw(deprecated);
45#line 1001
46 require Deprecated;
47#line
48 }
49 if( $tests{$lib} ) {
50 like($warn, qr/^Deprecated\s+will\s+be\s+removed\b/, "$lib - message");
096fcbb8
CB
51 my $me = quotemeta($0);
52 like($warn, qr/$me,?\s+line\s+1001\.?\n*$/, "$lib - location");
c0f08d2c
RB
53 }
54 else {
55 ok( !$warn, "$lib - no message" );
56 }
57
6b913759
RB
58 delete $INC{$module};
59 unlink $pm;
c0f08d2c
RB
60}
61
6b913759
RB
62my $sub_dir = 'Optionally';
63my $opt_mod = $sub_dir .'.pm';
c0f08d2c 64for my $lib (sort keys %tests) {
6b913759
RB
65 my $dir = File::Spec->catdir($libdir{$lib}, $sub_dir);
66 File::Path::make_path($dir);
c0f08d2c 67
6b913759
RB
68 my $pm = File::Spec->catfile($dir, $module);
69 File::Copy::copy($opt_mod, $pm);
70
71 my $warn = '';
c0f08d2c
RB
72 { local $SIG{__WARN__} = sub { $warn .= $_[0]; };
73 use warnings qw(deprecated);
74 require Optionally::Deprecated;
75 }
76 if( $tests{$lib} ) {
77 like($warn, qr/^Optionally::Deprecated\s+will\s+be\s+removed\b/,
78 "$lib - use if - message");
79 }
80 else {
81 ok( !$warn, "$lib - use if - no message" );
82 }
83
6b913759
RB
84 delete $INC{"$sub_dir/$module"};
85 unlink $pm;
c0f08d2c 86}
6b913759
RB
87
88END { File::Path::remove_tree('lib') }