A JavaScript development environment for Emacs https://indium.readthedocs.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
5.8 KiB

4 years ago
4 years ago
4 years ago
  1. ;;; indium-debugger-test.el --- Test for indium-debugger.el -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2016-2017 Nicolas Petton
  3. ;; Author: Nicolas Petton <nicolas@petton.fr>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;;; Code:
  16. (require 'buttercup)
  17. (require 'indium-debugger)
  18. (describe "Debugging frames are correctly set"
  19. (it "can set debugger frames and current frame"
  20. (with-fake-indium-connection
  21. (let ((frames '(first second))
  22. (current-frame 'first))
  23. (indium-debugger-set-frames frames)
  24. (expect (indium-current-connection-frames) :to-be frames)
  25. (expect (indium-current-connection-current-frame) :to-be current-frame))))
  26. (it "can set the current frame"
  27. ;; We're not interested in buffer setups
  28. (spy-on 'indium-debugger-get-buffer-create)
  29. (with-fake-indium-connection
  30. (indium-debugger-set-current-frame 'current)
  31. (expect (indium-current-connection-current-frame) :to-be 'current)))
  32. (it "can unset the debugging frames"
  33. (with-fake-indium-connection
  34. (indium-debugger-set-frames '(first second))
  35. (indium-debugger-unset-frames)
  36. (expect (indium-current-connection-frames) :to-be nil)
  37. (expect (indium-current-connection-current-frame) :to-be nil))))
  38. (describe "Jumping to the next/previous frame"
  39. (before-each
  40. (spy-on 'indium-debugger-select-frame))
  41. (it "can select the next frame"
  42. (with-fake-indium-connection
  43. (let ((frames '(first second)))
  44. (indium-debugger-set-frames frames)
  45. (indium-debugger-set-current-frame 'second)
  46. (indium-debugger-next-frame)
  47. (expect 'indium-debugger-select-frame :to-have-been-called-with 'first))))
  48. (it "can select the previous frame"
  49. (with-fake-indium-connection
  50. (let ((frames '(first second)))
  51. (indium-debugger-set-frames frames)
  52. (indium-debugger-previous-frame)
  53. (expect 'indium-debugger-select-frame :to-have-been-called-with 'second))))
  54. (it "should throw when selecting the next frame if it does not exist"
  55. (with-fake-indium-connection
  56. (let ((frames '(first second)))
  57. (indium-debugger-set-frames frames)
  58. (expect #'indium-debugger-next-frame :to-throw 'user-error))))
  59. (it "should throw when selecting the previous frame if it does not exist"
  60. (with-fake-indium-connection
  61. (let ((frames '(first second)))
  62. (indium-debugger-set-frames frames)
  63. (indium-debugger-set-current-frame 'second)
  64. (expect #'indium-debugger-previous-frame :to-throw 'user-error)))))
  65. (describe "Regression test for GitHub issue 53"
  66. (before-each
  67. (let ((debugger-buffer (get-buffer-create (indium-debugger--buffer-name-no-file))))
  68. (with-current-buffer debugger-buffer
  69. (indium-debugger-mode))))
  70. (after-each
  71. (ignore-errors
  72. (kill-buffer (indium-debugger--buffer-name-no-file))))
  73. ;; Regression test for https://github.com/NicolasPetton/Indium/issues/53
  74. ;; Killing the debugger buffer when stepping results in a visual
  75. ;; flickering. Since stepping over or into cause the execution to be resumed
  76. ;; and paused, the debugger buffer should not be killed.
  77. (it "should not killing the debugger buffer when execution is resumed"
  78. (spy-on 'indium-backend-resume)
  79. (expect (get-buffer (indium-debugger--buffer-name-no-file)) :not :to-be nil)
  80. (indium-debugger-resume)
  81. (expect (get-buffer (indium-debugger--buffer-name-no-file)) :not :to-be nil)))
  82. (describe "Debugger stepping"
  83. ;; Cleaning up the debugger state should only be done when the execution is
  84. ;; resumed, which happens between each step over/into/out.
  85. (it "should not unset the debugger buffer when stepping"
  86. (spy-on 'indium-debugger-unset-current-buffer)
  87. (spy-on 'indium-debugger-step-into)
  88. (spy-on 'indium-debugger-step-out)
  89. (spy-on 'indium-debugger-step-over)
  90. (indium-debugger-step-into)
  91. (expect #'indium-debugger-unset-current-buffer :not :to-have-been-called)
  92. (indium-debugger-step-over)
  93. (expect #'indium-debugger-unset-current-buffer :not :to-have-been-called)
  94. (indium-debugger-step-out)
  95. (expect #'indium-debugger-unset-current-buffer :not :to-have-been-called))
  96. (it "should call the backend when stepping into"
  97. (spy-on 'indium-backend-step-into)
  98. (spy-on 'indium-current-connection-backend :and-return-value 'backend)
  99. (indium-debugger-step-into)
  100. (expect #'indium-backend-step-into :to-have-been-called-with 'backend))
  101. (it "should call the backend when stepping over"
  102. (spy-on 'indium-backend-step-over)
  103. (spy-on 'indium-current-connection-backend :and-return-value 'backend)
  104. (indium-debugger-step-over)
  105. (expect #'indium-backend-step-over :to-have-been-called-with 'backend))
  106. (it "should call the backend when stepping out"
  107. (spy-on 'indium-backend-step-out)
  108. (spy-on 'indium-current-connection-backend :and-return-value 'backend)
  109. (indium-debugger-step-out)
  110. (expect #'indium-backend-step-out :to-have-been-called-with 'backend))
  111. (it "should call the backend when resuming execution"
  112. (spy-on 'indium-backend-resume)
  113. (spy-on 'indium-current-connection-backend :and-return-value 'backend)
  114. (indium-debugger-resume)
  115. (expect #'indium-backend-resume :to-have-been-called-with 'backend)))
  116. (provide 'indium-debugger-test)
  117. ;;; indium-debugger-test.el ends here