aboutsummaryrefslogtreecommitdiff
path: root/tests/test-dwim-shell-config-empty-dirs.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-23 20:20:17 -0500
committerCraig Jennings <c@cjennings.net>2026-05-23 20:20:17 -0500
commit4a7927bf7352e3e626dfb596a70bec9d3bc532eb (patch)
tree777b100ea74f4c41691773a5e3f375f9090b54c2 /tests/test-dwim-shell-config-empty-dirs.el
parent1ab0ac6397b1e41ae124d3990ba2dd20bca2cfe3 (diff)
downloaddotemacs-4a7927bf7352e3e626dfb596a70bec9d3bc532eb.tar.gz
dotemacs-4a7927bf7352e3e626dfb596a70bec9d3bc532eb.zip
fix(dwim-shell): make destructive file-op commands match their names
Two commands did less, or more, than their names implied. remove-empty-directories ran find . -type d -empty -delete from whatever the current directory happened to be, so its scope was implicit and easy to misjudge. It now prompts for a root, names that root in the confirmation, and runs find against the shell-quoted root via cj/dwim-shell--empty-dirs-command. secure-delete ran shred without -u, so it overwrote a file's contents but left the file in place, not the deletion the name and the "permanently destroy" prompt promise. Added -u so it unlinks after overwriting.
Diffstat (limited to 'tests/test-dwim-shell-config-empty-dirs.el')
-rw-r--r--tests/test-dwim-shell-config-empty-dirs.el28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/test-dwim-shell-config-empty-dirs.el b/tests/test-dwim-shell-config-empty-dirs.el
new file mode 100644
index 00000000..1c7129c3
--- /dev/null
+++ b/tests/test-dwim-shell-config-empty-dirs.el
@@ -0,0 +1,28 @@
+;;; test-dwim-shell-config-empty-dirs.el --- Tests for empty-dirs command builder -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Covers cj/dwim-shell--empty-dirs-command, which builds the find command for
+;; cj/dwim-shell-commands-remove-empty-directories. The command is scoped to an
+;; explicit root (shell-quoted) rather than the ambient current directory.
+
+;;; Code:
+
+(require 'ert)
+(require 'dwim-shell-config)
+
+(ert-deftest test-dwim-empty-dirs-command-shape ()
+ "Normal: builds a find ... -type d -empty -delete command for the root."
+ (let ((root "/home/me/proj"))
+ (should (equal (cj/dwim-shell--empty-dirs-command root)
+ (format "find %s -type d -empty -delete # <<*>>"
+ (shell-quote-argument root))))))
+
+(ert-deftest test-dwim-empty-dirs-command-quotes-spaces ()
+ "Boundary: a root with spaces is shell-quoted, not left to word-split."
+ (let ((cmd (cj/dwim-shell--empty-dirs-command "/home/me/my dir")))
+ (should (string-match-p (regexp-quote (shell-quote-argument "/home/me/my dir"))
+ cmd))
+ (should-not (string-match-p "find /home/me/my dir " cmd))))
+
+(provide 'test-dwim-shell-config-empty-dirs)
+;;; test-dwim-shell-config-empty-dirs.el ends here