This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
rewrote deprecate test using File::Spec
[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");
51 like($warn, qr/$0,?\s+line\s+1001\.?\n*$/, "$lib - location");
52 }
53 else {
54 ok( !$warn, "$lib - no message" );
55 }
56
6b913759
RB
57 delete $INC{$module};
58 unlink $pm;
c0f08d2c
RB
59}
60
6b913759
RB
61my $sub_dir = 'Optionally';
62my $opt_mod = $sub_dir .'.pm';
c0f08d2c 63for my $lib (sort keys %tests) {
6b913759
RB
64 my $dir = File::Spec->catdir($libdir{$lib}, $sub_dir);
65 File::Path::make_path($dir);
c0f08d2c 66
6b913759
RB
67 my $pm = File::Spec->catfile($dir, $module);
68 File::Copy::copy($opt_mod, $pm);
69
70 my $warn = '';
c0f08d2c
RB
71 { local $SIG{__WARN__} = sub { $warn .= $_[0]; };
72 use warnings qw(deprecated);
73 require Optionally::Deprecated;
74 }
75 if( $tests{$lib} ) {
76 like($warn, qr/^Optionally::Deprecated\s+will\s+be\s+removed\b/,
77 "$lib - use if - message");
78 }
79 else {
80 ok( !$warn, "$lib - use if - no message" );
81 }
82
6b913759
RB
83 delete $INC{"$sub_dir/$module"};
84 unlink $pm;
c0f08d2c 85}
6b913759
RB
86
87END { File::Path::remove_tree('lib') }