diff --git a/ChangeLog b/ChangeLog index 0ff62943..710603e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2026-04-24 Mats Lidell + +* test/hyrolo-tests.el (hyrolo-tests--add--error-cases): New test. + (hyrolo-tests--add-items-at-multiple-levels): + (hyrolo-tests--add-items-interactive): Fix quotes in docstring. + +* hyrolo.el (hyrolo-add): Handle not existing file error case. + 2026-04-21 Mats Lidell * Makefile (COVERAGE_TESTSPEC): Use test= for specifying the test selector diff --git a/hyrolo.el b/hyrolo.el index 6ccca4e4..9e07a030 100644 --- a/hyrolo.el +++ b/hyrolo.el @@ -401,7 +401,7 @@ entry which begins with the parent string." (mapcar #'list (hyrolo-get-file-list))))) (unless file (setq file (car (hyrolo-get-file-list)))) - (cond ((and file (or (not (stringp file)) (string-equal file ""))) + (cond ((and file (or (not (stringp file)) (string-equal file "") (not (file-exists-p file)))) (error "(hyrolo-add): Invalid file: `%s'" file)) ((and (file-exists-p file) (not (file-readable-p file))) (error "(hyrolo-add): File not readable: `%s'" file)) diff --git a/test/hyrolo-tests.el b/test/hyrolo-tests.el index ae0ff7b7..8dacb56d 100644 --- a/test/hyrolo-tests.el +++ b/test/hyrolo-tests.el @@ -28,8 +28,31 @@ (declare-function hy-test-helpers:consume-input-events "hy-test-helpers") +(ert-deftest hyrolo-tests--add--error-cases () + "Verify `hyrolo-add' error cases." + (defvar hyrolo-file) + (let ((hyrolo-file (make-temp-file "hypb" nil ".otl"))) + (unwind-protect + (let ((hyrolo-file-list (list hyrolo-file))) + (should-error (hyrolo-add "")) + (should-error (hyrolo-add 'symbol)) + (should-error (hyrolo-add "a" "")) + (should-error (hyrolo-add "a" 'symbol)) + (should-error (hyrolo-add "a/b/c")) + ;; File does not exist + (should-error (hyrolo-add "a" "/tmp/file-does-not-exist")) + ;; File not writable + (with-mock + (mock (file-writable-p hyrolo-file) => nil) + (should-error (hyrolo-add "a"))) + ;; File not readable + (with-mock + (mock (file-readable-p hyrolo-file) => nil) + (should-error (hyrolo-add "a")))) + (hy-delete-file-and-buffer hyrolo-file)))) + (ert-deftest hyrolo-tests--add-items-at-multiple-levels () - "`hyrolo-add` can add items at different levels." + "`hyrolo-add' can add items at different levels." (let ((hyrolo-file (make-temp-file "hypb" nil ".otl"))) (unwind-protect (let ((hyrolo-file-list (list hyrolo-file))) @@ -45,7 +68,7 @@ (hy-delete-file-and-buffer hyrolo-file)))) (ert-deftest hyrolo-tests--add-items-interactive () - "`hyrolo-add` can add items when called interactively." + "`hyrolo-add' can add items when called interactively." (let ((hyrolo-file (make-temp-file "hypb" nil ".otl"))) (unwind-protect (let ((hyrolo-file-list (list hyrolo-file)))