From 4a7927bf7352e3e626dfb596a70bec9d3bc532eb Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sat, 23 May 2026 20:20:17 -0500 Subject: 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. --- tests/test-dwim-shell-config-empty-dirs.el | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/test-dwim-shell-config-empty-dirs.el (limited to 'tests') 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 -- cgit v1.2.3