summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/system-commands.el11
-rw-r--r--tests/test-system-commands-resolve-and-run.el23
2 files changed, 32 insertions, 2 deletions
diff --git a/modules/system-commands.el b/modules/system-commands.el
index 8b155746..64eb5e79 100644
--- a/modules/system-commands.el
+++ b/modules/system-commands.el
@@ -43,8 +43,15 @@
"Run CMD (string or symbol naming a string) detached via the shell.
Shell expansions like $(...) are supported. Output is silenced.
If CMD is deemed dangerous, ask for confirmation."
- (interactive (list (read-shell-command "System command: ")))
- (pcase-let ((`(,sym ,cmdstr ,label) (cj/system-cmd--resolve cmd)))
+ (interactive "sSystem command: ")
+ ;; Plain `let*' + `nth' instead of `pcase-let' with a backquote
+ ;; destructure: edebug-based coverage tools (undercover.el) don't
+ ;; instrument inside backquote-destructured `pcase-let' bindings,
+ ;; so the body shows as uncovered even when tests exercise it.
+ (let* ((resolved (cj/system-cmd--resolve cmd))
+ (sym (nth 0 resolved))
+ (cmdstr (nth 1 resolved))
+ (label (nth 2 resolved)))
(when (and sym (get sym 'cj/system-confirm)
(memq (read-char-choice
(format "Run %s now (%s)? (Y/n) " label cmdstr)
diff --git a/tests/test-system-commands-resolve-and-run.el b/tests/test-system-commands-resolve-and-run.el
index 105628b6..f15559d7 100644
--- a/tests/test-system-commands-resolve-and-run.el
+++ b/tests/test-system-commands-resolve-and-run.el
@@ -126,6 +126,29 @@
(cj/system-cmd-restart-emacs))
(should (= schedules 2))))
+(ert-deftest test-system-cmd-restart-emacs-restart-lambda-shells-out ()
+ "Normal: the lambda scheduled by the first `run-at-time' call invokes
+`call-process-shell-command' with the systemctl restart line.
+
+Captures the lambda passed to the first scheduling call and invokes it
+directly with all relevant side effects stubbed, so the inner body
+registers under coverage even though the real timer never fires."
+ (let (captured-lambda call-args)
+ (cl-letf (((symbol-function 'read-char-choice) (lambda (&rest _) ?y))
+ ((symbol-function 'save-some-buffers) #'ignore)
+ ((symbol-function 'run-at-time)
+ (lambda (_when _repeat fn)
+ (unless captured-lambda (setq captured-lambda fn))))
+ ((symbol-function 'message) #'ignore)
+ ((symbol-function 'call-process-shell-command)
+ (lambda (&rest args) (setq call-args args))))
+ (cj/system-cmd-restart-emacs)
+ (should (functionp captured-lambda))
+ (funcall captured-lambda)
+ (should call-args)
+ (should (string-match-p "systemctl --user restart emacs.service"
+ (car call-args))))))
+
;;; cj/system-command-menu
(ert-deftest test-system-command-menu-dispatches-by-name ()