diff --git a/CHANGELOG.md b/CHANGELOG.md index 2dcdb8849..87e83c023 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Fixed * [#546](https://github.com/deivid-rodriguez/byebug/pull/546): `continue!` to ignore further `byebug` calls. +* [#545](https://github.com/deivid-rodriguez/byebug/pull/545): `skip` autolisting code for intermediate skipped breakpoints. ## [11.0.0] - 2019-02-15 diff --git a/lib/byebug/commands/skip.rb b/lib/byebug/commands/skip.rb index d036117a3..a01cc6434 100644 --- a/lib/byebug/commands/skip.rb +++ b/lib/byebug/commands/skip.rb @@ -13,6 +13,7 @@ class SkipCommand < Command class << self attr_writer :file_line, :file_path + attr_reader :previous_autolist def file_line @file_line ||= 0 @@ -21,6 +22,16 @@ def file_line def file_path @file_path ||= "" end + + def setup_autolist(value) + @previous_autolist = ListCommand.always_run + ListCommand.always_run = value + end + + def restore_autolist + ListCommand.always_run = @previous_autolist + @previous_autolist = nil + end end def self.regexp @@ -41,6 +52,7 @@ def self.short_description def initialize_attributes self.class.always_run = 2 + self.class.setup_autolist(0) self.class.file_path = frame.file self.class.file_line = frame.line end @@ -51,6 +63,8 @@ def keep_execution def reset_attributes self.class.always_run = 0 + ListCommand.new(processor).execute if self.class.previous_autolist == 1 + self.class.restore_autolist end def auto_run diff --git a/test/commands/skip_test.rb b/test/commands/skip_test.rb index 2e16e7e3d..ed0f32ec0 100644 --- a/test/commands/skip_test.rb +++ b/test/commands/skip_test.rb @@ -17,16 +17,17 @@ def program 6: def factor(num) 7: i = 1 8: num.times do |new_number| - 9: i *= new_number - 10: byebug + 9: byebug + 10: i *= new_number 11: end 12: end 13: end 14: c = 5 15: 16: result = #{example_class}.new.factor(c) - 17: "Result is: " + result.to_s - 18: end + 17: sleep 0 + 18: "Result is: " + result.to_s + 19: end RUBY end @@ -41,5 +42,25 @@ def test_works_in_abbreviated_mode_too debug_code(program) { assert_location example_path, 17 } end + + def test_does_not_list_code_for_intermediate_breakpoints + enter "break 17", "skip" + + debug_code(program) + + check_output_includes "=> 10: i *= new_number" + check_output_doesnt_include "=> 10: i *= new_number", "=> 10: i *= new_number" + check_output_includes "=> 17: sleep 0" + end + + def test_restores_previous_autolisting_after_skip + with_setting :autolist, false do + enter "break 17", "skip", "continue 18" + + debug_code(program) + + check_output_doesnt_include '=> 18: "Result is: " + result.to_s' + end + end end end