12 my $nonfile = tempfile();
14 @INC = qw(Perl Rules);
16 # The tests for ' ' and '.h' never did fail, but previously the error reporting
17 # code would read memory before the start of the SV's buffer
19 for my $file ($nonfile, ' ') {
24 like $@, qr/^Can't locate $file in \@INC \(\@INC contains: @INC\) at/,
25 "correct error message for require '$file'";
28 eval "require $nonfile";
30 like $@, qr/^Can't locate $nonfile\.pm in \@INC \(you may need to install the $nonfile module\) \(\@INC contains: @INC\) at/,
31 "correct error message for require $nonfile";
34 require "$nonfile.ph";
37 like $@, qr/^Can't locate $nonfile\.ph in \@INC \(did you run h2ph\?\) \(\@INC contains: @INC\) at/;
39 for my $file ("$nonfile.h", ".h") {
44 like $@, qr/^Can't locate \Q$file\E in \@INC \(change \.h to \.ph maybe\?\) \(did you run h2ph\?\) \(\@INC contains: @INC\) at/,
45 "correct error message for require '$file'";
48 for my $file ("$nonfile.ph", ".ph") {
53 like $@, qr/^Can't locate \Q$file\E in \@INC \(did you run h2ph\?\) \(\@INC contains: @INC\) at/,
54 "correct error message for require '$file'";
57 eval 'require <foom>';
58 like $@, qr/^<> at require-statement should be quotes at /, 'require <> error';
60 my $module = tempfile();
61 my $mod_file = "$module.pm";
63 open my $module_fh, ">", $mod_file or die $!;
64 print { $module_fh } "print 1; 1;\n";
67 chmod 0333, $mod_file;
70 skip_if_miniperl("these modules may not be available to miniperl", 2);
74 require File::Spec::Functions;
75 if ($^O eq 'cygwin') {
79 # Going to try to switch away from root. Might not work.
80 # (stolen from t/op/stat.t)
83 skip "Can't test permissions meaningfully if you're superuser", 2
84 if ($^O eq 'cygwin' ? Win32::IsAdminUser() : $> == 0);
89 qr<^\QCan't locate $mod_file:>,
90 "special error message if the file exists but can't be opened";
93 skip "Can't make the path absolute", 1
94 if !defined(Cwd::getcwd());
96 my $file = File::Spec::Functions::catfile(Cwd::getcwd(), $mod_file);
101 qr<^\QCan't locate $file:>,
102 "...even if we use a full path";
105 # switch uid back (may not be implemented)
106 eval { $> = $olduid; };
109 1 while unlink $mod_file;
111 # I can't see how to test the EMFILE case
112 # I can't see how to test the case of not displaying @INC in the message.
113 # (and does that only happen on VMS?)
115 # fail and print the full filename
116 eval { no warnings 'syscalls'; require "strict.pm\0invalid"; };
117 like $@, qr/^Can't locate strict\.pm\\0invalid: /, 'require nul check [perl #117265]';
118 eval { no warnings 'syscalls'; do "strict.pm\0invalid"; };
119 like $@, qr/^Can't locate strict\.pm\\0invalid: /, 'do nul check';
122 local $SIG{__WARN__} = sub { $WARN = shift };
123 eval { require "strict.pm\0invalid"; };
124 like $WARN, qr{^Invalid \\0 character in pathname for require: strict\.pm\\0invalid at }, 'nul warning';
125 like $@, qr{^Can't locate strict\.pm\\0invalid: }, 'nul error';
129 unshift @INC, "lib\0invalid";
130 eval { require "unknown.pm" };
131 like $WARN, qr{^Invalid \\0 character in \@INC entry for require: lib\\0invalid at }, 'nul warning';
133 eval "require strict\0::invalid;";
134 like $@, qr/^syntax error at \(eval \d+\) line 1/, 'parse error with \0 in barewords module names';