File: continue_test.rb

package info (click to toggle)
ruby-byebug 13.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,288 kB
  • sloc: ruby: 9,013; ansic: 1,692; makefile: 4; sh: 4
file content (154 lines) | stat: -rw-r--r-- 3,757 bytes parent folder | download
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
# frozen_string_literal: true

require "test_helper"

module Byebug
  #
  # Tests for continue command
  #
  class ContinueTest < TestCase
    def program
      strip_line_numbers <<-RUBY
         1:  module Byebug
         2:    #
         3:    # Toy class to test continue command.
         4:    #
         5:    class #{example_class}
         6:      def add_four(num)
         7:        num + 4
         8:      end
         9:    end
        10:
        11:    byebug
        12:
        13:    b = 5
        14:    c = b + 5
        15:    #{example_class}.new.add_four(c)
        16:    eval("c")
        17:  end
      RUBY
    end

    def test_continues_until_the_end_if_no_line_specified_and_no_breakpoints
      enter "continue"

      debug_code(program) { assert_program_finished }
    end

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

        debug_code(program) { assert_program_finished }
      end
    end

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

        debug_code(program) { assert_program_finished }
      end
    end

    def test_stops_byebug_after_continue
      enter "continue"

      debug_code(program) { assert_equal false, Byebug.started? }
    end

    def test_continues_up_to_breakpoint_if_no_line_specified
      enter "break 14", "continue"

      debug_code(program) { assert_equal 14, frame.line }
    end

    def test_works_in_abbreviated_mode_too
      enter "break 14", "cont"

      debug_code(program) { assert_equal 14, frame.line }
    end

    def test_continues_up_to_the_specified_line
      enter "cont 14"

      debug_code(program) { assert_equal 14, frame.line }
    end

    def test_ignores_the_command_if_specified_line_is_not_valid
      enter "cont 100"

      debug_code(program) { assert_equal 13, frame.line }
    end

    def test_shows_error_if_specified_line_is_not_valid
      enter "cont 100"
      debug_code(program)

      check_error_includes "Line 100 is not a valid stopping point in file"
    end

    def test_tracing_after_set_linetrace_and_continue
      with_setting :linetrace, false do
        enter "set linetrace", "cont"
        debug_code(program)

        check_output_includes "Tracing: #{example_path}:14   c = b + 5"
      end
    end

    if Gem.ruby_version < Gem::Version.new("3.3.a")
      def test_linetrace_does_not_show_a_line_in_eval_context
        with_setting :linetrace, true do
          enter "cont"
          debug_code(program)

          check_output_includes "Tracing: (eval):1"
        end
      end
    else
      def test_linetrace_shows_a_line_in_eval_context
        with_setting :linetrace, true do
          enter "cont"
          debug_code(program)

          check_output_includes "Tracing: (eval at #{example_path}:16):1"
        end
      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