summaryrefslogtreecommitdiff
path: root/t/run
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2016-07-02 00:08:48 -0700
committerSteve Hay <steve.m.hay@googlemail.com>2017-07-28 08:18:22 +0100
commitbe0ada6e96e67ddb6d3a8d150d05a501380bc2fe (patch)
treeb420bf2e75654629abb676c069fc4f71092717a4 /t/run
parentf2a117f170b84389d99a29cbff52b61fd2f36f69 (diff)
downloadperl-be0ada6e96e67ddb6d3a8d150d05a501380bc2fe.tar.gz
[perl #128508] Fix line numbers with perl -x
When lex_start is invoked with an SV and a handle pointer, it expects the SV to contain the beginning of the code to be parsed. The handle will be read from for subsequent code. The -x command line option happens to invoke lex_start with two non- null pointers like this (a line and a handle), since, to find the #!perl line, it has to read that first line out of the file handle. There is a line of code in lex_start that adds "\n;" to the buffer goes back to 8990e30710 (perl 5.0 alpha 6) and string eval fails catastrophically without it. As of v5.19.1-485-g2179133 multiple lines are supported in the current parsing buffer (PL_linestr) when there is a file handle, and as of v5.19.3-63-gbf1b738 the line number is correctly incremented when the parser goes past a newline. So, for -x, "#!perl\n" turns into "#!perl\n\n" (the final ; is skipped as of v5.19.3-63-gbf1b738 if there is a handle). That throws line numbers off by one. In the case where we have a string to parse and a file handle, the extra "\n;" added to the end of the buffer turns out to be completely unnecessary. So this commit makes it conditional on rsfp. The existing tests for -x are quite exotic. I have made no effort to make them less so. (cherry picked from commit b3dd0aba3d2bf0b22280303ef6f068e976e31888)
Diffstat (limited to 't/run')
-rw-r--r--t/run/switchx.aux7
-rw-r--r--t/run/switchx.t4
2 files changed, 6 insertions, 5 deletions
diff --git a/t/run/switchx.aux b/t/run/switchx.aux
index b59df4a0ed..106b2f79c6 100644
--- a/t/run/switchx.aux
+++ b/t/run/switchx.aux
@@ -17,11 +17,12 @@ still not perl
#!/some/path/that/leads/to/perl -l
-print "1..7";
+print "1..8";
+print "ok 1 - Correct line number" if __LINE__ == 4;
if (-f 'run/switchx.aux') {
- print "ok 1 - Test file exists";
+ print "ok 2 - Test file exists";
}
-print "ok 2 - Test file utilized";
+print "ok 3 - Test file utilized";
# other tests are in switchx2.aux
__END__
diff --git a/t/run/switchx.t b/t/run/switchx.t
index bcea3d0ab6..4e57d04497 100644
--- a/t/run/switchx.t
+++ b/t/run/switchx.t
@@ -15,9 +15,9 @@ print runperl( switches => ['-x'],
# Test '-xdir'
print runperl( switches => ['-x./run'],
progfile => 'run/switchx2.aux',
- args => [ 3 ] );
+ args => [ 4 ] );
-curr_test(5);
+curr_test(6);
# Test the error message for not found
like(runperl(switches => ['-x'], progfile => 'run/switchx3.aux', stderr => 1),