aboutsummaryrefslogtreecommitdiff
path: root/tests/test-video-audio-recording--interrupt-child-wf-recorder.el
blob: 6e4cda1c97d1f74bf1286bf2d405b42d75ff9f9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
;;; test-video-audio-recording--interrupt-child-wf-recorder.el --- Tests for scoped wf-recorder interrupt -*- lexical-binding: t; -*-

;;; Commentary:
;; Unit tests for cj/recording--interrupt-child-wf-recorder.
;; Verifies the producer-first stop signal targets only the wf-recorder
;; child of this module's own shell process, not every wf-recorder on the
;; system.

;;; Code:

(require 'ert)

;; Stub dependencies before loading the module
(defvar cj/custom-keymap (make-sparse-keymap)
  "Stub keymap for testing.")

(require 'video-audio-recording)

;;; Normal Cases

(ert-deftest test-video-audio-recording--interrupt-child-wf-recorder-normal-scopes-to-parent-pid ()
  "Normal: interrupt is scoped to the wf-recorder child of the given PID."
  (let ((captured nil))
    (cl-letf (((symbol-function 'call-process)
               (lambda (&rest args) (setq captured args) 0)))
      (cj/recording--interrupt-child-wf-recorder 12345)
      ;; Targets wf-recorder, by parent PID, with SIGINT — not a bare
      ;; system-wide name match.
      (should (member "-INT" captured))
      (should (member "-P" captured))
      (should (member "12345" captured))
      (should (member "wf-recorder" captured)))))

;;; Boundary Cases

(ert-deftest test-video-audio-recording--interrupt-child-wf-recorder-boundary-nil-pid-no-call ()
  "Boundary: a nil PID issues no kill at all (nothing to scope to)."
  (let ((called nil))
    (cl-letf (((symbol-function 'call-process)
               (lambda (&rest _) (setq called t) 0)))
      (cj/recording--interrupt-child-wf-recorder nil)
      (should-not called))))

;;; Error Cases

(ert-deftest test-video-audio-recording--interrupt-child-wf-recorder-error-never-bare-name ()
  "Error: must never call pkill with only the program name (system-wide kill)."
  (let ((captured nil))
    (cl-letf (((symbol-function 'call-process)
               (lambda (&rest args) (setq captured args) 0)))
      (cj/recording--interrupt-child-wf-recorder 999)
      ;; The whole point of the fix: a parent-scoping flag is always present.
      (should (member "-P" captured)))))

(provide 'test-video-audio-recording--interrupt-child-wf-recorder)
;;; test-video-audio-recording--interrupt-child-wf-recorder.el ends here