13 my $nonfile = tempfile();
15 @INC = qw(Perl Rules);
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
20 for my $file ($nonfile, ' ') {
25 like $@, qr/^Can't locate $file in \@INC \(\@INC contains: @INC\) at/,
26 "correct error message for require '$file'";
29 eval "require $nonfile";
31 like $@, 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";
35 require "$nonfile.ph";
38 like $@, qr/^Can't locate $nonfile\.ph in \@INC \(did you run h2ph\?\) \(\@INC contains: @INC\) at/;
40 for my $file ("$nonfile.h", ".h") {
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'";
49 for my $file ("$nonfile.ph", ".ph") {
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'";
58 eval 'require <foom>';
59 like $@, qr/^<> at require-statement should be quotes at /, 'require <> error';
61 my $module = tempfile();
62 my $mod_file = "$module.pm";
64 open my $module_fh, ">", $mod_file or die $!;
65 print { $module_fh } "print 1; 1;\n";
68 chmod 0333, $mod_file;
71 skip_if_miniperl("these modules may not be available to miniperl", 2);
75 require File::Spec::Functions;
76 if ($^O eq 'cygwin') {
80 # Going to try to switch away from root. Might not work.
81 # (stolen from t/op/stat.t)
84 skip "Can't test permissions meaningfully if you're superuser", 2
85 if ($^O eq 'cygwin' ? Win32::IsAdminUser() : $> == 0);
90 qr<^\QCan't locate $mod_file:>,
91 "special error message if the file exists but can't be opened";
94 skip "Can't make the path absolute", 1
95 if !defined(Cwd::getcwd());
97 my $file = File::Spec::Functions::catfile(Cwd::getcwd(), $mod_file);
102 qr<^\QCan't locate $file:>,
103 "...even if we use a full path";
106 # switch uid back (may not be implemented)
107 eval { $> = $olduid; };
110 1 while unlink $mod_file;
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?)
116 # fail and print the full filename
117 eval { no warnings 'syscalls'; require "strict.pm\0invalid"; };
118 like $@, qr/^Can't locate strict\.pm\\0invalid: /, 'require nul check [perl #117265]';
119 eval { no warnings 'syscalls'; do "strict.pm\0invalid"; };
120 like $@, qr/^Can't locate strict\.pm\\0invalid: /, 'do nul check';
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';
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';
134 eval "require strict\0::invalid;";
135 like $@, qr/^syntax error at \(eval \d+\) line 1/, 'parse error with \0 in barewords module names';