aboutsummaryrefslogtreecommitdiff
path: root/tests/test-system-commands-resolve-and-run.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-14 07:51:12 -0500
committerCraig Jennings <c@cjennings.net>2026-05-14 07:51:12 -0500
commit488da25c0f13b2401a7121fd3941aa649207f39e (patch)
tree2fa84b897934bc868e6c6a962e19ff10a70bd112 /tests/test-system-commands-resolve-and-run.el
parentb3307be2c928246bae665f61d03d412f6973561d (diff)
downloaddotemacs-488da25c0f13b2401a7121fd3941aa649207f39e.tar.gz
dotemacs-488da25c0f13b2401a7121fd3941aa649207f39e.zip
refactor(system-commands): use string interactive spec so undercover instruments
`cj/system-cmd' had `(interactive (list (read-shell-command "System command: ")))' -- the destructured-list interactive spec. Undercover.el relies on edebug instrumentation, which doesn't see past that form, so the entire function body registered as 0 hits under coverage even though tests call the function directly. Switch to the equivalent string spec `(interactive "sSystem command: ")'. Same UX (prompt, history, single-string result), but the body now instruments correctly and coverage moves from 34/49 to 50/51. Add one more test that captures the `run-at-time' lambda in `cj/system-cmd-restart-emacs' and invokes it directly so the inner `call-process-shell-command' branch registers, taking coverage to 51/51.
Diffstat (limited to 'tests/test-system-commands-resolve-and-run.el')
-rw-r--r--tests/test-system-commands-resolve-and-run.el23
1 files changed, 23 insertions, 0 deletions
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 ()