diff options
| author | Craig Jennings <c@cjennings.net> | 2025-10-12 11:47:26 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-10-12 11:47:26 -0500 |
| commit | 092304d9e0ccc37cc0ddaa9b136457e56a1cac20 (patch) | |
| tree | ea81999b8442246c978b364dd90e8c752af50db5 /tests/test-fs-validate-path.el | |
changing repositories
Diffstat (limited to 'tests/test-fs-validate-path.el')
| -rw-r--r-- | tests/test-fs-validate-path.el | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test-fs-validate-path.el b/tests/test-fs-validate-path.el new file mode 100644 index 00000000..011789e0 --- /dev/null +++ b/tests/test-fs-validate-path.el @@ -0,0 +1,45 @@ +;;; test-tool-library-cj/fs-validate-path.el --- ERT tests for cj/fs-validate-path -*- lexical-binding: t; -*- + +;; Author: gptel-tool-writer and cjennings +;; Keywords: tests, filesystem, tools + +;;; Commentary: +;; ERT tests for the cj/fs-validate-path function from tool-filesystem-library.el. +;; Place this file in ~/.emacs.d/tests/ and load it to run tests. + +;;; Code: + +(require 'ert) +(require 'f) +(require 'tool-filesystem-library) + +(ert-deftest test-cj/fs-validate-path-normal-home () + "Normal: validate home directory path." + (should (string-prefix-p (expand-file-name "~") + (cj/fs-validate-path "~")))) + +(ert-deftest test-cj/fs-validate-path-normal-temp () + "Normal: validate temp directory path." + (let ((temp (expand-file-name temporary-file-directory))) + (should (string-prefix-p temp (cj/fs-validate-path temp))))) + +(ert-deftest test-cj/fs-validate-path-error-outside () + "Error: path outside allowed directories." + (should-error (cj/fs-validate-path "/etc/passwd"))) + +(ert-deftest test-cj/fs-validate-path-error-nonexistent () + "Error: non-existent path." + (should-error (cj/fs-validate-path (format "/tmp/nonexistent-%d" (random 100000))))) + +(ert-deftest test-cj/fs-validate-path-error-unreadable () + "Error: unreadable path." + (let ((file (make-temp-file "test-unreadable"))) + (unwind-protect + (progn + (set-file-modes file 0) + (should-error (cj/fs-validate-path file))) + (set-file-modes file #o644) + (delete-file file)))) + +(provide 'test-tool-library-cj/fs-validate-path) +;;; test-tool-library-cj/fs-validate-path.el ends here |
