]> git.eshelyaron.com Git - emacs.git/commitdiff
add non locals tests
authorAndrea Corallo <andrea_corallo@yahoo.it>
Sun, 23 Jun 2019 10:08:59 +0000 (12:08 +0200)
committerAndrea Corallo <akrl@sdf.org>
Wed, 1 Jan 2020 10:33:44 +0000 (11:33 +0100)
test/src/comp-tests.el

index 6a643df9d3ec136248bf96145a9d8b8eb8bd2698..6a7370a880ca0d5e9d0c71f6141c1ef2209349a4 100644 (file)
                       (buffer-string))
                    "abcd")))
 
+(ert-deftest comp-tests-non-locals ()
+  "Test non locals."
+  (defun comp-tests-err-arith-f ()
+    (/ 1 0))
+  (defun comp-tests-err-foo-f ()
+    (error "foo"))
+
+  (defun comp-tests-condition-case-0-f ()
+    ;; Bpushhandler Bpophandler
+    (condition-case
+        err
+        (comp-tests-err-arith-f)
+      (arith-error (concat "arith-error "
+                           (error-message-string err)
+                           " catched"))
+      (error (concat "error "
+                     (error-message-string err)
+                     " catched"))))
+
+  (defun comp-tests-condition-case-1-f ()
+    ;; Bpushhandler Bpophandler
+    (condition-case
+        err
+        (comp-tests-err-foo-f)
+      (arith-error (concat "arith-error "
+                           (error-message-string err)
+                           " catched"))
+      (error (concat "error "
+                     (error-message-string err)
+                     " catched"))))
+
+  (defun comp-tests-catch-f (f)
+    (catch 'foo
+      (funcall f)))
+
+  (defun comp-tests-throw-f (x)
+    (throw 'foo x))
+
+  (byte-compile #'comp-tests-condition-case-0-f)
+  (native-compile #'comp-tests-condition-case-0-f)
+  (byte-compile #'comp-tests-condition-case-1-f)
+  (native-compile #'comp-tests-condition-case-1-f)
+  (byte-compile #'comp-tests-catch-f)
+  (native-compile #'comp-tests-catch-f)
+  (byte-compile #'comp-tests-throw-f)
+  (native-compile #'comp-tests-throw-f)
+
+  (should (string= (comp-tests-condition-case-0-f)
+                   "arith-error Arithmetic error catched"))
+  (should (string= (comp-tests-condition-case-1-f)
+                   "error foo catched"))
+  (should (= (comp-tests-catch-f (lambda () (throw 'foo 3))) 3))
+  (should (= (catch 'foo
+               (comp-tests-throw-f 3)))))
+
 (ert-deftest comp-tests-gc ()
   "Try to do some longer computation to let the gc kick in."
   (dotimes (_ 100000)