File: info_test.rb

package info (click to toggle)
ruby-byebug 11.1.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,220 kB
  • sloc: ruby: 8,835; ansic: 1,662; sh: 6; makefile: 4
file content (253 lines) | stat: -rw-r--r-- 7,084 bytes parent folder | download | duplicates (3)
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# frozen_string_literal: true

require "test_helper"

module Byebug
  #
  # Test info command.
  #
  class InfoTest < TestCase
    def program
      strip_line_numbers <<-RUBY
         1:  module Byebug
         2:    #
         3:    # Toy class to test information about files.
         4:    #
         5:    class #{example_class}
         6:      def initialize
         7:        @foo = "bar"
         8:        @bla = "blabla"
         9:      end
        10:
        11:      def a(y, z)
        12:        w = "1" * 45
        13:        x = 2
        14:        w + x.to_s + y + z + @foo
        15:      end
        16:
        17:      def b
        18:        a("a", "b")
        19:        e = "%.2f"
        20:        e
        21:      end
        22:    end
        23:
        24:    byebug
        25:    i = #{example_class}.new
        26:    i.b
        27:  end
      RUBY
    end

    def test_info_breakpoints_shows_information_about_all_breakpoints
      enter "break 12", "break 13 if x == w", "info breakpoints"
      debug_code(program)

      check_output_includes "Num Enb What",
                            /\d+ +y   at #{example_path}:12/,
                            /\d+ +y   at #{example_path}:13 if x == w/
    end

    def test_info_breakpoints_with_ids_shows_information_on_specific_breakpoints
      enter "b 12", "b 13", -> { "info breakpoints #{Breakpoint.first.id}" }
      debug_code(program)

      check_output_includes "Num Enb What", /\d+ +y   at #{example_path}:12/
      check_output_doesnt_include(/\d+ +y   at #{example_path}:13/)
    end

    def test_info_breakpoints_shows_a_message_when_no_breakpoints_found
      enter "info breakpoints"
      debug_code(program)

      check_output_includes "No breakpoints."
    end

    def test_info_breakpoints_shows_error_if_specific_breakpoint_do_not_exist
      enter "break 12", "break 13", "delete 100", "info breakpoints 100"
      debug_code(program)

      check_error_includes "No breakpoints found among list given"
    end

    def test_info_breakpoints_shows_hit_counts
      enter "break 12", "cont", "info breakpoints"
      debug_code(program)

      check_output_includes(/\d+ +y   at #{example_path}:12/,
                            "breakpoint already hit 1 time")
    end

    def test_info_display_shows_all_display_expressions
      enter "display 3 + 3", "display a + b", "info display"
      debug_code(program) { clear_displays }

      check_output_includes "Auto-display expressions now in effect:",
                            "Num Enb Expression",
                            "1: y  3 + 3",
                            "2: y  a + b"
    end

    def test_info_display_shows_a_message_when_no_display_expressions_found
      enter "info display"
      debug_code(program)

      check_output_includes "There are no auto-display expressions now."
    end

    def test_info_line_shows_info_about_the_current_line
      enter "break 12", "cont", "info line"
      debug_code(program)

      check_output_includes "Line 12 of \"#{example_path}\""
    end

    def test_info_program_shows_the_initial_stop_reason
      enter "info program"
      debug_code(program)

      check_output_includes \
        "It stopped after stepping, next'ing or initial start."
    end

    def test_info_program_shows_the_step_stop_reason
      enter "step", "info program"
      debug_code(program)

      check_output_includes \
        "Program stopped.",
        "It stopped after stepping, next'ing or initial start."
    end

    def test_info_program_shows_the_breakpoint_stop_reason
      enter "break 12", "cont", "info program"
      debug_code(program)

      check_output_includes "Program stopped.", "It stopped at a breakpoint."
    end

    def test_info_alone_shows_help
      enter "info", "cont"
      debug_code(program)

      check_output_includes \
        "Shows several informations about the program being debugged"
    end
  end

  #
  # Tests "info file" command
  #
  class InfoFileTest < TestCase
    def program
      strip_line_numbers <<-RUBY
        1:  module Byebug
        2:    byebug
        3:    3
        4:  end
      RUBY
    end

    def test_info_file_shows_basic_info_about_current_file
      enter "info file"
      debug_code(program)

      check_output_includes "File #{example_path} (4 lines)"
    end

    def test_info_file_with_a_file_name_shows_basic_info_about_a_specific_file
      with_new_tempfile("sleep 0") do |script_name|
        enter "info file #{script_name}"
        debug_code(program)

        check_output_includes "File #{script_name} (1 line)"
      end
    end

    def test_info_file_shows_mtime_of_current_file
      enter "info file"
      debug_code(program)

      check_output_includes \
        "Modification time: #{File.stat(example_path).mtime}"
    end

    def test_info_file_w_filename_shows_mtime_of_filename
      with_new_tempfile("sleep 0") do |script_name|
        enter "info file #{script_name}"
        debug_code(program)

        check_output_includes \
          "Modification time: #{File.stat(script_name).mtime}"
      end
    end

    def test_info_file_shows_sha1_signature_of_current_file
      enter "info file"
      debug_code(program)

      check_output_includes \
        "Sha1 Signature: #{Digest::SHA1.hexdigest(example_path)}"
    end

    def test_info_file_w_filename_shows_sha1_signature_of_filename
      with_new_tempfile("sleep 0") do |script_name|
        enter "info file #{script_name}"
        debug_code(program)

        check_output_includes \
          "Sha1 Signature: #{Digest::SHA1.hexdigest(script_name)}"
      end
    end

    def test_info_file_shows_potential_breakpoint_lines_in_current_file
      enter "info file"
      debug_code(minimal_program)

      check_output_includes "Breakpoint line numbers: 1 2 4 5"
    end

    def test_info_file_w_filename_shows_potential_breakpoint_lines_in_filename
      with_new_tempfile("sleep 0") do |script_name|
        enter "info file #{script_name}"
        debug_code(program)

        check_output_includes "Breakpoint line numbers: 1"
      end
    end

    def test_info_file_does_not_show_any_info_if_filename_is_invalid
      enter "info file blabla"
      debug_code(program)

      check_error_includes "blabla is not a valid source file"
    end

    def test_info_file_with_a_file_name_with_space_doesnt_fail
      enter "info file /filename/with space"
      debug_code(program)

      check_error_includes "/filename/with space is not a valid source file"
    end
  end

  #
  # Tests info command on crashed programs
  #
  class InfoCrashedTest < TestCase
    def program_raising
      strip_line_numbers <<-RUBY
        byebug

        fail "Bang"
      RUBY
    end

    def test_info_program_shows_the_catchpoint_stop_reason_for_crashed_programs
      enter "catch RuntimeError", "cont", "info program", "catch off", "y"

      assert_raises(RuntimeError) { debug_code(program_raising) }
      check_output_includes "Program stopped.", "It stopped at a catchpoint."
    end
  end
end