Tidier checks for eval failure modes
This commit is contained in:
parent
44416fc276
commit
503b4e1f81
@ -875,18 +875,6 @@
|
|||||||
(assert (= None (eval (quote (print ""))))))
|
(assert (= None (eval (quote (print ""))))))
|
||||||
|
|
||||||
|
|
||||||
(defmacro assert-raise [exc-type &rest body]
|
|
||||||
`(try
|
|
||||||
(do
|
|
||||||
(eval ~@body)
|
|
||||||
(assert False "we shouldn't have arrived here"))
|
|
||||||
(except [e Exception]
|
|
||||||
(assert (instance? ~exc-type e)
|
|
||||||
(.format "Expected exception of type {}, got {}: {}"
|
|
||||||
(. ~exc-type --name--)
|
|
||||||
(. (type e) --name--)
|
|
||||||
(str e))))))
|
|
||||||
|
|
||||||
(defn test-eval-globals []
|
(defn test-eval-globals []
|
||||||
"NATIVE: test eval with explicit global dict"
|
"NATIVE: test eval with explicit global dict"
|
||||||
(assert (= 'bar (eval (quote foo) {'foo 'bar})))
|
(assert (= 'bar (eval (quote foo) {'foo 'bar})))
|
||||||
@ -905,10 +893,11 @@
|
|||||||
(defn test-eval-failure []
|
(defn test-eval-failure []
|
||||||
"NATIVE: test eval failure modes"
|
"NATIVE: test eval failure modes"
|
||||||
(import [hy.errors [HyTypeError]])
|
(import [hy.errors [HyTypeError]])
|
||||||
(assert-raise HyTypeError '(eval))
|
; yo dawg
|
||||||
(assert-raise HyTypeError '(eval "snafu"))
|
(try (eval '(eval)) (except [e HyTypeError]) (else (assert False)))
|
||||||
(assert-raise HyTypeError '(eval 'false []))
|
(try (eval '(eval "snafu")) (except [e HyTypeError]) (else (assert False)))
|
||||||
(assert-raise HyTypeError '(eval 'false {} 1)))
|
(try (eval 'false []) (except [e HyTypeError]) (else (assert False)))
|
||||||
|
(try (eval 'false {} 1) (except [e HyTypeError]) (else (assert False))))
|
||||||
|
|
||||||
|
|
||||||
(defn test-import-syntax []
|
(defn test-import-syntax []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user