Skip to content

Commit

Permalink
warn on -i with no input files given [perl #113410]
Browse files Browse the repository at this point in the history
  • Loading branch information
doy committed Jun 26, 2012
1 parent 07b2a6c commit 82f9620
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions dist/B-Deparse/t/deparse.t
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ my $path = join " ", map { qq["-I$_"] } @INC;
$a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
$a =~ s/-e syntax OK\n//g;
$a =~ s/.*possible typo.*\n//; # Remove warning line
$a =~ s/.*-i used with no filenames.*\n//; # Remove warning line
$a =~ s{\\340\\242}{\\s} if (ord("\\") == 224); # EBCDIC, cp 1047 or 037
$a =~ s{\\274\\242}{\\s} if (ord("\\") == 188); # $^O eq 'posix-bc'
$b = <<'EOF';
Expand Down
5 changes: 5 additions & 0 deletions perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -4150,6 +4150,11 @@ Perl_init_argv_symbols(pTHX_ register int argc, register char **argv)
(void)sv_utf8_decode(sv);
}
}

if (PL_inplace && (!PL_argvgv || AvFILL(GvAV(PL_argvgv)) == -1))
Perl_ck_warner_d(aTHX_ packWARN(WARN_INPLACE),
"-i used with no filenames on the command line, "
"reading from STDIN");
}

STATIC void
Expand Down
10 changes: 10 additions & 0 deletions pod/perldiag.pod
Original file line number Diff line number Diff line change
Expand Up @@ -2109,6 +2109,16 @@ Further error messages would likely be uninformative.
(4294967295) and therefore non-portable between systems. See
L<perlport> for more on portability concerns.

=item -i used with no filenames on the command line, reading from STDIN

(S inplace) The C<-i> option was passed on the command line, indicating
that the script is intended to edit files inplace, but no files were
given. This is usually a mistake, since editing STDIN inplace doesn't
make sense, and can be confusing because it can make perl look like it
is hanging when it is really just trying to read from STDIN. You should
either pass a filename to edit, or remove C<-i> from the command line.
See L<perlrun> for more details.

=item Identifier too long

(F) Perl limits identifiers (names for variables, functions, etc.) to
Expand Down
22 changes: 21 additions & 1 deletion t/run/switches.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ BEGIN {

BEGIN { require "./test.pl"; }

plan(tests => 112);
plan(tests => 114);

use Config;

Expand Down Expand Up @@ -350,6 +350,26 @@ __EOF__
is(join(":", @bak),
"foo yada dada:bada foo bing:king kong foo",
"-i backup file");

my $out1 = runperl(
switches => ['-i.bak -p'],
prog => 'exit',
stderr => 1,
stdin => "1\n",
);
is(
$out1,
"-i used with no filenames on the command line, reading from STDIN.\n",
"warning when no files given"
);
my $out2 = runperl(
switches => ['-i.bak -p'],
prog => 'exit',
stderr => 1,
stdin => "1\n",
args => ['file'],
);
is($out2, "", "no warning when files given");
}

# Tests for -E
Expand Down

0 comments on commit 82f9620

Please sign in to comment.