debug icon indicating copy to clipboard operation
debug copied to clipboard

test code notation with break

Open ko1 opened this issue 3 years ago • 2 comments

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 avatar Mar 11 '22 06:03 ko1

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).

ko1 avatar Mar 11 '22 06:03 ko1

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.

st0012 avatar Apr 10 '22 11:04 st0012