aboutsummaryrefslogtreecommitdiff
path: root/tests/test-config-utilities--delete-compiled-files-in-dir.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-04-30 09:16:55 -0500
committerCraig Jennings <c@cjennings.net>2026-04-30 09:16:55 -0500
commit6930a43643dc0848a5711578f96a06c342c2281c (patch)
tree28506350439b039d16fa6d0500296dba00571c0c /tests/test-config-utilities--delete-compiled-files-in-dir.el
parent0ab3032947fb6dbff0fcbf8a666b7fdcd8f08a5a (diff)
downloaddotemacs-6930a43643dc0848a5711578f96a06c342c2281c.tar.gz
dotemacs-6930a43643dc0848a5711578f96a06c342c2281c.zip
test(config-utilities): cover cj/--delete-compiled-files-in-dir
Five tests against real temp directories: mixed .el/.elc/.eln content, recursive descent through subdirectories, no-compiled-files no-op, empty directory, and the suffix-vs-substring boundary that ensures a file like "looks.elc.bak" isn't deleted (string-suffix-p, not string-match).
Diffstat (limited to 'tests/test-config-utilities--delete-compiled-files-in-dir.el')
-rw-r--r--tests/test-config-utilities--delete-compiled-files-in-dir.el91
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/test-config-utilities--delete-compiled-files-in-dir.el b/tests/test-config-utilities--delete-compiled-files-in-dir.el
new file mode 100644
index 00000000..73b3705d
--- /dev/null
+++ b/tests/test-config-utilities--delete-compiled-files-in-dir.el
@@ -0,0 +1,91 @@
+;;; test-config-utilities--delete-compiled-files-in-dir.el --- Tests for cj/--delete-compiled-files-in-dir -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Tests for `cj/--delete-compiled-files-in-dir'. The helper walks DIR
+;; recursively, deletes every `.elc' and `.eln' file, and returns the
+;; count. Tests run against real temp directories so the file-system
+;; recursion and suffix matching are exercised end-to-end.
+
+;;; Code:
+
+(require 'ert)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'config-utilities)
+
+(defun test-config-utilities--make-temp-fixture-dir (specs)
+ "Create a fresh temp directory containing files described by SPECS.
+SPECS is a list of file paths relative to the temp dir. Each path
+gets created as an empty file (subdirectories created as needed).
+Returns the temp dir path."
+ (let ((dir (make-temp-file "delete-compiled-test-" t)))
+ (dolist (spec specs)
+ (let ((full (expand-file-name spec dir)))
+ (let ((parent (file-name-directory full)))
+ (when (and parent (not (file-exists-p parent)))
+ (make-directory parent t)))
+ (with-temp-file full (insert ""))))
+ dir))
+
+(ert-deftest test-config-utilities-delete-compiled-deletes-elc-and-eln ()
+ "Normal: a directory with mixed .el / .elc / .eln files keeps .el and
+deletes both compiled forms. Returns the count of deletions."
+ (let ((dir (test-config-utilities--make-temp-fixture-dir
+ '("a.el" "a.elc" "b.eln" "c.el"))))
+ (unwind-protect
+ (let ((count (cj/--delete-compiled-files-in-dir dir)))
+ (should (= count 2))
+ (should (file-exists-p (expand-file-name "a.el" dir)))
+ (should (file-exists-p (expand-file-name "c.el" dir)))
+ (should-not (file-exists-p (expand-file-name "a.elc" dir)))
+ (should-not (file-exists-p (expand-file-name "b.eln" dir))))
+ (delete-directory dir t))))
+
+(ert-deftest test-config-utilities-delete-compiled-recursive ()
+ "Boundary: deletion descends into subdirectories."
+ (let ((dir (test-config-utilities--make-temp-fixture-dir
+ '("top.elc" "sub/nested.elc" "sub/nested.el"
+ "sub/deep/very-nested.eln"))))
+ (unwind-protect
+ (let ((count (cj/--delete-compiled-files-in-dir dir)))
+ (should (= count 3))
+ (should (file-exists-p (expand-file-name "sub/nested.el" dir)))
+ (should-not (file-exists-p (expand-file-name "top.elc" dir)))
+ (should-not (file-exists-p (expand-file-name "sub/nested.elc" dir)))
+ (should-not (file-exists-p
+ (expand-file-name "sub/deep/very-nested.eln" dir))))
+ (delete-directory dir t))))
+
+(ert-deftest test-config-utilities-delete-compiled-no-compiled-files ()
+ "Boundary: a directory with no compiled files reports 0 and changes nothing."
+ (let ((dir (test-config-utilities--make-temp-fixture-dir
+ '("only.el" "another.el" "sub/more.el"))))
+ (unwind-protect
+ (let ((count (cj/--delete-compiled-files-in-dir dir)))
+ (should (zerop count))
+ (should (file-exists-p (expand-file-name "only.el" dir))))
+ (delete-directory dir t))))
+
+(ert-deftest test-config-utilities-delete-compiled-empty-dir ()
+ "Boundary: an empty directory returns 0."
+ (let ((dir (make-temp-file "empty-delete-test-" t)))
+ (unwind-protect
+ (should (zerop (cj/--delete-compiled-files-in-dir dir)))
+ (delete-directory dir t))))
+
+(ert-deftest test-config-utilities-delete-compiled-suffix-not-substring ()
+ "Boundary: a file whose name CONTAINS \".elc\" but doesn't end in it is kept."
+ (let ((dir (test-config-utilities--make-temp-fixture-dir
+ '("not-elc-suffix.el"
+ "looks.elc.bak"
+ "real.elc"))))
+ (unwind-protect
+ (let ((count (cj/--delete-compiled-files-in-dir dir)))
+ (should (= count 1))
+ (should (file-exists-p (expand-file-name "not-elc-suffix.el" dir)))
+ (should (file-exists-p (expand-file-name "looks.elc.bak" dir)))
+ (should-not (file-exists-p (expand-file-name "real.elc" dir))))
+ (delete-directory dir t))))
+
+(provide 'test-config-utilities--delete-compiled-files-in-dir)
+;;; test-config-utilities--delete-compiled-files-in-dir.el ends here