diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-23 20:20:17 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-23 20:20:17 -0500 |
| commit | ecbba038835c1eeb4784f4894d388bf9356fa10b (patch) | |
| tree | bb6945d3e52a332f364585541a04211a6e8045c7 /tests | |
| parent | 34181c70d37cc5bf44050fc42c7495258be0ce7a (diff) | |
| download | dotemacs-ecbba038835c1eeb4784f4894d388bf9356fa10b.tar.gz dotemacs-ecbba038835c1eeb4784f4894d388bf9356fa10b.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')
| -rw-r--r-- | tests/test-dwim-shell-config-empty-dirs.el | 28 |
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 |
