[Bug #18892] Reset ARGF.lineno
after reading shebang
This commit is contained in:
parent
7ba5c0633c
commit
cd94842922
Notes:
git
2022-07-07 11:33:34 +09:00
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;
|
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);
|
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
|
#define warn_cr_in_shebang(str, len) (void)0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void rb_reset_argf_lineno(long n);
|
||||||
|
|
||||||
struct load_file_arg {
|
struct load_file_arg {
|
||||||
VALUE parser;
|
VALUE parser;
|
||||||
VALUE fname;
|
VALUE fname;
|
||||||
@ -2247,6 +2249,7 @@ load_file_internal(VALUE argp_v)
|
|||||||
if (NIL_P(c)) {
|
if (NIL_P(c)) {
|
||||||
argp->f = f = Qnil;
|
argp->f = f = Qnil;
|
||||||
}
|
}
|
||||||
|
rb_reset_argf_lineno(0);
|
||||||
ruby_opt_init(opt);
|
ruby_opt_init(opt);
|
||||||
}
|
}
|
||||||
if (opt->src.enc.index >= 0) {
|
if (opt->src.enc.index >= 0) {
|
||||||
|
@ -143,6 +143,17 @@ class TestArgf < Test::Unit::TestCase
|
|||||||
};
|
};
|
||||||
end
|
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
|
def test_new_lineno_each
|
||||||
f = ARGF.class.new(@t1.path, @t2.path, @t3.path)
|
f = ARGF.class.new(@t1.path, @t2.path, @t3.path)
|
||||||
result = []
|
result = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user