blob: 011789e098efaaf475f98436ea352414c0a894ea (
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
 | ;;; 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
 |