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 | fb5cc4d5a026ec17fb89dfb26ac40ec1a28f315d (patch) | |
| tree | 2e1888132ed9549f8274b7df4f70a98321470ab3 /tests | |
| parent | 4ea4103760d7d73fb090b0f27df8def913519930 (diff) | |
| download | dotemacs-fb5cc4d5a026ec17fb89dfb26ac40ec1a28f315d.tar.gz dotemacs-fb5cc4d5a026ec17fb89dfb26ac40ec1a28f315d.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 000000000..1c7129c38 --- /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 |
