ruby / debug

Debugging functionality for Ruby
BSD 2-Clause "Simplified" License
1.12k stars 122 forks source link

test code notation with break #557

Open ko1 opened 2 years ago

ko1 commented 2 years ago

Just idea.

Now we need to set breakpoints with break commands on tests like:

    def program
      <<~RUBY
       1| def foo a
       2|   b = a + 1  # break
       3| end
       4| x = 1        # break
       5| x = 2
       6| x = 3
      RUBY
    end

    def test_foobar
      debug_code program do
        type 'break 2'
        type 'break 4'

On this code, line 2 and 4 is breakpont, and using 2 break commands. On the other hands, if we use IDE we can set breakpoints on a code (with editor's support). So we can write breakpoints on the code.

IDEA1: Use comment on the line.

      <<~RUBY
       1| def foo a
       2|   b = a + 1  # break
       3| end
       4| x = 1        # break
       5| x = 2
       6| x = 3
      RUBY

and issues two break commands by the test framework.

IDEA2: Check on the left of line number:

      <<~RUBY
       1| def foo a
      *2|   b = a + 1
       3| end
      *4| x = 1
       5| x = 2
       6| x = 3
      RUBY

and issues two break commands by the test framework.


Of course we can write debugger method, but it can be different from normal break points, so it should be supported separately.

ko1 commented 2 years ago

We can enhance this idea for normal Ruby programming by parsing the source code (with IDEA 1), but it's too much and almost case debugger method is enough. The difference between break command and debugger method is we can control (add/delete) breakpoints added by break commands (we can not delete deubgger method on a running process).

st0012 commented 2 years ago

I like the IDEA 1 better but only for debugger tests. I think putting breakpoint comment in the code will cause more trouble than convenience. For example: users may need to exit other people's breakpoint comments before entering the one they set.