diff --git a/lib/irb/init.rb b/lib/irb/init.rb index f933f5cec..7a16d922a 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -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 diff --git a/test/irb/test_init.rb b/test/irb/test_init.rb index b68681e38..1e2e63d0a 100644 --- a/test/irb/test_init.rb +++ b/test/irb/test_init.rb @@ -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)