Fork me on GitHub
#clojure-spec
<
2017-02-19
>
Yehonathan Sharvit08:02:31

Is there a way to instrument by default while in dev environment?

gfredericks14:02:49

@viebel I think you could pull that off with leiningen profiles; not sure how that would interact with code reloading though

nblumoe15:02:43

Is there an established standard to run spec tests (`stest/check`) from a clojure.test suite (e.g. on lein test)?

tbaldridge15:02:01

@nblumoe not a standard, but I would probably reach for test.check's defspec: https://github.com/clojure/test.check#clojuretest-integration

tbaldridge15:02:25

Call that and use (s/gen ::my-spec) to get the gen to us in prop/for-all

gfredericks15:02:22

If it's just the builtin spec tests, then just using deftest and wrapping the stest/check call in an assertion might make more sense

gfredericks15:02:53

defspec would be more useful for custom assertions/tests

nblumoe15:02:29

@gfredericks something like (deftest specs (is (stest/check))) would not be sufficient as it seems, what would you check for?

gfredericks15:02:29

Examine the return value. Is there a result key?

Yehonathan Sharvit15:02:01

It’s for cljs but not too hard to adapt to clojure

nblumoe15:02:06

thx. If I understand correctly all three solutions require looking at the :failure key manually / with a helper. Okay then I will do that too. Was hoping for a generic integration into clojure.test

nblumoe16:02:39

ok works from the REPL and via Cider, but not with lein test. Any ideas? Here is the error (I don’t get it so far tbh):

ERROR in (foo) (FutureTask.java:122)
foo
expected: (nil? (-> spec-check first :failure))
  actual: java.util.concurrent.ExecutionException: java.lang.ClassCastException: clojure.lang.AFunction$1 cannot be cast to clojure.lang.MultiFn, compiling:(clojure/test/check/clojure_test.cljc:95:1)
 at java.util.concurrent.FutureTask.report (FutureTask.java:122)
    java.util.concurrent.FutureTask.get (FutureTask.java:192)
    clojure.core$deref_future.invokeStatic (core.clj:2290)
    clojure.core$future_call$reify__9377.deref (core.clj:6849)
    clojure.core$deref.invokeStatic (core.clj:2310)
    clojure.core$deref.invoke (core.clj:2296)
    clojure.core$map$fn__6881.invoke (core.clj:2728)
    clojure.lang.LazySeq.sval (LazySeq.java:40)
    clojure.lang.LazySeq.seq (LazySeq.java:56)
    clojure.lang.LazySeq.first (LazySeq.java:71)
    clojure.lang.RT.first (RT.java:682)
    clojure.core$first__6404.invokeStatic (core.clj:55)
    clojure.core/first (core.clj:55)
    geomix.calc.pva_test$check_SINGLEQUOTE_.invokeStatic (pva_test.clj:244)

nblumoe16:02:01

this happens whenever I call some function with (stest/check my-fn)` as an argument within a deftest body....

nblumoe17:02:25

had to require [clojure.test.check.clojure-test]

alexmiller18:02:21

You're running into the lein test monkey patch problem

alexmiller18:02:24

There are tickets in both lein and test.check about it, but you can work around it by turning it off in project.clj

Yehonathan Sharvit18:02:06

What is the flag that needs to be set in order to instrument all the namespaces (while in dev environment)?

alexmiller18:02:31

There is no such flag

nblumoe18:02:09

thanks a lot, good to know! 👍

alexmiller18:02:25

@viebel you can call instrument with no args though

Yehonathan Sharvit18:02:18

Where would I put this call?

Yehonathan Sharvit18:02:35

Is there a dynamic var that I could set from leiningen like *assert*?

richiardiandrea21:02:20

@viebel I do a classic when at the top of my files to instrument everything, I haven't seen anything fancier

frank22:02:58

you can set up a :once fixture that calls (s/instrument) before running tests and (s/unstrument) after running tests