diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-10 14:42:04 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-10 14:42:04 -0500 |
| commit | 16396d25c2795bd7f8822a695de111d07f588b26 (patch) | |
| tree | c452c193c1eb813cedcd3b4faca030d8775da4a3 /tests/test-external-open-launcher-p.el | |
| parent | c44a52a7905b605a6537e3ff9bb4fe3afede0485 (diff) | |
| download | dotemacs-16396d25c2795bd7f8822a695de111d07f588b26.tar.gz dotemacs-16396d25c2795bd7f8822a695de111d07f588b26.zip | |
refactor(external-open): consolidate OS-open dispatch in external-open.el
Phase 4 of utility-consolidation. Three previously-overlapping helpers (system-utils' `cj/identify-external-open-command' and `cj/--open-with-is-launcher-p', plus the dirvish-only `cj/--file-manager-program-for' shipped earlier today) all answered "which OS-open program should I run?". Pull the answer into one place: external-open.el.
Move and rename:
- `cj/--open-with-is-launcher-p' (system-utils) -> `cj/external-open-launcher-p' (external-open). Public name now matches its module.
- `cj/identify-external-open-command' (system-utils) -> `cj/external-open-command' (external-open). Returns nil for unsupported hosts instead of signaling -- callers that need a command must handle nil explicitly. The wrapper `cj/xdg-open' (also moved into external-open) converts nil to a `user-error' with a clear message, preserving the user-facing failure shape.
- Delete dirvish's `cj/--file-manager-program-for' helper. `cj/dirvish-open-file-manager-here' now calls `cj/external-open-command' directly. The shell-command fallback for nil-program preserves the previous escape hatch.
Break the system-utils <-> external-open recursive require by moving `cj/xdg-open' (the only system-utils function that external-open used) into external-open along with the dispatch.
Tests reorganized to match the move. Two new test files (`test-external-open-command.el', `test-external-open-launcher-p.el') replace the two system-utils-named test files. The dirvish file-manager-program test goes away with the helper. 11 tests covering Normal/Boundary/Error for the dispatch (plus the new "unsupported host returns nil" contract).
Add `(require \='external-open)' to system-utils.el and `(require \='system-lib)' to external-open.el (for `cj/file-from-context' which xdg-open uses).
Diffstat (limited to 'tests/test-external-open-launcher-p.el')
| -rw-r--r-- | tests/test-external-open-launcher-p.el | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/test-external-open-launcher-p.el b/tests/test-external-open-launcher-p.el new file mode 100644 index 000000000..4aca3a559 --- /dev/null +++ b/tests/test-external-open-launcher-p.el @@ -0,0 +1,55 @@ +;;; test-external-open-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.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) + +;;; 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-launcher-p) +;;; test-external-open-launcher-p.el ends here |
