speculative 2018-12-06

@marc-omorain has joined the channel

šŸ‘‹ Is there a way to include speculative in all namespaces, from a leiningen project.clj? I’d like to add a CI job that does a test run with it enabled in all cases.

@marc-omorain if you (require '[speculative.instrument :refer [instrument]]) and call instrument, the speculative functions will be instrumented

you could do this as a test fixture, but there is no global test fixture in clojure.test šŸ˜•

aha, we use circleci.test

the way I worked around this is by depending on the alphabetical ordering of a test runner and call it in the first namespace šŸ˜‰

ah, that’s good then

I’m still wondering if I should have made the PR with the snapshot at your rollbar library šŸ˜„

since there might be a breaking change in a snapshot

don’t worry about it - I’ll know how to fix it

also I’m still wondering if speculative.instrument is a good name for this namespace… maybe speculative.load is better. feedback welcome

providing a function that can be used as a clojure.test fixture would be neat

what it does, it loads all relevant namespaces (speculative.core, speculative.string, speculative.set)

@marc-omorain that would be a nice one for speculative.test which already has a bunch of test tooling

šŸ’Æ 1

@marc-omorain no wait, the function is already speculative.instrument/instrument, so I’m not sure what you need

(and coming to think of it, I’d like to keep speculative.test independent from loading the specs in speculative, that should be optional)

@marc-omorain what’s currently missing in rollbar is the call to the instrument function. I introduced this because @mfikes suggested that instrumenting as a side effect of loading the namespace might not be a good idea, I agreed

so, a fixture would look like:

(fn [test] (speculative.instrument/instrument) (test))

Yup, I’m thinking something like this:

(in-ns 'speculative.test)

(defn with-instrumentation [test]
  (try
    (speculative.instrument/instrument)
    (test)
    (finally
      (speculative.instrument/unstrument))))
(in-ns 'my-tests

(clojure.test/use-fixtures :once speculative.test/with-instrumentation)

I think that function should live in speculative.instrument because speculative.test should not load the speculative specs, it’s kind of an independent testing library for clojure.spec.test.

but that’s a detail

This would very much be a convenience to save me having to define the function in my code šŸ™‚

I’ll run speculative on the CircleCI monolith once I get it compiling with 1.10. it’s currently on 1.8 and I have 2 failing tests with 1.10

That’s 66,469 LOC

PR welcome as we say šŸ™‚

@borkdude doc string somewhat poor english šŸ˜‰

You might be missing ā€œusedā€

I’m considering pulling speculative.test out as a separate lib

not sure about it yet

also not sure about the name speculative.instrument, so if you have better suggestions…

so that speculative-test depends on speculative?

no, the other way around

the name should not have speculative. it’s a bunch of helpers around clojure.spec.test. nothing to do with speculative, apart from that we use it in our tests

maybe we should make a speculative organization where that lib can live?

(or some other name for the org)

could also do it under ā€œborkdudeā€, no problem

That hmm, was to myself… I might have found something…

Ha! a bug (maybe)

17:48 $ clj
Clojure 1.9.0
user=> (require '[clojure.spec.test.alpha :as st])
nil
user=> (require '[clojure.spec.alpha :as s])
nil
user=> (defmulti foo identity)
#'user/foo
user=> (s/fdef foo :args (s/cat :wat string?))
user/foo
user=> (defmethod foo :bar [lol])
#object[clojure.lang.MultiFn 0x4bff64c2 "clojure.lang.MultiFn@4bff64c2"]
user=> (st/instrument)
[user/foo]
user=> (defmethod foo :baz [lol])
ClassCastException clojure.spec.test.alpha$spec_checking_fn$fn__2943 cannot be cast to clojure.lang.MultiFn  user/eval159 (NO_SOURCE_FILE:7)
user=>

would doing it under borkdude be a problem for you? since there is a macro in that ns that you started and I finished šŸ˜‰

No, go ahead!

@alexmiller would the above be considered a bug?

I’ve never tried to spec a multimethod, but there is something around multimethods in spec.

Yeah, but I do believe that is to do checking on dispatch and such.

So you can have different specs on different dispatch values. But it might be that you have to use multi-specs on multi-methods.

Anyways, it stopped speculative cold on our project šŸ™‚

stopped speculative or your project?

stopped speculative on my project.

Alex Miller (Clojure team) 2018-12-06T17:46:59.061400Z

it’s known (to me at least) that you can’t currently spec multimethods

Alex Miller (Clojure team) 2018-12-06T17:47:06.061700Z

don’t remember if anyone actually logged it or not

Alex Miller (Clojure team) 2018-12-06T17:47:12.061900Z

if not, feel free to do so

Alex Miller (Clojure team) 2018-12-06T17:47:22.062200Z

and happy to fix as well, just haven’t looked at it

Alex Miller (Clojure team) 2018-12-06T17:48:16.062600Z

defmultis have defonce semantics so not sure if that hoses instrumentation or not