Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix continue! with byebug calls #546

Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

* [#546](https://github.com/deivid-rodriguez/byebug/pull/546): `continue!` to ignore further `byebug` calls.

## [11.0.0] - 2019-02-15

### Added
Expand Down
6 changes: 3 additions & 3 deletions lib/byebug/attacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module Byebug
# Starts byebug, and stops at the first line of user's code.
#
def self.attach
require "byebug/core"

unless started?
self.mode = :attached

Expand All @@ -35,7 +33,9 @@ def self.spawn(host = "localhost", port = nil)
#
module Kernel
def byebug
Byebug.attach
require "byebug/core"

Byebug.attach unless Byebug.mode == :off
end

def remote_byebug(host = "localhost", port = nil)
Expand Down
1 change: 1 addition & 0 deletions lib/byebug/commands/continue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def execute

processor.proceed!

Byebug.mode = :off if unconditionally?
Byebug.stop if unconditionally? || Byebug.stoppable?
end

Expand Down
1 change: 1 addition & 0 deletions lib/byebug/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module Byebug
#
# * :attached => Attached to a running program through the `byebug` method.
# * :standalone => Started through `byebug` script.
# * :off => Ignoring any `byebug` method calls.
#
attr_accessor :mode

Expand Down
46 changes: 42 additions & 4 deletions test/commands/continue_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@ def test_continues_until_the_end_if_no_line_specified_and_no_breakpoints
end

def test_continues_until_the_end_if_used_with_bang
enter "break 14", "continue!"
with_mode(:attached) do
enter "break 14", "continue!"

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

def test_continues_until_the_end_if_used_with_unconditionally
enter "break 14", "continue unconditionally"
with_mode(:attached) do
enter "break 14", "continue unconditionally"

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

def test_stops_byebug_after_continue
Expand Down Expand Up @@ -102,4 +106,38 @@ def test_linetrace_does_not_show_a_line_in_eval_context
end
end
end

class ContinueUnconditionallyWithByebugCallsTest < TestCase
def program
strip_line_numbers <<-RUBY
1: module Byebug
2: byebug
3:
4: b = 5
5:
6: byebug
7:
8: c = b + 5
9:
10: d = c + 5
11: end
RUBY
end

def test_continues_until_the_end_ignoring_byebug_calls_if_used_with_bang
with_mode(:attached) do
enter "continue!"

debug_code(program) { assert_program_finished }
end
end

def test_continues_until_the_end_ignoring_byebug_calls_if_used_with_unconditionally
with_mode(:attached) do
enter "continue unconditionally"

debug_code(program) { assert_program_finished }
end
end
end
end
26 changes: 26 additions & 0 deletions test/runner_against_program_with_byebug_call_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require "test_helper"

module Byebug
#
# Tests standalone byebug when debugging a target program
#
class RunnerAgainstProgramWithByebugCallTest < TestCase
def setup
super

example_file.write("require 'byebug'\nbyebug\nsleep 0")
example_file.close
end

def test_run_with_a_script_to_debug
stdout = run_program(
["ruby", example_path],
'puts "Program: #{$PROGRAM_NAME}"'
)

assert_match(/Program: #{example_path}/, stdout)
end
end
end