blob: 3b9803583e6c6636321f4751f5b1bb5bc43a1fd7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
;;; test-org-drill-config--drill-files-or-error.el --- Tests for validated drill file listing -*- lexical-binding: t; -*-
;;; Commentary:
;; Unit tests for cj/--drill-files-or-error, the single validated entry point
;; that drill capture templates and the drill commands share. It returns the
;; drill files in a directory or signals a clear `user-error' when the
;; directory is missing, unreadable, or empty — instead of leaking a low-level
;; error from `directory-files' or handing `completing-read' an empty list.
;;; Code:
(require 'ert)
(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
(require 'org-drill-config)
;;; Normal Cases
(ert-deftest test-org-drill--files-or-error-normal-lists-org-files ()
"Normal: a directory with drill files returns their names."
(let ((dir (make-temp-file "cj-drill-or-error-" t)))
(unwind-protect
(progn
(write-region "" nil (expand-file-name "a.org" dir))
(write-region "" nil (expand-file-name "b.org" dir))
(should (equal '("a.org" "b.org")
(cj/--drill-files-or-error dir))))
(delete-directory dir t))))
;;; Boundary Cases
(ert-deftest test-org-drill--files-or-error-boundary-empty-dir-signals ()
"Boundary: an existing but empty directory signals a clear user-error."
(let ((dir (make-temp-file "cj-drill-or-error-empty-" t)))
(unwind-protect
(should-error (cj/--drill-files-or-error dir) :type 'user-error)
(delete-directory dir t))))
(ert-deftest test-org-drill--files-or-error-boundary-only-non-org-signals ()
"Boundary: a directory with no .org files signals a user-error."
(let ((dir (make-temp-file "cj-drill-or-error-nonorg-" t)))
(unwind-protect
(progn
(write-region "" nil (expand-file-name "notes.txt" dir))
(should-error (cj/--drill-files-or-error dir) :type 'user-error))
(delete-directory dir t))))
;;; Error Cases
(ert-deftest test-org-drill--files-or-error-missing-dir-signals-user-error ()
"Error: a missing directory signals a `user-error', not a low-level error."
(should-error (cj/--drill-files-or-error "/no/such/cj-drill/dir/")
:type 'user-error))
(provide 'test-org-drill-config--drill-files-or-error)
;;; test-org-drill-config--drill-files-or-error.el ends here
|