emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master a34c7d7: Add tests to verify error propagation in '


From: Philipp Stephani
Subject: [Emacs-diffs] master a34c7d7: Add tests to verify error propagation in 'json-insert'.
Date: Sat, 3 Feb 2018 15:15:57 -0500 (EST)

branch: master
commit a34c7d7470d5f749659658943bd4084942d873e3
Author: Philipp Stephani <address@hidden>
Commit: Philipp Stephani <address@hidden>

    Add tests to verify error propagation in 'json-insert'.
    
    * test/src/json-tests.el (json-tests--error): New error symbol.
    (json-insert/signal, json-insert/throw): New tests.
---
 test/src/json-tests.el | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/test/src/json-tests.el b/test/src/json-tests.el
index 47bccbe..3bbf9eb 100644
--- a/test/src/json-tests.el
+++ b/test/src/json-tests.el
@@ -26,6 +26,8 @@
 (require 'cl-lib)
 (require 'map)
 
+(define-error 'json-tests--error "JSON test error")
+
 (ert-deftest json-serialize/roundtrip ()
   (skip-unless (fboundp 'json-serialize))
   ;; The noncharacter U+FFFF should be passed through,
@@ -176,5 +178,35 @@ Test with both unibyte and multibyte strings."
     (should-not (bobp))
     (should (looking-at-p (rx " [456]" eos)))))
 
+(ert-deftest json-insert/signal ()
+  (skip-unless (fboundp 'json-insert))
+  (with-temp-buffer
+    (let ((calls 0))
+      (add-hook 'after-change-functions
+                (lambda (_begin _end _length)
+                  (cl-incf calls)
+                  (signal 'json-tests--error
+                          '("Error in `after-change-functions'")))
+                :local)
+      (should-error
+       (json-insert '((a . "b") (c . 123) (d . [1 2 t :false])))
+       :type 'json-tests--error)
+      (should (equal calls 1)))))
+
+(ert-deftest json-insert/throw ()
+  (skip-unless (fboundp 'json-insert))
+  (with-temp-buffer
+    (let ((calls 0))
+      (add-hook 'after-change-functions
+                (lambda (_begin _end _length)
+                  (cl-incf calls)
+                  (throw 'test-tag 'throw-value))
+                :local)
+      (should-error
+       (catch 'test-tag
+         (json-insert '((a . "b") (c . 123) (d . [1 2 t :false]))))
+       :type 'no-catch)
+      (should (equal calls 1)))))
+
 (provide 'json-tests)
 ;;; json-tests.el ends here



reply via email to

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