Skip to content

Commit

Permalink
Stop Byebug after continue
Browse files Browse the repository at this point in the history
to optimize performance for the case you use no breakpoints or
catchpoints.
  • Loading branch information
k0kubun committed Oct 10, 2015
1 parent 72fff22 commit fc1eb51
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
4 changes: 4 additions & 0 deletions lib/byebug/commands/continue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def execute
end

processor.proceed!
ensure
if Byebug.catchpoints.empty? && Byebug.breakpoints.empty?
Byebug.stop
end
end
end
end
10 changes: 8 additions & 2 deletions test/commands/continue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ def program
def test_continues_until_the_end_if_no_line_specified_and_no_breakpoints
enter 'continue'

debug_code(program) { assert_program_finished }
debug_without_byebug_stop(program) { assert_program_finished }
end

def test_stops_byebug_after_continue
enter 'continue'

debug_code(program) { assert_equal false, Byebug.started? }
end

def test_continues_up_to_breakpoint_if_no_line_specified
Expand All @@ -53,7 +59,7 @@ def test_continues_up_to_the_specified_line
def test_ignores_the_command_if_specified_line_is_not_valid
enter 'cont 100'

debug_code(program) { assert_equal 13, frame.line }
debug_without_byebug_stop(program) { assert_equal 13, frame.line }
end

def test_shows_error_if_specified_line_is_not_valid
Expand Down
4 changes: 2 additions & 2 deletions test/commands/interrupt_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def program
def test_interrupt_stops_at_the_next_statement
enter 'interrupt', 'continue'

debug_code(program) { assert_equal 6, frame.line }
debug_without_byebug_stop(program) { assert_equal 6, frame.line }
end

def test_interrupt_steps_into_blocks
enter 'next', 'interrupt', 'continue'

debug_code(program) { assert_equal 7, frame.line }
debug_without_byebug_stop(program) { assert_equal 7, frame.line }
end
end
end
2 changes: 1 addition & 1 deletion test/post_mortem_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_execution_is_stopped_at_the_correct_line_after_exception
enter 'cont'

begin
debug_code(program)
debug_without_byebug_stop(program)
rescue
assert_equal 7, Byebug.raised_exception.__bb_context.frame.line
end
Expand Down
2 changes: 1 addition & 1 deletion test/processors/command_processor_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_subdebugger_stops_at_correct_point_when_invoked_from_breakpoint
def test_subdebugger_goes_back_to_previous_debugger_after_continue
enter "#{example_class}.a", 'continue'

debug_code(program) { assert_equal 13, frame.line }
debug_without_byebug_stop(program) { assert_equal 13, frame.line }
end
end

Expand Down
17 changes: 17 additions & 0 deletions test/support/utils.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative 'matchers'
require 'minitest/mock'

module Byebug
#
Expand Down Expand Up @@ -59,6 +60,22 @@ def debug_code(program, &block)
interface.test_block.call if interface.test_block
end

#
# Runs the code block passed as a string preventing Byebug.stop.
#
# If there are no breakpoints or catchpoints, Byebug will stop and you can
# no longer get Byebug.current_context. This is a helper to test such a
# situation.
#
# @param program [String] Ruby code to be debugged
# @param &block proc which will be executed with Byebug.stop stubbed
#
def debug_without_byebug_stop(program, &block)
Byebug.stub(:stop, true) do
debug_code(program, &block)
end
end

#
# Writes a string containing Ruby code to a file and then debugs that file.
#
Expand Down

0 comments on commit fc1eb51

Please sign in to comment.