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 170 171 172 173 174 175 176
|
# frozen_string_literal: true
require "test_helper"
module Byebug
#
# Tests commands which deal with backtraces.
#
class WhereStandardTest < TestCase
def program
strip_line_numbers <<-RUBY
1: module Byebug
2: #
3: # Toy class to test backtraces.
4: #
5: class #{example_class}
6: def initialize(l)
7: @letter = encode(l)
8: end
9:
10: def encode(str)
11: to_int(str + "x") + 5
12: end
13:
14: def to_int(str)
15: byebug
16: str.ord
17: end
18: end
19:
20: frame = #{example_class}.new("f")
21:
22: frame
23: end
RUBY
end
def test_where_displays_current_backtrace_with_fullpaths_by_default
enter "where"
debug_code(program)
expected_output = prepare_for_regexp <<-TXT
--> #0 #{example_full_class}.to_int(str#String) at #{example_path}:16
#1 #{example_full_class}.encode(str#String) at #{example_path}:11
#2 #{example_full_class}.initialize(l#String) at #{example_path}:7
ͱ-- #3 Class.new(*args) at #{example_path}:20
#4 <module:Byebug> at #{example_path}:20
#5 <top (required)> at #{example_path}:1
TXT
check_output_includes(*expected_output)
end
def test_where_displays_backtraces_using_long_callstyle_by_default
enter "where"
debug_code(program)
expected_output = prepare_for_regexp <<-TXT
--> #0 #{example_full_class}.to_int(str#String) at #{example_path}:16
#1 #{example_full_class}.encode(str#String) at #{example_path}:11
#2 #{example_full_class}.initialize(l#String) at #{example_path}:7
ͱ-- #3 Class.new\(*args) at #{example_path}:20
#4 <module:Byebug> at #{example_path}:20
#5 <top (required)> at #{example_path}:1
TXT
check_output_includes(*expected_output)
end
def test_where_displays_backtraces_using_short_callstyle
enter "set callstyle short", "where", "set callstyle long"
debug_code(program)
expected_output = prepare_for_regexp <<-TXT
--> #0 to_int(str) at #{example_path}:16
#1 encode(str) at #{example_path}:11
#2 initialize(l) at #{example_path}:7
ͱ-- #3 new(*args) at #{example_path}:20
#4 <module:Byebug> at #{example_path}:20
#5 <top (required)> at #{example_path}:1
TXT
check_output_includes(*expected_output)
end
def test_where_displays_instance_exec_block_frames
enter "where"
program = strip_line_numbers <<-RUBY
1: module Byebug
2: class #{example_full_class}
3: def foo
4: Object.new.instance_exec do
5: byebug
6: end
7: end
8: end
9:
10: #{example_full_class}.new.foo
11: end
RUBY
debug_code(program)
expected_output = prepare_for_regexp <<-TXT
--> #0 block in #{example_full_class}.block in foo at #{example_path}:6
#1 BasicObject.instance_exec(*args) at #{example_path}:4
#2 #{example_full_class}.foo at #{example_path}:4
#3 <module:Byebug> at #{example_path}:10
#4 <top (required)> at #{example_path}:1
TXT
check_output_includes(*expected_output)
end
end
#
# Tests dealing with backtraces when the path being debugged is not deeply
# nested.
#
# @note We skip this tests in Windows since the paths in this CI environment
# are usually very deeply nested and on OS X where tmp path is always
# deeply nested.
#
unless /cygwin|mswin|mingw|darwin/.match?(RUBY_PLATFORM)
class WhereWithNotDeeplyNestedPathsTest < WhereStandardTest
def test_where_displays_current_backtrace_w_shorpaths_if_fullpath_disabled
enter "set nofullpath", "where", "set fullpath"
debug_code(program)
expected_output = prepare_for_regexp <<-TXT
--> #0 #{example_full_class}.to_int(str#String) at #{example_path}:16
#1 #{example_full_class}.encode(str#String) at #{example_path}:11
#2 #{example_full_class}.initialize(l#String) at #{example_path}:7
ͱ-- #3 Class.new(*args) at #{example_path}:20
#4 <module:Byebug> at #{example_path}:20
#5 <top (required)> at #{example_path}:1
TXT
check_output_includes(*expected_output)
end
end
end
#
# Tests dealing with backtraces when the path being debugged is deeply nested.
#
class WhereWithDeeplyNestedPathsTest < WhereStandardTest
def setup
@example_parent_folder = Dir.mktmpdir(nil)
@example_folder = File.realpath(Dir.mktmpdir(nil, @example_parent_folder))
super
end
def teardown
super
FileUtils.remove_dir(@example_parent_folder, true)
end
def test_where_displays_current_backtrace_w_shorpaths_if_fullpath_disabled
enter "set nofullpath", "where", "set fullpath"
debug_code(program)
expected_output = prepare_for_regexp <<-TXT
--> #0 #{example_full_class}.to_int(str#String) at ...
#1 #{example_full_class}.encode(str#String) at ...
#2 #{example_full_class}.initialize(l#String) at ...
ͱ-- #3 Class.new(*args) at ...
#4 <module:Byebug> at ...
#5 <top (required)> at ...
TXT
check_output_includes(*expected_output)
end
end
end
|