1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

eval_error.c: last newline

* eval_error.c (print_errinfo): do not print an empty line at the
  end when the message ends with a newline.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62736 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-03-13 03:40:10 +00:00
parent e537dc331e
commit b07e4af869
2 changed files with 14 additions and 12 deletions

View file

@ -153,14 +153,16 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, const VA
write_warn2(str, "\n", 1); write_warn2(str, "\n", 1);
} }
if (tail) { if (tail) {
if (highlight) { int eol = einfo[elen-1] == '\n';
if (einfo[elen-1] == '\n') --elen; if (eol && highlight) --elen;
write_warn(str, bold); if (tail < einfo+elen) {
} if (highlight) write_warn(str, bold);
if (tail < einfo+elen) write_warn2(str, tail, einfo+elen-tail); write_warn2(str, tail, einfo+elen-tail);
}
if (tail ? (highlight || einfo[elen-1] != '\n') : !epath) {
if (highlight) write_warn(str, reset); if (highlight) write_warn(str, reset);
if (highlight || !eol) write_warn2(str, "\n", 1);
}
}
else if (!epath) {
write_warn2(str, "\n", 1); write_warn2(str, "\n", 1);
} }
} }

View file

@ -1255,12 +1255,12 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
_, err2, status1 = EnvUtil.invoke_ruby(['-e', "#{test_method}; begin; foo; end"], '', true, true) _, err2, status1 = EnvUtil.invoke_ruby(['-e', "#{test_method}; begin; foo; end"], '', true, true)
assert_equal(err2, out1) assert_equal(err2, out1)
if $stderr.tty?
e = RuntimeError.new("a\n") e = RuntimeError.new("a\n")
message = assert_nothing_raised(ArgumentError, proc {e.pretty_inspect}) do message = assert_nothing_raised(ArgumentError, proc {e.pretty_inspect}) do
e.full_message e.full_message
end end
assert_operator(message, :end_with?, "\n") assert_operator(message, :end_with?, "\n")
end message = message.gsub(/\e\[[\d;]*m/, '')
assert_not_operator(message, :end_with?, "\n\n")
end end
end end