leiningen - clojure.test throws? not working in the repl -


following docstring in source of clojure.test, issue following in repl:

(use 'clojure.test) (is (thrown? arithmeticexception (/ 1 0))) 

and other variations substituting arithmeticexception java.lang.arithmeticexception. yet exception never captured clojure.test rather bubbles way top:

> #error {  :cause "divide zero"  :via  [{:type java.lang.arithmeticexception    :message "divide zero"    :at > [clojure.lang.numbers divide "numbers.java" 158]}]  :trace  > [[clojure.lang.numbers divide "numbers.java" 158]   > [clojure.lang.numbers divide "numbers.java" 3808]   [api.core$eval1305 > invokestatic "form-init8750388124499546857.clj" 1]   > [api.core$eval1305 invoke "form-init8750388124499546857.clj" 1]   > [clojure.lang.compiler eval "compiler.java" 6927]   > [clojure.lang.compiler eval "compiler.java" 6890]   [clojure.core$eval > invokestatic "core.clj" 3105]   [clojure.core$eval invoke "core.clj" > 3101]   [clojure.main$repl$read_eval_print__7408$fn__7411 invoke > "main.clj" 240]   [clojure.main$repl$read_eval_print__7408 invoke > "main.clj" 240]   [clojure.main$repl$fn__7417 invoke "main.clj" 258]   > [clojure.main$repl invokestatic "main.clj" 258]   [clojure.main$repl > doinvoke "main.clj" 174]   [clojure.lang.restfn invoke "restfn.java" > 1523]   > [clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__667 > invoke "interruptible_eval.clj" 87]   [clojure.lang.afn applytohelper > "afn.java" 152]   [clojure.lang.afn applyto "afn.java" 144]   > [clojure.core$apply invokestatic "core.clj" 646]   > [clojure.core$with_bindings_star_ invokestatic "core.clj" 1881]   > [clojure.core$with_bindings_star_ doinvoke "core.clj" 1881]   > [clojure.lang.restfn invoke "restfn.java" 425]   > [clojure.tools.nrepl.middleware.interruptible_eval$evaluate > invokestatic "interruptible_eval.clj" 85]   > [clojure.tools.nrepl.middleware.interruptible_eval$evaluate invoke > "interruptible_eval.clj" 55]   > [clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__712$fn__715 > invoke "interruptible_eval.clj" 222]   > [clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__707 > invoke "interruptible_eval.clj" 190]   [clojure.lang.afn run > "afn.java" 22]   [java.util.concurrent.threadpoolexecutor runworker > "threadpoolexecutor.java" 1142]   > [java.util.concurrent.threadpoolexecutor$worker run > "threadpoolexecutor.java" 617]   [java.lang.thread run "thread.java" > 745]]} 

what might be? other stuff clojure.test work in repl expected.

version information:

leiningen 2.7.1 on java 1.8.0_101 java hotspot(tm) 64-bit server vm

> nrepl server started on port 44025 on host 127.0.0.1 - > nrepl://127.0.0.1:44025 repl-y 0.3.7, nrepl 0.2.12 clojure 1.8.0 java > hotspot(tm) 64-bit server vm 1.8.0_101-b13 

use it/wrap in (clojure.test/deftest...)


assuming:

(require '[clojure.test :as t]) 

pass example

(t/deftest    (t/testing "a test"      (t/is (thrown? arithmeticexception (/ 1 0)))))  (a) nil 

fail example

(t/deftest    (t/testing "a test"      (t/is (thrown? nullpointerexception (/ 1 0)))))  (a) ; error in (a) (numbers.java:158) ; test ; expected: (thrown? nullpointerexception (/ 1 0)) ; actual: java.lang.arithmeticexception: divide 0 

you can use t/run-tests summary/stats


alternatively seems can use t/test-var directly so

(t/test-var (t/is (thrown? arithmeticexception (/ 1 0)))) nil 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -