diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-07 05:38:37 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-01-07 05:38:37 +0000 |
commit | 89f041957548302af46d71e3c97fa58415677c8a (patch) | |
tree | bd458239934fc1c7a5ae17e3dcba270a891be1ed | |
parent | ac4d348d458defd030c548f608e0b0882a9c705a (diff) | |
download | ruby-89f041957548302af46d71e3c97fa58415677c8a.tar.gz |
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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61650 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | eval_error.c | 31 | ||||
-rw-r--r-- | test/ruby/test_exception.rb | 3 |
2 files changed, 27 insertions, 7 deletions
diff --git a/eval_error.c b/eval_error.c index 4b7e761742..26e2efd15e 100644 --- a/eval_error.c +++ b/eval_error.c @@ -109,7 +109,9 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, const VA 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 VALUE errat, const VALUE emesg, const VA 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 diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 386d736d16..98462bef93 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -1113,6 +1113,9 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| 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) |