1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
# frozen_string_literal: true
require "test_helper"
#
# Some common specs for breakpoints
#
module BreakpointSpecs
def test_shows_breakpoint_enabled
assert_match @regexp, @output.string
end
def test_shows_breakpoint_hit
assert_match @regexp, @output.string
match = @output.string.match(@regexp)
assert_match(/^ Breakpoint #{match[:id]}\. First hit/, @output.string)
end
def test_shows_breakpoint_line
assert_match(/\=> \s*#{@line}:/, @output.string)
end
end
#
# Tests for breakpoint commands
#
class BreakpointsTest < Minitest::Test
def setup
super
@input = InputTester.new "break --delete-all"
@output = StringIO.new
end
def teardown
super
clean_remove_const(:Break1Example)
clean_remove_const(:Break2Example)
end
def width
Byebug.breakpoints.last.id.to_s.length
end
end
#
# Tests setting a breakpoint by line number
#
class SettingBreakpointsTestByLineNumber < BreakpointsTest
def setup
super
@input.add("break 8")
redirect_pry_io(@input, @output) { load test_file("break1") }
@line = 8
@regexp = / Breakpoint (?<id>\d+): #{test_file('break1')} @ 8 \(Enabled\)/
end
include BreakpointSpecs
end
#
# Tests setting a breakpoint in a method
#
class SettingBreakpointsTestByMethodId < BreakpointsTest
def setup
super
@input.add("break Break1Example#a")
redirect_pry_io(@input, @output) { load test_file("break1") }
@line = RUBY_VERSION >= "2.5.0" ? 8 : 7
@regexp = / Breakpoint (?<id>\d+): Break1Example#a \(Enabled\)/
end
include BreakpointSpecs
end
#
# Tests setting a breakpoint in a bang method
#
class SettingBreakpointsTestByMethodIdForBangMethods < BreakpointsTest
def setup
super
@input.add("break Break1Example#c!")
redirect_pry_io(@input, @output) { load test_file("break1") }
@line = RUBY_VERSION >= "2.5.0" ? 18 : 17
@regexp = / Breakpoint (?<id>\d+): Break1Example#c! \(Enabled\)/
end
include BreakpointSpecs
end
#
# Tests setting a breakpoint in a (non fully qualified) method
#
class SettingBreakpointsTestByMethodIdWithinContext < BreakpointsTest
def setup
super
@input.add("break #b")
redirect_pry_io(@input, @output) { load test_file("break2") }
@line = 9
@regexp = / Breakpoint (?<id>\d+): Break2Example#b \(Enabled\)/
end
include BreakpointSpecs
end
#
# Tests listing breakpoints
#
class ListingBreakpoints < BreakpointsTest
def setup
super
@input.add("break #b", "break")
redirect_pry_io(@input, @output) { load test_file("break2") }
end
def test_shows_all_breakpoints
assert_match(/Yes \s*Break2Example#b/, @output.string)
end
def test_properly_displays_breakpoint_list
assert_match(/ {#{width - 1}}# Enabled At/, @output.string)
assert_match(/ \d{#{width}} Yes Break2Example#b/, @output.string)
end
end
#
# Tests disabling breakpoints
#
class DisablingBreakpoints < BreakpointsTest
def setup
super
@input.add("break #b", "break --disable-all")
redirect_pry_io(@input, @output) { load test_file("break2") }
end
def test_shows_breakpoints_as_disabled
assert_match(/ {#{width - 1}}# Enabled At/, @output.string)
assert_match(/ \d{#{width}} No Break2Example#b/, @output.string)
end
end
#
# Tests that the break Ruby keyword does not conflict with the break command
#
class BreakInsideMultilineInput < BreakpointsTest
def setup
super
@input.add("2.times do |i|", "break 18 if i > 0", "end")
redirect_pry_io(@input, @output) { load test_file("break1") }
end
def test_it_is_ignored
assert_equal 0, Pry::Byebug::Breakpoints.size
end
def test_lets_input_be_properly_evaluated
assert_match(/=> 18/, @output.string)
end
end
|