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