diff options
-rw-r--r-- | io.c | 6 | ||||
-rw-r--r-- | ruby.c | 3 | ||||
-rw-r--r-- | test/ruby/test_argf.rb | 11 |
3 files changed, 20 insertions, 0 deletions
@@ -9866,6 +9866,12 @@ argf_lineno_setter(VALUE val, ID id, VALUE *var) ARGF.last_lineno = ARGF.lineno = n; } +void +rb_reset_argf_lineno(long n) +{ + ARGF.last_lineno = ARGF.lineno = n; +} + static VALUE argf_gets(int, VALUE *, VALUE); /* @@ -2151,6 +2151,8 @@ warn_cr_in_shebang(const char *str, long len) #define warn_cr_in_shebang(str, len) (void)0 #endif +void rb_reset_argf_lineno(long n); + struct load_file_arg { VALUE parser; VALUE fname; @@ -2247,6 +2249,7 @@ load_file_internal(VALUE argp_v) if (NIL_P(c)) { argp->f = f = Qnil; } + rb_reset_argf_lineno(0); ruby_opt_init(opt); } if (opt->src.enc.index >= 0) { diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb index dbffd24370..12f7d6485a 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -143,6 +143,17 @@ class TestArgf < Test::Unit::TestCase }; end + def test_lineno_after_shebang + expected = %w"1 1 1 2 2 2 3 3 1 4 4 2" + assert_in_out_err(["--enable=gems", "-", @t1.path, @t2.path], "#{<<~"{#"}\n#{<<~'};'}", expected) + #!/usr/bin/env ruby + {# + ARGF.each do |line| + puts [$., ARGF.lineno, ARGF.file.lineno] + end + }; + end + def test_new_lineno_each f = ARGF.class.new(@t1.path, @t2.path, @t3.path) result = [] |