зеркало из https://github.com/github/ruby.git
[Bug #18892] Reset `ARGF.lineno` after reading shebang
This commit is contained in:
Родитель
7ba5c0633c
Коммит
cd94842922
6
io.c
6
io.c
|
@ -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);
|
||||
|
||||
/*
|
||||
|
|
3
ruby.c
3
ruby.c
|
@ -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) {
|
||||
|
|
|
@ -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 = []
|
||||
|
|
Загрузка…
Ссылка в новой задаче