1#!perl 2 3BEGIN { 4 chdir 't' if -d 't'; 5 require './test.pl'; 6} 7 8use strict; 9use warnings; 10 11plan(tests => 19); 12 13my $nonfile = tempfile(); 14 15@INC = qw(Perl Rules); 16 17# The tests for ' ' and '.h' never did fail, but previously the error reporting 18# code would read memory before the start of the SV's buffer 19 20for my $file ($nonfile, ' ') { 21 eval { 22 require $file; 23 }; 24 25 like $@, qr/^Can't locate $file in \@INC \(\@INC contains: @INC\) at/, 26 "correct error message for require '$file'"; 27} 28 29eval "require $nonfile"; 30 31like $@, qr/^Can't locate $nonfile\.pm in \@INC \(you may need to install the $nonfile module\) \(\@INC contains: @INC\) at/, 32 "correct error message for require $nonfile"; 33 34eval { 35 require "$nonfile.ph"; 36}; 37 38like $@, qr/^Can't locate $nonfile\.ph in \@INC \(did you run h2ph\?\) \(\@INC contains: @INC\) at/; 39 40for my $file ("$nonfile.h", ".h") { 41 eval { 42 require $file 43 }; 44 45 like $@, qr/^Can't locate \Q$file\E in \@INC \(change \.h to \.ph maybe\?\) \(did you run h2ph\?\) \(\@INC contains: @INC\) at/, 46 "correct error message for require '$file'"; 47} 48 49for my $file ("$nonfile.ph", ".ph") { 50 eval { 51 require $file 52 }; 53 54 like $@, qr/^Can't locate \Q$file\E in \@INC \(did you run h2ph\?\) \(\@INC contains: @INC\) at/, 55 "correct error message for require '$file'"; 56} 57 58eval 'require <foom>'; 59like $@, qr/^<> at require-statement should be quotes at /, 'require <> error'; 60 61my $module = tempfile(); 62my $mod_file = "$module.pm"; 63 64open my $module_fh, ">", $mod_file or die $!; 65print { $module_fh } "print 1; 1;\n"; 66close $module_fh; 67 68chmod 0333, $mod_file; 69 70SKIP: { 71 skip_if_miniperl("these modules may not be available to miniperl", 2); 72 73 push @INC, '../lib'; 74 require Cwd; 75 require File::Spec::Functions; 76 if ($^O eq 'cygwin') { 77 require Win32; 78 } 79 80 # Going to try to switch away from root. Might not work. 81 # (stolen from t/op/stat.t) 82 my $olduid = $>; 83 eval { $> = 1; }; 84 skip "Can't test permissions meaningfully if you're superuser", 2 85 if ($^O eq 'cygwin' ? Win32::IsAdminUser() : $> == 0); 86 87 local @INC = "."; 88 eval "use $module"; 89 like $@, 90 qr<^\QCan't locate $mod_file:>, 91 "special error message if the file exists but can't be opened"; 92 93 SKIP: { 94 skip "Can't make the path absolute", 1 95 if !defined(Cwd::getcwd()); 96 97 my $file = File::Spec::Functions::catfile(Cwd::getcwd(), $mod_file); 98 eval { 99 require($file); 100 }; 101 like $@, 102 qr<^\QCan't locate $file:>, 103 "...even if we use a full path"; 104 } 105 106 # switch uid back (may not be implemented) 107 eval { $> = $olduid; }; 108} 109 1101 while unlink $mod_file; 111 112# I can't see how to test the EMFILE case 113# I can't see how to test the case of not displaying @INC in the message. 114# (and does that only happen on VMS?) 115 116# fail and print the full filename 117eval { no warnings 'syscalls'; require "strict.pm\0invalid"; }; 118like $@, qr/^Can't locate strict\.pm\\0invalid: /, 'require nul check [perl #117265]'; 119eval { no warnings 'syscalls'; do "strict.pm\0invalid"; }; 120like $@, qr/^Can't locate strict\.pm\\0invalid: /, 'do nul check'; 121{ 122 my $WARN; 123 local $SIG{__WARN__} = sub { $WARN = shift }; 124 eval { require "strict.pm\0invalid"; }; 125 like $WARN, qr{^Invalid \\0 character in pathname for require: strict\.pm\\0invalid at }, 'nul warning'; 126 like $@, qr{^Can't locate strict\.pm\\0invalid: }, 'nul error'; 127 128 $WARN = ''; 129 local @INC = @INC; 130 unshift @INC, "lib\0invalid"; 131 eval { require "unknown.pm" }; 132 like $WARN, qr{^Invalid \\0 character in \@INC entry for require: lib\\0invalid at }, 'nul warning'; 133} 134eval "require strict\0::invalid;"; 135like $@, qr/^syntax error at \(eval \d+\) line 1/, 'parse error with \0 in barewords module names'; 136 137# Refs and globs that stringify with embedded nulls 138# These crashed from 5.20 to 5.24 [perl #128182]. 139eval { no warnings 'syscalls'; require eval "qr/\0/" }; 140like $@, qr/^Can't locate \(\?\^:\\0\):/, 141 'require ref that stringifies with embedded null'; 142eval { no strict; no warnings 'syscalls'; require *{"\0a"} }; 143like $@, qr/^Can't locate \*main::\\0a:/, 144 'require ref that stringifies with embedded null'; 145