108_backtrace_debug_commands_spec.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. -- Tests for backtrace debug commands.
  2. local helpers = require('test.functional.helpers')(after_each)
  3. local command = helpers.command
  4. local feed, clear = helpers.feed, helpers.clear
  5. local feed_command, expect = helpers.feed_command, helpers.expect
  6. describe('108', function()
  7. before_each(clear)
  8. it('is working', function()
  9. command("set shortmess-=F")
  10. feed_command('lang mess C')
  11. feed_command('function! Foo()')
  12. feed_command(' let var1 = 1')
  13. feed_command(' let var2 = Bar(var1) + 9')
  14. feed_command(' return var2')
  15. feed_command('endfunction')
  16. feed_command('function! Bar(var)')
  17. feed_command(' let var1 = 2 + a:var')
  18. feed_command(' let var2 = Bazz(var1) + 4')
  19. feed_command(' return var2')
  20. feed_command('endfunction')
  21. feed_command('function! Bazz(var)')
  22. feed_command(' let var1 = 3 + a:var')
  23. feed_command(' let var3 = "another var"')
  24. feed_command(' return var1')
  25. feed_command('endfunction')
  26. feed_command('new')
  27. feed_command('debuggreedy')
  28. feed_command('redir => out')
  29. feed_command('debug echo Foo()')
  30. feed('step<cr>')
  31. feed('step<cr>')
  32. feed('step<cr>')
  33. feed('step<cr>')
  34. feed('step<cr>')
  35. feed('step<cr>')
  36. feed([[echo "- show backtrace:\n"<cr>]])
  37. feed('backtrace<cr>')
  38. feed([[echo "\nshow variables on different levels:\n"<cr>]])
  39. feed('echo var1<cr>')
  40. feed('up<cr>')
  41. feed('back<cr>')
  42. feed('echo var1<cr>')
  43. feed('u<cr>')
  44. feed('bt<cr>')
  45. feed('echo var1<cr>')
  46. feed([[echo "\n- undefined vars:\n"<cr>]])
  47. feed('step<cr>')
  48. feed('frame 2<cr>')
  49. feed('echo "undefined var3 on former level:"<cr>')
  50. feed('echo var3<cr>')
  51. feed('fr 0<cr>')
  52. feed([[echo "here var3 is defined with \"another var\":"<cr>]])
  53. feed('echo var3<cr>')
  54. feed('step<cr>')
  55. feed('step<cr>')
  56. feed('step<cr>')
  57. feed('up<cr>')
  58. feed([[echo "\nundefined var2 on former level"<cr>]])
  59. feed('echo var2<cr>')
  60. feed('down<cr>')
  61. feed('echo "here var2 is defined with 10:"<cr>')
  62. feed('echo var2<cr>')
  63. feed([[echo "\n- backtrace movements:\n"<cr>]])
  64. feed('b<cr>')
  65. feed([[echo "\nnext command cannot go down, we are on bottom\n"<cr>]])
  66. feed('down<cr>')
  67. feed('up<cr>')
  68. feed([[echo "\nnext command cannot go up, we are on top\n"<cr>]])
  69. feed('up<cr>')
  70. feed('b<cr>')
  71. feed('echo "fil is not frame or finish, it is file"<cr>')
  72. feed('fil<cr>')
  73. feed([[echo "\n- relative backtrace movement\n"<cr>]])
  74. feed('fr -1<cr>')
  75. feed('frame<cr>')
  76. feed('fra +1<cr>')
  77. feed('fram<cr>')
  78. feed([[echo "\n- go beyond limits does not crash\n"<cr>]])
  79. feed('fr 100<cr>')
  80. feed('fra<cr>')
  81. feed('frame -40<cr>')
  82. feed('fram<cr>')
  83. feed([[echo "\n- final result 19:"<cr>]])
  84. feed('cont<cr>')
  85. feed_command('0debuggreedy')
  86. feed_command('redir END')
  87. feed_command('$put =out')
  88. -- Assert buffer contents.
  89. expect([=[
  90. - show backtrace:
  91. 2 function Foo[2]
  92. 1 Bar[2]
  93. ->0 Bazz
  94. line 2: let var3 = "another var"
  95. show variables on different levels:
  96. 6
  97. 2 function Foo[2]
  98. ->1 Bar[2]
  99. 0 Bazz
  100. line 2: let var3 = "another var"
  101. 3
  102. ->2 function Foo[2]
  103. 1 Bar[2]
  104. 0 Bazz
  105. line 2: let var3 = "another var"
  106. 1
  107. - undefined vars:
  108. undefined var3 on former level:
  109. Error detected while processing function Foo[2]..Bar[2]..Bazz:
  110. line 3:
  111. E121: Undefined variable: var3
  112. here var3 is defined with "another var":
  113. another var
  114. undefined var2 on former level
  115. Error detected while processing function Foo[2]..Bar:
  116. line 3:
  117. E121: Undefined variable: var2
  118. here var2 is defined with 10:
  119. 10
  120. - backtrace movements:
  121. 1 function Foo[2]
  122. ->0 Bar
  123. line 3: End of function
  124. next command cannot go down, we are on bottom
  125. frame is zero
  126. next command cannot go up, we are on top
  127. frame at highest level: 1
  128. ->1 function Foo[2]
  129. 0 Bar
  130. line 3: End of function
  131. fil is not frame or finish, it is file
  132. "[No Name]" --No lines in buffer--
  133. - relative backtrace movement
  134. 1 function Foo[2]
  135. ->0 Bar
  136. line 3: End of function
  137. ->1 function Foo[2]
  138. 0 Bar
  139. line 3: End of function
  140. - go beyond limits does not crash
  141. frame at highest level: 1
  142. ->1 function Foo[2]
  143. 0 Bar
  144. line 3: End of function
  145. frame is zero
  146. 1 function Foo[2]
  147. ->0 Bar
  148. line 3: End of function
  149. - final result 19:
  150. 19
  151. ]=])
  152. end)
  153. end)