aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-01-16 14:49:47 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2023-01-16 14:49:47 +0100
commit009e33bbc9084c63ad3e81b778855025826a0845 (patch)
tree4df08192db170eecfba00d96cb9b96d600fd7854
parentab6e9af55036567ec5dcd25d5b447d34ed9b5934 (diff)
Add test for file-has-changed-p
-rw-r--r--compat-29.el8
-rw-r--r--compat-tests.el26
2 files changed, 28 insertions, 6 deletions
diff --git a/compat-29.el b/compat-29.el
index 7b53d59..f8a6630 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -410,11 +410,11 @@ to `default-directory', and the result will also be relative."
(t
parent))))
-(compat-defvar file-has-changed-p--hash-table ;; <UNTESTED>
+(compat-defvar file-has-changed-p--hash-table ;; <compat-tests:file-has-changed-p>
(make-hash-table :test #'equal)
"Internal variable used by `file-has-changed-p'.")
-(compat-defun file-has-changed-p (file &optional tag) ;; <UNTESTED>
+(compat-defun file-has-changed-p (file &optional tag) ;; <compat-tests:file-has-changed-p>
"Return non-nil if FILE has changed.
The size and modification time of FILE are compared to the size
and modification time of the same FILE during a previous
@@ -431,8 +431,8 @@ the symbol of the calling function, for example."
(file-attribute-modification-time fileattr))))
(sym (concat (symbol-name tag) "@" file))
(cachedattr (gethash sym file-has-changed-p--hash-table)))
- (when (not (equal attr cachedattr))
- (puthash sym attr file-has-changed-p--hash-table))))
+ (when (not (equal attr cachedattr))
+ (puthash sym attr file-has-changed-p--hash-table))))
;;;; Defined in keymap.el
diff --git a/compat-tests.el b/compat-tests.el
index 93288c0..e79cff2 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -1215,7 +1215,7 @@
(should-not (directory-name-p "dir/subdir")))
(ert-deftest directory-empty-p ()
- (let ((name (make-temp-name "compat-tests")))
+ (let ((name (make-temp-name "/tmp/compat-tests")))
(make-directory name)
(should (directory-empty-p name))
(make-empty-file (file-name-concat name "file"))
@@ -1224,7 +1224,7 @@
(delete-directory name)))
(ert-deftest make-empty-file ()
- (let ((name (make-temp-name "compat-tests")))
+ (let ((name (make-temp-name "/tmp/compat-tests")))
(should-not (file-exists-p name))
(make-empty-file name)
(should-equal 0 (file-attribute-size (file-attributes name)))
@@ -1252,6 +1252,28 @@
(should-equal (expand-file-name "bar/.#b") (make-lock-file-name "bar/b"))
(should-equal (expand-file-name "bar/.#foo") (make-lock-file-name "bar/foo")))
+(ert-deftest file-has-changed-p ()
+ (let ((name (make-temp-file "/tmp/compat-tests")))
+ (should (file-has-changed-p name))
+ (should-not (file-has-changed-p name))
+ (should-not (file-has-changed-p name))
+ (should (file-has-changed-p name 'tag1))
+ (should-not (file-has-changed-p name 'tag1))
+ (should-not (file-has-changed-p name 'tag1))
+ (with-temp-buffer
+ (insert "changed")
+ (write-region (point-min) (point-max) name))
+ (should (file-has-changed-p name))
+ (should-not (file-has-changed-p name))
+ (should-not (file-has-changed-p name))
+ (should (file-has-changed-p name 'tag1))
+ (should-not (file-has-changed-p name 'tag1))
+ (should-not (file-has-changed-p name 'tag1))
+ (should (file-has-changed-p name 'tag2))
+ (should-not (file-has-changed-p name 'tag2))
+ (should-not (file-has-changed-p name 'tag2))
+ (delete-file name)))
+
(ert-deftest file-attribute-getters ()
(let ((attrs '(type link-number user-id group-id access-time modification-time
status-change-time size modes unspecified inode-number device-number)))