aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test-org-agenda-config-add-files.el12
-rw-r--r--tests/test-org-refile-config--scan-dir.el57
2 files changed, 69 insertions, 0 deletions
diff --git a/tests/test-org-agenda-config-add-files.el b/tests/test-org-agenda-config-add-files.el
index e977cc68..8c6f2a69 100644
--- a/tests/test-org-agenda-config-add-files.el
+++ b/tests/test-org-agenda-config-add-files.el
@@ -7,6 +7,7 @@
;;; Code:
(require 'ert)
+(require 'cl-lib)
(add-to-list 'load-path (expand-file-name "tests" user-emacs-directory))
(require 'testutil-general)
@@ -129,5 +130,16 @@
(should (member "/existing/file.org" org-agenda-files))))
(cj/delete-test-base-dir)))
+(ert-deftest test-org-agenda-config-add-files-boundary-missing-dir-warns-not-errors ()
+ "Boundary: a missing project directory warns and adds nothing, without erroring.
+Previously `directory-files' on a missing dir crashed the agenda build."
+ (let ((org-agenda-files '("/existing/file.org"))
+ (warned nil))
+ (cl-letf (((symbol-function 'display-warning)
+ (lambda (&rest _) (setq warned t))))
+ (cj/add-files-to-org-agenda-files-list "/no/such/cj-agenda/dir/"))
+ (should warned)
+ (should (equal org-agenda-files '("/existing/file.org")))))
+
(provide 'test-org-agenda-config-add-files)
;;; test-org-agenda-config-add-files.el ends here
diff --git a/tests/test-org-refile-config--scan-dir.el b/tests/test-org-refile-config--scan-dir.el
new file mode 100644
index 00000000..184fa98e
--- /dev/null
+++ b/tests/test-org-refile-config--scan-dir.el
@@ -0,0 +1,57 @@
+;;; test-org-refile-config--scan-dir.el --- Tests for refile dir scan -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Unit tests for cj/--org-refile-scan-dir, which lists the todo.org files
+;; under one root for the refile-target scan. A missing, unreadable, or
+;; permission-denied root must be non-fatal: it logs a warning and returns
+;; nil so the rest of the scan continues, instead of silently swallowing the
+;; failure or crashing on a missing directory.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'org-refile-config)
+
+;;; Normal Cases
+
+(ert-deftest test-org-refile-scan-dir-normal-finds-todo ()
+ "Normal: a readable directory with a todo.org returns it."
+ (let ((dir (make-temp-file "cj-refile-scan-" t)))
+ (unwind-protect
+ (progn
+ (write-region "* TODO x\n" nil (expand-file-name "todo.org" dir))
+ (let ((found (cj/--org-refile-scan-dir dir)))
+ (should (= 1 (length found)))
+ (should (string-suffix-p "todo.org" (car found)))))
+ (delete-directory dir t))))
+
+;;; Boundary Cases
+
+(ert-deftest test-org-refile-scan-dir-boundary-missing-warns-and-returns-nil ()
+ "Boundary: a missing directory warns and returns nil, without erroring."
+ (let ((warned nil))
+ (cl-letf (((symbol-function 'display-warning)
+ (lambda (&rest _) (setq warned t))))
+ (should (null (cj/--org-refile-scan-dir "/no/such/cj-refile/dir/")))
+ (should warned))))
+
+;;; Error Cases
+
+(ert-deftest test-org-refile-scan-dir-error-permission-denied-warns-and-returns-nil ()
+ "Error: a permission-denied during the scan warns and returns nil."
+ (let ((dir (make-temp-file "cj-refile-perm-" t))
+ (warned nil))
+ (unwind-protect
+ (cl-letf (((symbol-function 'directory-files-recursively)
+ (lambda (&rest _) (signal 'permission-denied (list dir))))
+ ((symbol-function 'display-warning)
+ (lambda (&rest _) (setq warned t))))
+ (should (null (cj/--org-refile-scan-dir dir)))
+ (should warned))
+ (delete-directory dir t))))
+
+(provide 'test-org-refile-config--scan-dir)
+;;; test-org-refile-config--scan-dir.el ends here