diff --git a/src/nvim/testdir/test_debugger.vim b/src/nvim/testdir/test_debugger.vim index db18f7695d..c923b22836 100644 --- a/src/nvim/testdir/test_debugger.vim +++ b/src/nvim/testdir/test_debugger.vim @@ -38,10 +38,13 @@ func Test_Debugger() \ ' return var2', \ 'endfunc', \ 'func Bazz(var)', - \ ' let var1 = 3 + a:var', - \ ' let var3 = "another var"', - \ ' let var3 = "value2"', - \ ' let var3 = "value3"', + \ ' try', + \ ' let var1 = 3 + a:var', + \ ' let var3 = "another var"', + \ ' let var3 = "value2"', + \ ' catch', + \ ' let var4 = "exception"', + \ ' endtry', \ ' return var1', \ 'endfunc'], 'Xtest.vim') @@ -58,13 +61,14 @@ func Test_Debugger() call RunDbgCmd(buf, 'step') call RunDbgCmd(buf, 'step') call RunDbgCmd(buf, 'step') + call RunDbgCmd(buf, 'step') " check backtrace call RunDbgCmd(buf, 'backtrace', [ \ ' 2 function Foo[2]', \ ' 1 Bar[2]', \ '->0 Bazz', - \ 'line 2: let var3 = "another var"']) + \ 'line 3: let var3 = "another var"']) " Check variables in different stack frames call RunDbgCmd(buf, 'echo var1', ['6']) @@ -74,7 +78,7 @@ func Test_Debugger() \ ' 2 function Foo[2]', \ '->1 Bar[2]', \ ' 0 Bazz', - \ 'line 2: let var3 = "another var"']) + \ 'line 3: let var3 = "another var"']) call RunDbgCmd(buf, 'echo var1', ['3']) call RunDbgCmd(buf, 'u') @@ -82,7 +86,7 @@ func Test_Debugger() \ '->2 function Foo[2]', \ ' 1 Bar[2]', \ ' 0 Bazz', - \ 'line 2: let var3 = "another var"']) + \ 'line 3: let var3 = "another var"']) call RunDbgCmd(buf, 'echo var1', ['1']) " Undefined variables @@ -90,7 +94,7 @@ func Test_Debugger() call RunDbgCmd(buf, 'frame 2') call RunDbgCmd(buf, 'echo var3', [ \ 'Error detected while processing function Foo[2]..Bar[2]..Bazz:', - \ 'line 3:', + \ 'line 4:', \ 'E121: Undefined variable: var3']) " var3 is defined in this level with some other value @@ -98,9 +102,10 @@ func Test_Debugger() call RunDbgCmd(buf, 'echo var3', ['another var']) call RunDbgCmd(buf, 'step') - call RunDbgCmd(buf, 'step') - call RunDbgCmd(buf, 'step') - call RunDbgCmd(buf, 'step') + call RunDbgCmd(buf, '') + call RunDbgCmd(buf, '') + call RunDbgCmd(buf, '') + call RunDbgCmd(buf, '') call RunDbgCmd(buf, 'step', [ \ 'function Foo[2]..Bar', \ 'line 3: End of function']) @@ -189,7 +194,7 @@ func Test_Debugger() call RunDbgCmd(buf, 'cont', [ \ 'Breakpoint in "Bazz" line 3', \ 'function Foo[2]..Bar[2]..Bazz', - \ 'line 3: let var3 = "value2"']) + \ 'line 3: let var3 = "another var"']) " Delete the breakpoints call RunDbgCmd(buf, 'breakd 1') @@ -207,23 +212,100 @@ func Test_Debugger() " Expression breakpoint call RunDbgCmd(buf, ':breakadd func 2 Bazz') - call RunDbgCmd(buf, ':echo Bazz(1)') + call RunDbgCmd(buf, ':echo Bazz(1)', [ + \ 'Entering Debug mode. Type "cont" to continue.', + \ 'function Bazz', + \ 'line 2: let var1 = 3 + a:var']) + call RunDbgCmd(buf, 'step') call RunDbgCmd(buf, 'step') call RunDbgCmd(buf, 'breaka expr var3') - call RunDbgCmd(buf, 'breakl', [' 4 expr var3']) - call RunDbgCmd(buf, 'cont', ['Breakpoint in "Bazz" line 4', + call RunDbgCmd(buf, 'breakl', [' 3 func Bazz line 2', + \ ' 4 expr var3']) + call RunDbgCmd(buf, 'cont', ['Breakpoint in "Bazz" line 5', \ 'Oldval = "''another var''"', \ 'Newval = "''value2''"', \ 'function Bazz', - \ 'line 4: let var3 = "value3"']) + \ 'line 5: catch']) call RunDbgCmd(buf, 'breakdel *') call RunDbgCmd(buf, 'breakl', ['No breakpoints defined']) + " Check for error cases + call RunDbgCmd(buf, 'breakadd abcd', [ + \ 'Error detected while processing function Bazz:', + \ 'line 5:', + \ 'E475: Invalid argument: abcd']) + call RunDbgCmd(buf, 'breakadd func', ['E475: Invalid argument: func']) + call RunDbgCmd(buf, 'breakadd func 2', ['E475: Invalid argument: func 2']) + call RunDbgCmd(buf, 'breaka func a()', ['E475: Invalid argument: func a()']) + call RunDbgCmd(buf, 'breakd abcd', ['E475: Invalid argument: abcd']) + call RunDbgCmd(buf, 'breakd func', ['E475: Invalid argument: func']) + call RunDbgCmd(buf, 'breakd func a()', ['E475: Invalid argument: func a()']) + call RunDbgCmd(buf, 'breakd func a', ['E161: Breakpoint not found: func a']) + call RunDbgCmd(buf, 'breakd expr', ['E475: Invalid argument: expr']) + call RunDbgCmd(buf, 'breakd expr x', [ + \ 'E121: Undefined variable: x', + \ 'E161: Breakpoint not found: expr x']) + " finish the current function call RunDbgCmd(buf, 'finish', [ \ 'function Bazz', - \ 'line 5: End of function']) + \ 'line 8: End of function']) + call RunDbgCmd(buf, 'cont') + + " Test for :next + call RunDbgCmd(buf, ':debug echo Bar(1)') + call RunDbgCmd(buf, 'step') + call RunDbgCmd(buf, 'next') + call RunDbgCmd(buf, '', [ + \ 'function Bar', + \ 'line 3: return var2']) + call RunDbgCmd(buf, 'c') + + " Test for :interrupt + call RunDbgCmd(buf, ':debug echo Bazz(1)') + call RunDbgCmd(buf, 'step') + call RunDbgCmd(buf, 'step') + call RunDbgCmd(buf, 'interrupt', [ + \ 'Exception thrown: Vim:Interrupt', + \ 'function Bazz', + \ 'line 5: catch']) + call RunDbgCmd(buf, 'c') + + " Test for :quit + call RunDbgCmd(buf, ':debug echo Foo()') + call RunDbgCmd(buf, 'breakdel *') + call RunDbgCmd(buf, 'breakadd func 3 Foo') + call RunDbgCmd(buf, 'breakadd func 3 Bazz') + call RunDbgCmd(buf, 'cont', [ + \ 'Breakpoint in "Bazz" line 3', + \ 'function Foo[2]..Bar[2]..Bazz', + \ 'line 3: let var3 = "another var"']) + call RunDbgCmd(buf, 'quit', [ + \ 'Breakpoint in "Foo" line 3', + \ 'function Foo', + \ 'line 3: return var2']) + call RunDbgCmd(buf, 'breakdel *') + call RunDbgCmd(buf, 'quit') + call RunDbgCmd(buf, 'enew! | only!') + + call StopVimInTerminal(buf) + + " Tests for :breakadd file and :breakadd here + " Breakpoints should be set before sourcing the file + + call writefile([ + \ 'let var1 = 10', + \ 'let var2 = 20', + \ 'let var3 = 30', + \ 'let var4 = 40'], 'Xtest.vim') + + " Start Vim in a terminal + let buf = RunVimInTerminal('Xtest.vim', {}) + call RunDbgCmd(buf, ':breakadd file 2 Xtest.vim') + call RunDbgCmd(buf, ':4 | breakadd here') + call RunDbgCmd(buf, ':source Xtest.vim', ['line 2: let var2 = 20']) + call RunDbgCmd(buf, 'cont', ['line 4: let var4 = 40']) call RunDbgCmd(buf, 'cont') call StopVimInTerminal(buf)