Skip to content

Commit

Permalink
Command continue_breakpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
renatocassino committed Jan 4, 2019
1 parent 66a998f commit cd943d0
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 62 deletions.
Binary file added byebug-10.0.2.gem
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/byebug/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require "byebug/commands/catch"
require "byebug/commands/condition"
require "byebug/commands/continue"
require "byebug/commands/continue_always"
require "byebug/commands/continue_breakpoint"
require "byebug/commands/debug"
require "byebug/commands/delete"
require "byebug/commands/disable"
Expand Down
39 changes: 0 additions & 39 deletions lib/byebug/commands/continue_always.rb

This file was deleted.

75 changes: 75 additions & 0 deletions lib/byebug/commands/continue_breakpoint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true

require "byebug/command"
require "byebug/helpers/parse"

module Byebug
#
# Allows the user to continue execution until the next breakpoint, if
# the breakpoint file or line be different, stop again
#
class ContinueBreakpointCommand < Command
include Helpers::ParseHelper

class << self
attr_writer :file_line, :file_path

def file_line=(file_line)
@file_line = file_line
end

def file_line
@file_line
end

def file_path=(file_path)
@file_path = file_path
end

def file_path
@file_path
end
end

def self.regexp
/^\s* c(?:ont(?:inue)?_)?(?:b(?:reak(?:point)?)?) \s*$/x
end

def self.description
<<-DESCRIPTION
c[ont[inue]_]b[reak[point]]
#{short_description}
DESCRIPTION
end

def self.short_description
"Runs until the same breakpoint, if breakpoint change stop again"
end

def keep_execution(file, line)
[self.class.file_path, self.class.file_line] === [file, line]
end

def reset_attributes
self.class.always_run = 0
end

def auto_run(frame)
return false unless self.class.always_run == 2

keep_execution(frame.file, frame.line) ? processor.proceed! : reset_attributes
true
end

def execute
return if auto_run frame

self.class.always_run = 2
self.class.file_path = frame.file
self.class.file_line = frame.line

processor.proceed!
Byebug.stop if Byebug.stoppable?
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module Byebug
#
# Tests for continue command
#
class ContinueAlwaysTest < TestCase
class ContinueBreakpointTest < TestCase
def program
strip_line_numbers <<-RUBY
1: module Byebug
2: #
3: # Toy class to test continue command.
3: # Toy class to test continue_breakpoint command.
4: #
5: class #{example_class}
6: def factor(num)
Expand All @@ -31,30 +31,16 @@ def program
RUBY
end

def reset_commands
ContinueAlwaysCommand.always_run = 0
ListCommand.always_run = 1
end

def test_continues_and_never_stop_again
enter "continue!"

debug_code(program) { assert_program_finished }
reset_commands
end

def test_continues_and_never_stop_using_abbreviation
enter "c!"
def test_continues_until_the_end_if_no_line_specified_and_no_breakpoints
enter 'continue_breakpoint'

debug_code(program) { assert_program_finished }
reset_commands
debug_code(program) { assert_location example_path, 18 }
end

def test_continues_and_never_stop_using_another_abbreviation
enter "cont!"
def test_works_in_abbreviated_mode_too
enter "cb"

debug_code(program) { assert_program_finished }
reset_commands
debug_code(program) { assert_location example_path, 18 }
end
end
end

0 comments on commit cd943d0

Please sign in to comment.