diff options
| author | Craig Jennings <c@cjennings.net> | 2026-04-23 01:37:52 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-04-23 01:37:52 -0500 |
| commit | 73a95c7d1c5ba591a3444f92012be4a281e8d08b (patch) | |
| tree | ca6e185c191d0457e4e0a5312d8726af553ba1eb /tests/test-system-utils-identify-external-open-command.el | |
| parent | 305a58c6fcc5e9321f5b94011124b16ea73e2f00 (diff) | |
| download | dotemacs-73a95c7d1c5ba591a3444f92012be4a281e8d08b.tar.gz dotemacs-73a95c7d1c5ba591a3444f92012be4a281e8d08b.zip | |
test(system-utils): cover identify-external-open-command and eval-buffer
Adds two per-function test files covering the easily-testable functions in system-utils.el. Takes the module from 0/52 (0%) to 10/52 (19.2%) coverage.
tests/test-system-utils-identify-external-open-command.el — five tests for cj/identify-external-open-command: one each for the three supported platforms (linux, macos, windows), one documenting the dispatch-order invariant when multiple predicates return t, and one for the unsupported-host error case. env-*-p predicates are stubbed via cl-letf so the tests run correctly on any host.
tests/test-system-utils-eval-buffer.el — three tests for cj/eval-buffer-with-confirmation-or-error-message: the valid-elisp success path, an empty-buffer boundary case, and the broken-elisp error path (confirming the condition-case wrapper catches errors rather than propagating). A small macro stubs message to capture what the user would see.
Split into two files per the project's per-function test convention (elisp-testing.md).
Not covered in this commit and flagged for follow-up:
- cj/open-file-with-command and cj/xdg-open mix user-input resolution with process launching. Per elisp-testing.md's "split interactive from internal" rule, a pure file-resolution helper should be extracted before tests are written.
- cj/server-shutdown kills Emacs, so it isn't meaningfully testable.
Diffstat (limited to 'tests/test-system-utils-identify-external-open-command.el')
| -rw-r--r-- | tests/test-system-utils-identify-external-open-command.el | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test-system-utils-identify-external-open-command.el b/tests/test-system-utils-identify-external-open-command.el new file mode 100644 index 00000000..dc272570 --- /dev/null +++ b/tests/test-system-utils-identify-external-open-command.el @@ -0,0 +1,59 @@ +;;; test-system-utils-identify-external-open-command.el --- Tests for cj/identify-external-open-command -*- lexical-binding: t; -*- + +;;; Commentary: +;; Unit tests for `cj/identify-external-open-command' in system-utils.el. +;; The function dispatches on host-environment predicates to return the +;; appropriate "open" command: xdg-open on Linux, open on macOS, +;; start on Windows. Anything else is a fatal error. + +;;; Code: + +(require 'ert) +(require 'cl-lib) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'system-utils) + +(defmacro test-siuec--with-host (linux macos windows &rest body) + "Run BODY with env-*-p predicates stubbed to LINUX, MACOS, WINDOWS." + (declare (indent 3)) + `(cl-letf (((symbol-function 'env-linux-p) (lambda () ,linux)) + ((symbol-function 'env-macos-p) (lambda () ,macos)) + ((symbol-function 'env-windows-p) (lambda () ,windows))) + ,@body)) + +;;; Normal cases + +(ert-deftest test-siuec-linux-returns-xdg-open () + "Normal: Linux host returns \"xdg-open\"." + (test-siuec--with-host t nil nil + (should (string= "xdg-open" (cj/identify-external-open-command))))) + +(ert-deftest test-siuec-macos-returns-open () + "Normal: macOS host returns \"open\"." + (test-siuec--with-host nil t nil + (should (string= "open" (cj/identify-external-open-command))))) + +(ert-deftest test-siuec-windows-returns-start () + "Normal: Windows host returns \"start\"." + (test-siuec--with-host nil nil t + (should (string= "start" (cj/identify-external-open-command))))) + +;;; Boundary cases + +(ert-deftest test-siuec-dispatch-order-linux-wins () + "Boundary: Linux check runs first; wins when predicates disagree. +Documents the dispatch order. A real host only returns t from one +of these anyway — but if something goes wrong, Linux takes priority." + (test-siuec--with-host t t t + (should (string= "xdg-open" (cj/identify-external-open-command))))) + +;;; Error cases + +(ert-deftest test-siuec-unsupported-host-signals-error () + "Error: when no platform predicate returns non-nil, signals an error." + (test-siuec--with-host nil nil nil + (should-error (cj/identify-external-open-command)))) + +(provide 'test-system-utils-identify-external-open-command) +;;; test-system-utils-identify-external-open-command.el ends here |
