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.
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;
}
BEGIN { require "./test.pl"; }
-plan(tests => 71);
+plan(tests => 110);
use Config;
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