From: Philipp Stephani Date: Sat, 3 Feb 2018 20:14:59 +0000 (+0100) Subject: Add tests to verify error propagation in 'json-insert'. X-Git-Tag: emacs-27.0.90~5727 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=a34c7d7470d5f749659658943bd4084942d873e3;p=emacs.git 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. --- diff --git a/test/src/json-tests.el b/test/src/json-tests.el index 47bccbe6f3e..3bbf9eb96b0 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