aboutsummaryrefslogtreecommitdiff
path: root/tests/test-external-open-lib-launcher-p.el
blob: 928293b4e5e7671725d4aa18fabaadc3df5efcab (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
;;; test-external-open-lib-launcher-p.el --- Tests for cj/external-open-launcher-p -*- lexical-binding: t; -*-

;;; Commentary:
;; Unit tests for `cj/external-open-launcher-p' in external-open-lib.el.
;; The predicate returns t for desktop launcher commands (xdg-open,
;; open, start) that need `call-process' with a zero buffer argument
;; to fully detach from Emacs.  Anything else returns nil.

;;; Code:

(require 'ert)
(require 'package)

(setq package-user-dir (expand-file-name "elpa" user-emacs-directory))
(package-initialize)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'external-open-lib)

;;; Normal cases

(ert-deftest test-eolp-xdg-open-is-launcher ()
  "Normal: \"xdg-open\" (Linux launcher) returns t."
  (should (eq t (cj/external-open-launcher-p "xdg-open"))))

(ert-deftest test-eolp-open-is-launcher ()
  "Normal: \"open\" (macOS launcher) returns t."
  (should (eq t (cj/external-open-launcher-p "open"))))

(ert-deftest test-eolp-start-is-launcher ()
  "Normal: \"start\" (Windows launcher) returns t."
  (should (eq t (cj/external-open-launcher-p "start"))))

;;; Boundary cases

(ert-deftest test-eolp-non-launcher-command-returns-nil ()
  "Boundary: a non-launcher command (e.g. gimp) returns nil."
  (should-not (cj/external-open-launcher-p "gimp")))

(ert-deftest test-eolp-empty-string-returns-nil ()
  "Boundary: empty string is not a launcher."
  (should-not (cj/external-open-launcher-p "")))

(ert-deftest test-eolp-case-sensitive ()
  "Boundary: launcher check is case-sensitive (\"Open\" is not \"open\")."
  (should-not (cj/external-open-launcher-p "Open"))
  (should-not (cj/external-open-launcher-p "XDG-OPEN")))

;;; Error cases

(ert-deftest test-eolp-nil-argument-returns-nil ()
  "Error: nil input is handled gracefully (not in the launcher list)."
  (should-not (cj/external-open-launcher-p nil)))

(provide 'test-external-open-lib-launcher-p)
;;; test-external-open-lib-launcher-p.el ends here