summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/t/op/require_errors.t
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/perl/t/op/require_errors.t')
-rw-r--r--gnu/usr.bin/perl/t/op/require_errors.t96
1 files changed, 87 insertions, 9 deletions
diff --git a/gnu/usr.bin/perl/t/op/require_errors.t b/gnu/usr.bin/perl/t/op/require_errors.t
index 23df8b1676b..e3239486bec 100644
--- a/gnu/usr.bin/perl/t/op/require_errors.t
+++ b/gnu/usr.bin/perl/t/op/require_errors.t
@@ -3,20 +3,32 @@ use strict;
use warnings;
BEGIN {
+ chdir 't';
require './test.pl';
}
-plan(tests => 3);
+plan(tests => 11);
my $nonfile = tempfile();
@INC = qw(Perl Rules);
-eval {
- require $nonfile;
-};
+# The tests for ' ' and '.h' never did fail, but previously the error reporting
+# code would read memory before the start of the SV's buffer
-like $@, qr/^Can't locate $nonfile in \@INC \(\@INC contains: @INC\) at/;
+for my $file ($nonfile, ' ') {
+ eval {
+ require $file;
+ };
+
+ like $@, qr/^Can't locate $file in \@INC \(\@INC contains: @INC\) at/,
+ "correct error message for require '$file'";
+}
+
+eval "require $nonfile";
+
+like $@, qr/^Can't locate $nonfile\.pm in \@INC \(you may need to install the $nonfile module\) \(\@INC contains: @INC\) at/,
+ "correct error message for require $nonfile";
eval {
require "$nonfile.ph";
@@ -24,11 +36,77 @@ eval {
like $@, qr/^Can't locate $nonfile\.ph in \@INC \(did you run h2ph\?\) \(\@INC contains: @INC\) at/;
-eval {
- require "$nonfile.h";
-};
+for my $file ("$nonfile.h", ".h") {
+ eval {
+ require $file
+ };
+
+ like $@, qr/^Can't locate \Q$file\E in \@INC \(change \.h to \.ph maybe\?\) \(did you run h2ph\?\) \(\@INC contains: @INC\) at/,
+ "correct error message for require '$file'";
+}
+
+for my $file ("$nonfile.ph", ".ph") {
+ eval {
+ require $file
+ };
+
+ like $@, qr/^Can't locate \Q$file\E in \@INC \(did you run h2ph\?\) \(\@INC contains: @INC\) at/,
+ "correct error message for require '$file'";
+}
+
+eval 'require <foom>';
+like $@, qr/^<> should be quotes at /, 'require <> error';
+
+my $module = tempfile();
+my $mod_file = "$module.pm";
+
+open my $module_fh, ">", $mod_file or die $!;
+print { $module_fh } "print 1; 1;\n";
+close $module_fh;
+
+chmod 0333, $mod_file;
+
+SKIP: {
+ skip_if_miniperl("these modules may not be available to miniperl", 2);
+
+ push @INC, '../lib';
+ require Cwd;
+ require File::Spec::Functions;
+ if ($^O eq 'cygwin') {
+ require Win32;
+ }
+
+ # Going to try to switch away from root. Might not work.
+ # (stolen from t/op/stat.t)
+ my $olduid = $>;
+ eval { $> = 1; };
+ skip "Can't test permissions meaningfully if you're superuser", 2
+ if ($^O eq 'cygwin' ? Win32::IsAdminUser() : $> == 0);
+
+ local @INC = ".";
+ eval "use $module";
+ like $@,
+ qr<^\QCan't locate $mod_file:>,
+ "special error message if the file exists but can't be opened";
+
+ SKIP: {
+ skip "Can't make the path absolute", 1
+ if !defined(Cwd::getcwd());
+
+ my $file = File::Spec::Functions::catfile(Cwd::getcwd(), $mod_file);
+ eval {
+ require($file);
+ };
+ like $@,
+ qr<^\QCan't locate $file:>,
+ "...even if we use a full path";
+ }
+
+ # switch uid back (may not be implemented)
+ eval { $> = $olduid; };
+}
-like $@, qr/^Can't locate $nonfile\.h in \@INC \(change \.h to \.ph maybe\?\) \(did you run h2ph\?\) \(\@INC contains: @INC\) at/;
+1 while unlink $mod_file;
# I can't see how to test the EMFILE case
# I can't see how to test the case of not displaying @INC in the message.