Browse Source

Make sure invalid breakpoints are not added/removed

* Do not attempt to add a breakpoint on a line with an existing breakpoint.
* Do not attempt to remove non-existing breakpoints.
workspaces
Nicolas Petton 3 years ago
parent
commit
5ad6f1961e
Signed by: nico GPG Key ID: 233587A47C207910
2 changed files with 49 additions and 1 deletions
  1. +16
    -1
      indium-interaction.el
  2. +33
    -0
      test/unit/indium-interaction-test.el

+ 16
- 1
indium-interaction.el View File

@ -122,8 +122,10 @@ If PRINT is non-nil, print the output into the current buffer."
(user-error "No REPL buffer open")))
(defun indium-add-breakpoint ()
"Add a breakpoint at point."
"Add a breakpoint on the current line.
If there is already a breakpoint, signal an error."
(interactive)
(indium-interaction--guard-no-breakpoint-at-point)
(if-let ((location (indium-script-generated-location-at-point)))
(indium-breakpoint-add location)
(user-error "Cannot place a breakpoint here")))
@ -131,16 +133,19 @@ If PRINT is non-nil, print the output into the current buffer."
(defun indium-add-conditional-breakpoint ()
"Add a conditional breakpoint at point."
(interactive)
(indium-interaction--guard-no-breakpoint-at-point)
(indium-breakpoint-add (read-from-minibuffer "Breakpoint condition: ")))
(defun indium-edit-breakpoint-condition ()
"Edit the condition of breakpoint at point."
(interactive)
(indium-interaction--guard-breakpoint-at-point)
(indium-breakpoint-edit-condition))
(defun indium-remove-breakpoint ()
"Remove the breakpoint at point."
(interactive)
(indium-interaction--guard-breakpoint-at-point)
(indium-breakpoint-remove))
(defun indium-remove-all-breakpoints-from-buffer ()
@ -293,6 +298,16 @@ hitting a breakpoint."
(lambda ()
(run-hook-with-args 'indium-update-script-source-hook url)))))
(defun indium-interaction--guard-breakpoint-at-point ()
"Signal an error if there is no breakpoint on the current line."
(unless (indium-breakpoint-at-point)
(user-error "No breakpoint on the current line")))
(defun indium-interaction--guard-no-breakpoint-at-point ()
"Signal an error if there is a breakpoint on the current line."
(when (indium-breakpoint-at-point)
(user-error "There is already a breakpoint on the current line")))
(add-hook 'after-save-hook #'indium-interaction-update)
(provide 'indium-interaction)


+ 33
- 0
test/unit/indium-interaction-test.el View File

@ -22,6 +22,8 @@
;;; Code:
(require 'buttercup)
(require 'assess)
(require 'indium-interaction)
(describe "Finding the AST node to evaluate"
@ -119,5 +121,36 @@
(expect (js2-node-string (indium-interaction-node-before-point))
:to-equal "for (const x of [1, 2, 3]) {console.log(x);}"))))
(describe "Adding/removing invalid breakpoints"
(it "should not try to add duplicate breakpoints"
(assess-with-filesystem '("app.js")
(let ((buf (find-file-noselect (expand-file-name "app.js"))))
(with-current-buffer buf
(insert "let a = 2;")
(indium-add-breakpoint)
(expect #'indium-add-breakpoint :to-throw 'user-error)))))
(it "should not try to remove non-existant breakpoints"
(assess-with-filesystem '("app.js")
(let ((buf (find-file-noselect (expand-file-name "app.js"))))
(with-current-buffer buf
(insert "let a = 2;")
(expect #'indium-remove-breakpoint :to-throw 'user-error)))))
(it "should not try to edit non-existant breakpoints"
(assess-with-filesystem '("app.js")
(let ((buf (find-file-noselect (expand-file-name "app.js"))))
(with-current-buffer buf
(insert "let a = 2;")
(expect #'indium-edit-breakpoint-condition :to-throw 'user-error)))))
(it "should not try to add conditional breakpoints twice"
(assess-with-filesystem '("app.js")
(let ((buf (find-file-noselect (expand-file-name "app.js"))))
(with-current-buffer buf
(insert "let a = 2;")
(indium-add-breakpoint)
(expect #'indium-add-conditional-breakpoint :to-throw 'user-error))))))
(provide 'indium-interaction-test)
;;; indium-interaction-test.el ends here

Loading…
Cancel
Save