Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2026-04-24 Mats Lidell <matsl@gnu.org>

* 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 <matsl@gnu.org>

* Makefile (COVERAGE_TESTSPEC): Use test= for specifying the test selector
Expand Down
2 changes: 1 addition & 1 deletion hyrolo.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
27 changes: 25 additions & 2 deletions test/hyrolo-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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)))
Expand Down