summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eval_error.c14
-rw-r--r--test/ruby/test_exception.rb12
2 files changed, 14 insertions, 12 deletions
diff --git a/eval_error.c b/eval_error.c
index d909125fbd..d630f47014 100644
--- a/eval_error.c
+++ b/eval_error.c
@@ -153,14 +153,16 @@ print_errinfo(const VALUE eclass, const VALUE errat, const VALUE emesg, const VA
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);
}
}
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index 6532fecea9..feda30644f 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -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)
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