summaryrefslogtreecommitdiff
path: root/tests/test-system-lib-executable-exists-p.el
blob: 457bb0104d1503f175c515af4034d3780ebf749c (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
;;; test-system-lib-executable-exists-p.el --- Tests for cj/executable-exists-p -*- lexical-binding: t; -*-

;;; Commentary:
;; Unit tests for cj/executable-exists-p function from system-lib.el.
;; Tests whether external programs are correctly detected in PATH.

;;; Code:

(require 'ert)
(require 'system-lib)

;;; Normal Cases

(ert-deftest test-system-lib-executable-exists-p-normal-existing-program-returns-path ()
  "Test that existing program in PATH returns non-nil.

Standard case: checking for a program that definitely exists on all systems."
  (should (cj/executable-exists-p "ls")))

(ert-deftest test-system-lib-executable-exists-p-normal-diff-exists-returns-path ()
  "Test that diff program exists and is detected.

Tests specifically for diff which we use in our diff functionality."
  (should (cj/executable-exists-p "diff")))

;;; Boundary Cases

(ert-deftest test-system-lib-executable-exists-p-boundary-empty-string-returns-nil ()
  "Test that empty string returns nil.

Boundary case: empty string is not a valid program name."
  (should-not (cj/executable-exists-p "")))

(ert-deftest test-system-lib-executable-exists-p-boundary-whitespace-only-returns-nil ()
  "Test that whitespace-only string returns nil.

Boundary case: strings containing only whitespace are not valid programs."
  (should-not (cj/executable-exists-p "   ")))

(ert-deftest test-system-lib-executable-exists-p-boundary-absolute-path-returns-path ()
  "Test that absolute path to executable returns the path.

Boundary case: executable-find accepts both program names and full paths."
  (should (cj/executable-exists-p "/usr/bin/ls")))

;;; Error Cases

(ert-deftest test-system-lib-executable-exists-p-error-nil-input-returns-nil ()
  "Test that nil input returns nil gracefully.

Error case: nil is not a valid program name."
  (should-not (cj/executable-exists-p nil)))

(ert-deftest test-system-lib-executable-exists-p-error-number-input-returns-nil ()
  "Test that numeric input returns nil gracefully.

Error case: number is not a valid program name."
  (should-not (cj/executable-exists-p 42)))

(ert-deftest test-system-lib-executable-exists-p-error-nonexistent-program-returns-nil ()
  "Test that nonexistent program returns nil.

Error case: program that definitely doesn't exist in PATH."
  (should-not (cj/executable-exists-p "this-program-definitely-does-not-exist-xyz123")))

(ert-deftest test-system-lib-executable-exists-p-error-special-characters-returns-nil ()
  "Test that program name with special characters returns nil.

Error case: invalid characters in program name."
  (should-not (cj/executable-exists-p "program-with-$pecial-ch@rs")))

(provide 'test-system-lib-executable-exists-p)
;;; test-system-lib-executable-exists-p.el ends here