Reinstate require error messages for .h and .ph
authorNicholas Clark <nick@ccl4.org>
Tue, 29 Jun 2010 16:23:41 +0000 (17:23 +0100)
committerNicholas Clark <nick@ccl4.org>
Tue, 29 Jun 2010 16:26:06 +0000 (17:26 +0100)
These had been present since 5.000, but were inadvertently removed by the
refactoring b8f04b1b779ce1df.

Yes, files matching /.*.h\z/ get two pieces of advice in the error message, but
this was the exact behaviour pre-b8f04b1b779ce1df.

MANIFEST
pp_ctl.c
t/op/require_errors.t [new file with mode: 0644]

index 3452fcc..4363cd5 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -4494,6 +4494,7 @@ t/op/read.t                       See if read() works
 t/op/recurse.t                 See if deep recursion works
 t/op/ref.t                     See if refs and objects work
 t/op/repeat.t                  See if x operator works
+t/op/require_errors.t          See if errors from require are reported correctly
 t/op/reset.t                   See if reset operator works
 t/op/reverse.t                 See if reverse operator works
 t/op/runlevel.t                        See if die() works from perl_call_*()
index d718531..8134187 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -3647,9 +3647,9 @@ PP(pp_require)
                    SV * const msg = sv_2mortal(Perl_newSVpvf(aTHX_ 
                        "%s in @INC%s%s (@INC contains:",
                        msgstr,
-                       (instr(msgstr, ".h ")
-                        ? " (change .h to .ph maybe?)" : ""),
-                       (instr(msgstr, ".ph ")
+                       (memEQ(name + len - 2, ".h", 3)
+                        ? " (change .h to .ph maybe?) (did you run h2ph?)" : ""),
+                       (memEQ(name + len - 3, ".ph", 4)
                         ? " (did you run h2ph?)" : "")
                                                              ));
                    
diff --git a/t/op/require_errors.t b/t/op/require_errors.t
new file mode 100644 (file)
index 0000000..23df8b1
--- /dev/null
@@ -0,0 +1,35 @@
+#!perl
+use strict;
+use warnings;
+
+BEGIN {
+    require './test.pl';
+}
+
+plan(tests => 3);
+
+my $nonfile = tempfile();
+
+@INC = qw(Perl Rules);
+
+eval {
+    require $nonfile;
+};
+
+like $@, qr/^Can't locate $nonfile in \@INC \(\@INC contains: @INC\) at/;
+
+eval {
+    require "$nonfile.ph";
+};
+
+like $@, qr/^Can't locate $nonfile\.ph in \@INC \(did you run h2ph\?\) \(\@INC contains: @INC\) at/;
+
+eval {
+    require "$nonfile.h";
+};
+
+like $@, qr/^Can't locate $nonfile\.h in \@INC \(change \.h to \.ph maybe\?\) \(did you run h2ph\?\) \(\@INC contains: @INC\) at/;
+
+# 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.
+# (and does that only happen on VMS?)