Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/irb/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ def IRB.init_config(ap_path)
@CONF[:MEASURE_PROC] = {}
@CONF[:MEASURE_PROC][:TIME] = proc { |context, code, line_no, &block|
time = Time.now
result = block.()
now = Time.now
puts 'processing time: %fs' % (now - time) if IRB.conf[:MEASURE]
begin
result = block.()
ensure
now = Time.now
puts 'processing time: %fs' % (now - time) if IRB.conf[:MEASURE]
end
result
}
# arg can be either a symbol for the mode (:cpu, :wall, ..) or a hash for
Expand Down
11 changes: 11 additions & 0 deletions test/irb/test_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ def test_nobanner
assert_equal(false, IRB.conf[:SHOW_BANNER])
end

def test_measure_when_exception_occurs
out, err = execute_lines(
"measure\n",
"raise 'boom'\n"
)

assert_empty err
assert_match(/processing time: \d+\.\d+s/, out)
assert_match(/boom \(RuntimeError\)/, out)
end

private

def with_argv(argv)
Expand Down