ruby-changes:50588
From: nobu <ko1@a...>
Date: Tue, 13 Mar 2018 12:40:14 +0900 (JST)
Subject: [ruby-changes:50588] nobu:r62736 (trunk): eval_error.c: last newline
nobu 2018-03-13 12:40:10 +0900 (Tue, 13 Mar 2018) New Revision: 62736 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62736 Log: 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. Modified files: trunk/eval_error.c trunk/test/ruby/test_exception.rb Index: eval_error.c =================================================================== --- eval_error.c (revision 62735) +++ eval_error.c (revision 62736) @@ -153,14 +153,16 @@ print_errinfo(const VALUE eclass, const https://github.com/ruby/ruby/blob/trunk/eval_error.c#L153 write_warn2(str, "\n", 1); } if (tail) { - if (highlight) { - if (einfo[elen-1] == '\n') --elen; - write_warn(str, bold); + int eol = einfo[elen-1] == '\n'; + if (eol && highlight) --elen; + if (tail < einfo+elen) { + if (highlight) write_warn(str, bold); + write_warn2(str, tail, einfo+elen-tail); + if (highlight) write_warn(str, reset); + if (highlight || !eol) write_warn2(str, "\n", 1); } - if (tail < einfo+elen) write_warn2(str, tail, einfo+elen-tail); } - if (tail ? (highlight || einfo[elen-1] != '\n') : !epath) { - if (highlight) write_warn(str, reset); + else if (!epath) { write_warn2(str, "\n", 1); } } Index: test/ruby/test_exception.rb =================================================================== --- test/ruby/test_exception.rb (revision 62735) +++ test/ruby/test_exception.rb (revision 62736) @@ -1255,12 +1255,12 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1255 _, err2, status1 = EnvUtil.invoke_ruby(['-e', "#{test_method}; begin; foo; end"], '', true, true) assert_equal(err2, out1) - if $stderr.tty? - e = RuntimeError.new("a\n") - message = assert_nothing_raised(ArgumentError, proc {e.pretty_inspect}) do - e.full_message - end - assert_operator(message, :end_with?, "\n") + e = RuntimeError.new("a\n") + message = assert_nothing_raised(ArgumentError, proc {e.pretty_inspect}) do + e.full_message end + assert_operator(message, :end_with?, "\n") + message = message.gsub(/\e\[[\d;]*m/, '') + assert_not_operator(message, :end_with?, "\n\n") end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/