1
0
mirror of https://github.com/janet-lang/janet synced 2025-09-10 23:06:08 +00:00

janet_try macro and janet_restore function.

This allows catching panics without using pcall.
This commit is contained in:
Calvin Rose
2020-09-19 18:47:47 -05:00
parent c455bdad11
commit d1f0a13ddc
3 changed files with 52 additions and 46 deletions

View File

@@ -3,7 +3,6 @@
(var num-tests-passed 0)
(var num-tests-run 0)
(var suite-num 0)
(var numchecks 0)
(var start-time 0)
(defn assert
@@ -13,16 +12,8 @@
(++ num-tests-run)
(when x (++ num-tests-passed))
(if x
(do
(when (= numchecks 25)
(set numchecks 0)
(print))
(++ numchecks)
(file/write stdout "\e[32m✔\e[0m"))
(do
(file/write stdout "\n\e[31m✘\e[0m ")
(set numchecks 0)
(print e)))
(xprintf stdout "\e[32m✔\e[0m %s: %v" (string e) x)
(xprintf stdout "\n\e[31m✘\e[0m %s: %v" (string e) x))
x)
(defmacro assert-error