emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/persist 5b83259 1/2: perist can now work with values ot


From: Phillip Lord
Subject: [elpa] externals/persist 5b83259 1/2: perist can now work with values other than numbers
Date: Mon, 8 Jul 2019 17:01:51 -0400 (EDT)

branch: externals/persist
commit 5b832595f448189572e8886baaa260e164bba543
Author: Phillip Lord <address@hidden>
Commit: Phillip Lord <address@hidden>

    perist can now work with values other than numbers
    
    No longer compare arbitrary values with `=` in persist-save.
---
 persist.el            |  4 +--
 test/persist-tests.el | 76 ++++++++++++++++++++++++++++++++++-----------------
 2 files changed, 53 insertions(+), 27 deletions(-)

diff --git a/persist.el b/persist.el
index a741b6d..223f239 100644
--- a/persist.el
+++ b/persist.el
@@ -132,8 +132,8 @@ variables persist automatically when Emacs exits."
   (unless (persist--persistant-p symbol)
     (error (format
             "Symbol %s is not persistant" symbol)))
-  (when (not (= (symbol-value symbol)
-                (persist-default symbol)))
+  (unless (equal (symbol-value symbol)
+                 (persist-default symbol))
     (let ((dir-loc
            (file-name-directory
             (persist--file-location symbol))))
diff --git a/test/persist-tests.el b/test/persist-tests.el
index 2e06dc6..9fa406f 100644
--- a/test/persist-tests.el
+++ b/test/persist-tests.el
@@ -21,11 +21,15 @@
   ;; do not save not persist variables
   (should-error
    (with-local-temp-persist
-    (persist-save (cl-gensym)))))
+    (persist-save (cl-gensym)))
+   :type 'error
+   :exclude-subtypes t))
 
 (ert-deftest test-persist-save ()
   (with-local-temp-persist
    (let ((sym (cl-gensym)))
+     ;; precondition
+   (should-not (file-exists-p (persist--file-location sym)))
      (set sym 10)
      (persist-symbol sym 10)
      (persist-save sym)
@@ -43,6 +47,27 @@
      (should-error
       (persist-save 'fred)))))
 
+(ert-deftest test-persist-save-non-number ()
+  "Test saving something that is not a number.
+
+`test-persist-save' missed "
+  (with-local-temp-persist
+   (let ((sym (cl-gensym)))
+     (set sym "fred")
+     (persist-symbol sym "fred")
+     (persist-save sym)
+     (should t)
+     (should-not (file-exists-p (persist--file-location sym)))
+     (set sym "george")
+     (persist-save sym)
+     (should (file-exists-p (persist--file-location sym)))
+     (should
+      (string-match-p
+       "george"
+       (with-temp-buffer
+         (insert-file-contents (persist--file-location sym))
+         (buffer-string)))))))
+
 (ert-deftest test-persist-load ()
   (with-local-temp-persist
    (let ((sym (cl-gensym)))
@@ -75,27 +100,28 @@
               (persist-default 'test-persist-variable)))))
 
 (ert-deftest test-persist-location ()
-   (let ((sym (cl-gensym)))
-     (set sym 10)
-     (persist-symbol sym 10)
-     (persist-location sym "./persist-defined-location")
-     (should
-      (equal (expand-file-name
-              (symbol-name sym)
-              "./persist-defined-location/")
-             (persist--file-location sym)))
-     (persist-save sym)
-     (should t)
-     (should-not (file-exists-p (persist--file-location sym)))
-     (set sym 20)
-     (persist-save sym)
-     (should (file-exists-p (persist--file-location sym)))
-     (should
-      (string-match-p
-       "20"
-       (with-temp-buffer
-         (insert-file-contents (persist--file-location sym))
-         (buffer-string))))
-     (should-error
-      (persist-save 'fred))
-     (delete-directory "./persist-defined-location" t)))
+  (unwind-protect
+      (let ((sym (cl-gensym)))
+        (delete-directory "./persist-defined-location" t)
+        (set sym 10)
+        (persist-symbol sym 10)
+        (persist-location sym "./persist-defined-location")
+        (should
+         (equal (expand-file-name
+                 (symbol-name sym)
+                 "./persist-defined-location/")
+                (persist--file-location sym)))
+        (persist-save sym)
+        (should-not (file-exists-p (persist--file-location sym)))
+        (set sym 20)
+        (persist-save sym)
+        (should (file-exists-p (persist--file-location sym)))
+        (should
+         (string-match-p
+          "20"
+          (with-temp-buffer
+            (insert-file-contents (persist--file-location sym))
+            (buffer-string))))
+        (should-error
+         (persist-save 'fred)))
+    (delete-directory "./persist-defined-location" t)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]