ruby-changes:49535
From: nobu <ko1@a...>
Date: Sun, 7 Jan 2018 14:38:42 +0900 (JST)
Subject: [ruby-changes:49535] nobu:r61650 (trunk): eval_error.c: reset in each line
nobu 2018-01-07 14:38:37 +0900 (Sun, 07 Jan 2018) New Revision: 61650 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61650 Log: eval_error.c: reset in each line * eval_error.c (print_errinfo): reset in each line, so that Exception#full_message ends with a newline and puts will not print an extra newline. Modified files: trunk/eval_error.c trunk/test/ruby/test_exception.rb Index: test/ruby/test_exception.rb =================================================================== --- test/ruby/test_exception.rb (revision 61649) +++ test/ruby/test_exception.rb (revision 61650) @@ -1113,6 +1113,9 @@ $stderr = $stdout; raise "\x82\xa0"') do https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1113 end def test_full_message + message = RuntimeError.new("testerror").full_message + assert_operator(message, :end_with?, "\n") + test_method = "def foo; raise 'testerror'; end" out1, err1, status1 = EnvUtil.invoke_ruby(['-e', "#{test_method}; begin; foo; rescue => e; puts e.full_message; end"], '', true, true) Index: eval_error.c =================================================================== --- eval_error.c (revision 61649) +++ eval_error.c (revision 61650) @@ -109,7 +109,9 @@ print_errinfo(const VALUE eclass, const https://github.com/ruby/ruby/blob/trunk/eval_error.c#L109 if (eclass == rb_eRuntimeError && elen == 0) { if (highlight) write_warn(str, underline); - write_warn(str, "unhandled exception\n"); + write_warn(str, "unhandled exception"); + if (highlight) write_warn(str, reset); + write_warn2(str, "\n", 1); } else { VALUE epath; @@ -118,34 +120,49 @@ print_errinfo(const VALUE eclass, const https://github.com/ruby/ruby/blob/trunk/eval_error.c#L120 if (elen == 0) { if (highlight) write_warn(str, underline); write_warn_str(str, epath); + if (highlight) write_warn(str, reset); write_warn(str, "\n"); } else { const char *tail = 0; long len = elen; + if (emesg == Qundef && highlight) write_warn(str, bold); if (RSTRING_PTR(epath)[0] == '#') epath = 0; if ((tail = memchr(einfo, '\n', elen)) != 0) { len = tail - einfo; tail++; /* skip newline */ + write_warn2(str, einfo, len); + } + else { + write_warn_str(str, emesg); } - write_warn_str(str, tail ? rb_str_subseq(emesg, 0, len) : emesg); if (epath) { write_warn(str, " ("); if (highlight) write_warn(str, underline); write_warn_str(str, epath); + if (highlight) { + write_warn(str, reset); + write_warn(str, bold); + } + write_warn2(str, ")", 1); if (highlight) write_warn(str, reset); - if (highlight) write_warn(str, bold); - write_warn(str, ")\n"); + write_warn2(str, "\n", 1); } if (tail) { - write_warn_str(str, rb_str_subseq(emesg, tail - einfo, elen - len - 1)); + if (highlight) { + if (einfo[elen-1] == '\n') --elen; + write_warn(str, bold); + } + write_warn2(str, tail, elen - len - 1); + } + if (tail ? (highlight || einfo[elen-1] != '\n') : !epath) { + if (highlight) write_warn(str, reset); + write_warn2(str, "\n", 1); } - if (tail ? einfo[elen-1] != '\n' : !epath) write_warn2(str, "\n", 1); } } - if (highlight) write_warn(str, reset); } static void -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/