[perl #104288] Die with ‘Unrecognized switch’ on #! line
authorFather Chrysostomos <sprout@cpan.org>
Sat, 31 Dec 2011 04:13:29 +0000 (20:13 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 31 Dec 2011 04:30:44 +0000 (20:30 -0800)
If a switch such as -x that cannot occur on the shebang line is used
there, perl dies with ‘Can’t emulate...’.

If an unrecognised switch is used on the command line, perl dies with
‘Unrecognized switch...’.

It just happens to use the former error message for unrecognized
switches on the shebang line, which can be confusing:

$ perl -e '#!perl -G'
Can't emulate -G on #! line at -e line 1.

This commit changes it to output the same message as command-line
switches for those that are unrecognised wherever they are used.

perl.c
t/run/switches.t

diff --git a/perl.c b/perl.c
index d50116b..3fae0e5 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -3354,8 +3354,12 @@ Perl_moreswitches(pTHX_ const char *s)
     case 'S':                  /* OS/2 needs -S on "extproc" line. */
        break;
 #endif
-    default:
+    case 'e': case 'f': case 'x': case 'E': case 'S': case 'V':
        Perl_croak(aTHX_ "Can't emulate -%.1s on #! line",s);
+    default:
+       Perl_croak(aTHX_
+           "Unrecognized switch: -%.1s  (-h will show valid options)",s
+       );
     }
     return NULL;
 }
index f636cea..419d580 100644 (file)
@@ -11,7 +11,7 @@ BEGIN {
 
 BEGIN { require "./test.pl"; }
 
-plan(tests => 71);
+plan(tests => 110);
 
 use Config;
 
@@ -297,6 +297,20 @@ foreach my $switch (split //, "ABbGgHJjKkLNOoPQqRrYyZz123456789_")
          qr/\QUnrecognized switch: -$switch  (-h will show valid options)./,
           "-$switch correctly unknown" );
 
+    # [perl #104288]
+    like( runperl( stderr => 1, prog => "#!perl -$switch" ),
+         qr/^Unrecognized switch: -$switch  \(-h will show valid (?x:
+            )options\) at -e line 1\./,
+          "-$switch unrecognised on #! line" );
+}
+
+# Tests for unshebangable switches
+for (qw( e f x E S V )) {
+    $r = runperl(
+       stderr   => 1,
+       prog     => "#!perl -$_",
+    );
+    is $r, "Can't emulate -$_ on #! line at -e line 1.\n","-$_ on #! line";
 }
 
 # Tests for -i