This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test preamble: unify chdir 't' if -d 't';
[perl5.git] / t / lib / deprecate.t
CommitLineData
eaa79d3d 1#!perl -w
c0f08d2c
RB
2use strict;
3
4BEGIN {
eaa79d3d 5 require './test.pl';
c0f08d2c
RB
6}
7use File::Copy ();
8use File::Path ();
6b913759 9use File::Spec ();
eaa79d3d 10plan(tests => 10);
c0f08d2c 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
eaa79d3d 34no warnings 'once';
c0f08d2c
RB
35local %deprecate::Config = (%libdir);
36
6b913759 37my $module = 'Deprecated.pm';
c0f08d2c
RB
38for 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
63my $sub_dir = 'Optionally';
64my $opt_mod = $sub_dir .'.pm';
c0f08d2c 65for 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
89END { File::Path::remove_tree('lib') }