From 6d637027e01f43623f4bca29c233cb7c298ebb08 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 10 May 2026 14:42:04 -0500 Subject: 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). --- .../test-system-utils--open-with-is-launcher-p.el | 52 ---------------------- 1 file changed, 52 deletions(-) delete mode 100644 tests/test-system-utils--open-with-is-launcher-p.el (limited to 'tests/test-system-utils--open-with-is-launcher-p.el') diff --git a/tests/test-system-utils--open-with-is-launcher-p.el b/tests/test-system-utils--open-with-is-launcher-p.el deleted file mode 100644 index 64e9a4b6..00000000 --- a/tests/test-system-utils--open-with-is-launcher-p.el +++ /dev/null @@ -1,52 +0,0 @@ -;;; test-system-utils--open-with-is-launcher-p.el --- Tests for cj/--open-with-is-launcher-p -*- lexical-binding: t; -*- - -;;; Commentary: -;; Unit tests for `cj/--open-with-is-launcher-p' in system-utils.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) - -(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) -(require 'system-utils) - -;;; Normal cases - -(ert-deftest test-owilp-xdg-open-is-launcher () - "Normal: \"xdg-open\" (Linux launcher) returns t." - (should (eq t (cj/--open-with-is-launcher-p "xdg-open")))) - -(ert-deftest test-owilp-open-is-launcher () - "Normal: \"open\" (macOS launcher) returns t." - (should (eq t (cj/--open-with-is-launcher-p "open")))) - -(ert-deftest test-owilp-start-is-launcher () - "Normal: \"start\" (Windows launcher) returns t." - (should (eq t (cj/--open-with-is-launcher-p "start")))) - -;;; Boundary cases - -(ert-deftest test-owilp-non-launcher-command-returns-nil () - "Boundary: a non-launcher command (e.g. gimp) returns nil." - (should-not (cj/--open-with-is-launcher-p "gimp"))) - -(ert-deftest test-owilp-empty-string-returns-nil () - "Boundary: empty string is not a launcher." - (should-not (cj/--open-with-is-launcher-p ""))) - -(ert-deftest test-owilp-case-sensitive () - "Boundary: launcher check is case-sensitive (\"Open\" is not \"open\")." - (should-not (cj/--open-with-is-launcher-p "Open")) - (should-not (cj/--open-with-is-launcher-p "XDG-OPEN"))) - -;;; Error cases - -(ert-deftest test-owilp-nil-argument-returns-nil () - "Error: nil input is handled gracefully (not in the launcher list)." - (should-not (cj/--open-with-is-launcher-p nil))) - -(provide 'test-system-utils--open-with-is-launcher-p) -;;; test-system-utils--open-with-is-launcher-p.el ends here -- cgit v1.2.3