Commit | Line | Data |
---|---|---|
686c4ca0 NC |
1 | #!perl |
2 | use strict; | |
3 | use warnings; | |
4 | ||
5 | BEGIN { | |
c69577e2 | 6 | chdir 't'; |
686c4ca0 NC |
7 | require './test.pl'; |
8 | } | |
9 | ||
2fc7dfcb | 10 | plan(tests => 9); |
686c4ca0 NC |
11 | |
12 | my $nonfile = tempfile(); | |
13 | ||
14 | @INC = qw(Perl Rules); | |
15 | ||
2fc7dfcb NC |
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 | |
18 | ||
19 | for my $file ($nonfile, ' ') { | |
20 | eval { | |
21 | require $file; | |
22 | }; | |
23 | ||
24 | like $@, qr/^Can't locate $file in \@INC \(\@INC contains: @INC\) at/, | |
25 | "correct error message for require '$file'"; | |
26 | } | |
686c4ca0 | 27 | |
2fc7dfcb NC |
28 | eval "require $nonfile"; |
29 | ||
30 | like $@, qr/^Can't locate $nonfile\.pm in \@INC \(\@INC contains: @INC\) at/, | |
31 | "correct error message for require $nonfile"; | |
686c4ca0 NC |
32 | |
33 | eval { | |
34 | require "$nonfile.ph"; | |
35 | }; | |
36 | ||
37 | like $@, qr/^Can't locate $nonfile\.ph in \@INC \(did you run h2ph\?\) \(\@INC contains: @INC\) at/; | |
38 | ||
2fc7dfcb NC |
39 | for my $file ("$nonfile.h", ".h") { |
40 | eval { | |
41 | require $file | |
42 | }; | |
686c4ca0 | 43 | |
2fc7dfcb NC |
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'"; | |
46 | } | |
686c4ca0 | 47 | |
32437794 FC |
48 | eval 'require <foom>'; |
49 | like $@, qr/^<> should be quotes at /, 'require <> error'; | |
50 | ||
2433d39e BF |
51 | my $module = tempfile(); |
52 | my $mod_file = "$module.pm"; | |
53 | ||
54 | open my $module_fh, ">", $mod_file or die $!; | |
55 | print { $module_fh } "print 1; 1;\n"; | |
56 | close $module_fh; | |
57 | ||
58 | chmod 0333, $mod_file; | |
59 | ||
60 | SKIP: { | |
61 | skip_if_miniperl("these modules may not be available to miniperl", 2); | |
62 | ||
63 | push @INC, '../lib'; | |
64 | require Cwd; | |
65 | require File::Spec::Functions; | |
66 | if ($^O eq 'cygwin') { | |
67 | require Win32; | |
68 | } | |
69 | ||
70 | # Going to try to switch away from root. Might not work. | |
71 | # (stolen from t/op/stat.t) | |
72 | my $olduid = $>; | |
73 | eval { $> = 1; }; | |
74 | skip "Can't test permissions meaningfully if you're superuser", 2 | |
75 | if ($^O eq 'cygwin' ? Win32::IsAdminUser() : $> == 0); | |
76 | ||
77 | local @INC = "."; | |
78 | eval "use $module"; | |
79 | like $@, | |
80 | qr<^\QCan't locate $mod_file:>, | |
81 | "special error message if the file exists but can't be opened"; | |
82 | ||
83 | my $file = File::Spec::Functions::catfile(Cwd::getcwd(), $mod_file); | |
84 | eval { | |
85 | require($file); | |
86 | }; | |
87 | like $@, | |
88 | qr<^\QCan't locate $file:>, | |
89 | "...even if we use a full path"; | |
90 | ||
91 | # switch uid back (may not be implemented) | |
92 | eval { $> = $olduid; }; | |
93 | } | |
94 | ||
95 | 1 while unlink $mod_file; | |
96 | ||
686c4ca0 NC |
97 | # I can't see how to test the EMFILE case |
98 | # I can't see how to test the case of not displaying @INC in the message. | |
99 | # (and does that only happen on VMS?) |