diff --git a/ChangeLog b/ChangeLog index ab62ebb4..f2a07efe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2026-11-04 Mats Lidell + +* Makefile (verify-clean-test-run): Target that runs checks for left over + resources. + (test-ert): Use verify-clean-test-run. + +* test/hywiki-tests.el (hywiki-tests--preserve-hywiki-mode): Store and reset + prior hywiki-directory on test completion. Resetting hywiki-mode recreates + the temporary hywiki-directory otherwise. + +* test/hib-social-tests.el (hibtypes-repo-cache-does-not-exist-test): +* test/hyrolo-tests.el (hyrolo-tests--rename): +* test/hywiki-tests.el (hywiki-tests--edit): Avoid deleting files that do + not exist. + +* test/hywiki-tests.el (hywiki-tests--kill-empty-wiki-buffer): Helper for + removing empty hywiki files and trigger a test error if it is not removed + when buffer is killed. + (hywiki-tests--add-path-link-v2): + (hywiki-tests--action-key-on-hywikiword-displays-page): Use + hywiki-tests--kill-empty-wiki-buffer. + 2026-10-30 Mats Lidell * man/Lucide-LICENSE: Licens information for svg icons. diff --git a/Makefile b/Makefile index 19a6d23c..ad50753e 100644 --- a/Makefile +++ b/Makefile @@ -666,6 +666,15 @@ test-ert: (ert-batch-print-length nil) \ $(HYPB_ERT_BATCH_BT) (ert-batch-backtrace-right-margin 2048)) \ $(LOAD_TEST_ERT_FILES) $(HYPB_ERT_FAILURE) $(HYPB_ERT_BATCH))" + $(MAKE) verify-clean-test-run + +# Verify that temporary files and directories are cleaned after a test run. +.PHONY: verify-clean-test-run +verify-clean-test-run: + @if [ -n "$$(find /tmp -name 'hywiki*' -print -quit 2>/dev/null)" ]; then \ + echo "hywiki test folders not removed!"; \ + exit 1; \ + fi # Run all tests by starting an Emacs that runs the tests interactively in windowed mode. .PHONY: all-tests test-all diff --git a/test/hib-social-tests.el b/test/hib-social-tests.el index 22476168..d77362a5 100644 --- a/test/hib-social-tests.el +++ b/test/hib-social-tests.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell ;; ;; Orig-Date: 20-Feb-21 at 23:24:00 -;; Last-Mod: 3-Mar-24 at 11:28:17 by Mats Lidell +;; Last-Mod: 4-Nov-26 at 17:33:51 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -14,7 +14,7 @@ ;;; Commentary: -;; +;; ;;; Code: @@ -63,8 +63,10 @@ (let ((hibtypes-git-repos-cache "not-existing-file")) (unwind-protect (mocklet (((hibtypes-git-build-repos-cache t) => t)) - (should (hibtypes-git-build-or-add-to-repos-cache "project"))) - (hy-delete-file-and-buffer hibtypes-git-repos-cache)))) + (should (hibtypes-git-build-or-add-to-repos-cache "project")) + (should-not (file-exists-p hibtypes-git-repos-cache))) + (when (file-exists-p hibtypes-git-repos-cache) + (delete-file hibtypes-git-repos-cache))))) (ert-deftest hibtypes-repo-cache-exist-test () "Verify project is added if cache exist." @@ -84,4 +86,3 @@ ;; End: ;;; hib-social-tests.el ends here - diff --git a/test/hyrolo-tests.el b/test/hyrolo-tests.el index 313f3897..4e72e4fd 100644 --- a/test/hyrolo-tests.el +++ b/test/hyrolo-tests.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell ;; ;; Orig-Date: 19-Jun-21 at 22:42:00 -;; Last-Mod: 13-Oct-26 at 17:51:03 by Bob Weiner +;; Last-Mod: 4-Nov-26 at 17:26:40 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -2145,8 +2145,12 @@ Dependencies on the consult package are mocked." (should (string-search "Your personal rolo file is now" cap))) (should (file-exists-p new-file-backup)) (with-current-buffer (find-file new-file) - (should (looking-at-p "old-file")))) - (hy-delete-files-and-buffers (list old-file old-file-backup new-file new-file-backup))))) + (should (looking-at-p "old-file"))) + (dolist (f (list old-file old-file-backup)) + (should-not (file-exists-p f)))) + (dolist (f (list old-file old-file-backup)) + (delete-file f)) + (hy-delete-files-and-buffers (list new-file new-file-backup))))) (ert-deftest hyrolo-tests--edit-entry-edits-the-selected-match () "Verify `hyrolo-edit-entry' moves to the selected match and not a substring." diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el index 717ffb60..2d19e1f8 100644 --- a/test/hywiki-tests.el +++ b/test/hywiki-tests.el @@ -164,9 +164,16 @@ Last two elements are optional.") :test-num test-num :before before :after after))))) hywiki-tests--edit-string-pairs)) - (let ((default-directory hywiki-directory)) - (hy-delete-files-and-buffers - '("AI.org" "FAI.org" "Hi.org" "HiHo.org" "HyWiki.org" "HyWikiW.org" "HyWikiWord.org" "MyWikiWord.org" "Non.org" "Wiki.org"))))) + (let ((files '("AI.org" "FAI.org" "Hi.org" "HiHo.org" "HyWiki.org" "HyWikiW.org" "HyWikiWord.org" "MyWikiWord.org" "Non.org" "Wiki.org"))) + ;; Remove buffers for files. We remove empty HyWiki buffers so + ;; this will remove the file if it is empty. + (dolist (f files) + (let ((buf (get-file-buffer f))) + (when buf + (kill-buffer buf)))) + ;; Go over and remove the files that still exists + (dolist (f files) + (delete-file f))))) (message "(hywiki-tests--edit): took %.2f seconds" test-time))) (defun hywiki-tests--get-brace-strings (s) @@ -288,10 +295,23 @@ around the call. This is for simulating the command loop." (run-hooks 'post-self-insert-hook)) (run-hooks 'post-command-hook)))) +(defun hywiki-tests--kill-empty-wiki-buffer (wikifile) + "Delete empty WIKIFILE by deleting its buffer. +Verify that the file is deleted. If it is still there raise a test error +and remove it." + (should (file-exists-p wikifile)) + (let ((buf (get-file-buffer wikifile))) + (kill-buffer buf)) + (unwind-protect + (should-not (file-exists-p wikifile)) + (when (file-exists-p wikifile) + (delete-file wikifile)))) + (defmacro hywiki-tests--preserve-hywiki-mode (&rest body) "Restore hywiki-mode after running BODY." (declare (indent 0) (debug t)) `(let ((prior-hywiki-mode hywiki-mode) + (prior-hywiki-directory hywiki-directory) (hywiki-directory (file-name-as-directory (make-temp-file "hywiki" t))) wiki-page) (save-window-excursion @@ -313,9 +333,14 @@ around the call. This is for simulating the command loop." ;; after `hywiki-mode' is enabled. (setq wiki-page (cdr (hywiki-add-page "WikiWord" nil t))) ,@body) - (hy-delete-files-and-buffers (list wiki-page (hywiki-cache-default-file))) + (let ((buf (get-file-buffer wiki-page))) + (when buf + (kill-buffer buf)) + (delete-file wiki-page)) + (hy-delete-file-and-buffer (hywiki-cache-default-file)) (hywiki-tests--delete-hywiki-dir-and-buffer hywiki-directory) (unless (eq hywiki-mode prior-hywiki-mode) + (setq hywiki-directory prior-hywiki-directory) (hywiki-mode prior-hywiki-mode)))))))) (ert-deftest hywiki-tests--verify-preserve-hywiki-mode () @@ -364,7 +389,8 @@ around the call. This is for simulating the command loop." (action-key) (should (equal (cons 'page wikifile) (hywiki-get-referent "WikiPage")))) (sit-for 0.01) - (hy-delete-file-and-buffer (expand-file-name wikifile hywiki-directory)))))) + (hywiki-tests--kill-empty-wiki-buffer + (expand-file-name wikifile hywiki-directory)))))) (ert-deftest hywiki-tests--assist-key-on-hywikiword-displays-help () "Verify `assist-key' on a prefixed WikiWord, outside of hywiki-directory, displays help for the WikiWord link." @@ -2050,7 +2076,8 @@ expected result." (hywiki-add-path-link "HoRef" wikiHo 3) (should (string= (concat (file-name-nondirectory wikiHo) ":L1:C2") (cdr (hywiki-get-referent "HoRef")))))) - (hy-delete-files-and-buffers (list wikiHi wikiHo)))))) + (hywiki-tests--kill-empty-wiki-buffer wikiHi) + (hy-delete-file-and-buffer wikiHo))))) (ert-deftest hywiki-test--hywiki-mode () "Verify activating local and global `hywiki-mode'."