speculative

https://github.com/borkdude/speculative
Marc O'Morain 2018-12-06T16:08:15.033800Z

šŸ‘‹ 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.

borkdude 2018-12-06T16:09:30.034900Z

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

borkdude 2018-12-06T16:09:48.035400Z

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

Marc O'Morain 2018-12-06T16:10:02.035900Z

aha, we use circleci.test

Marc O'Morain 2018-12-06T16:10:16.036300Z

https://github.com/circleci/circleci.test#global-fixtures

borkdude 2018-12-06T16:10:21.036600Z

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

borkdude 2018-12-06T16:10:32.037Z

ah, thatā€™s good then

borkdude 2018-12-06T16:10:57.037500Z

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

borkdude 2018-12-06T16:11:35.038100Z

since there might be a breaking change in a snapshot

Marc O'Morain 2018-12-06T16:12:11.039Z

donā€™t worry about it - Iā€™ll know how to fix it

borkdude 2018-12-06T16:12:13.039100Z

also Iā€™m still wondering if speculative.instrument is a good name for this namespaceā€¦ maybe speculative.load is better. feedback welcome

Marc O'Morain 2018-12-06T16:12:42.040Z

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

borkdude 2018-12-06T16:12:43.040100Z

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

borkdude 2018-12-06T16:13:09.040800Z

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

šŸ’Æ 1
borkdude 2018-12-06T16:13:49.041600Z

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

borkdude 2018-12-06T16:14:28.042100Z

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

borkdude 2018-12-06T16:16:44.043200Z

@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

borkdude 2018-12-06T16:19:57.044600Z

so, a fixture would look like:

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

Marc O'Morain 2018-12-06T16:24:09.047200Z

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)

borkdude 2018-12-06T16:25:05.048200Z

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.

borkdude 2018-12-06T16:25:08.048500Z

but thatā€™s a detail

Marc O'Morain 2018-12-06T16:25:10.048600Z

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

Marc O'Morain 2018-12-06T16:25:54.049400Z

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

Marc O'Morain 2018-12-06T16:26:59.049600Z

Thatā€™s 66,469 LOC

borkdude 2018-12-06T16:29:21.049900Z

@marc-omorain how about this? https://github.com/slipset/speculative/pull/162/files

slipset 2018-12-06T16:29:22.050Z

PR welcome as we say šŸ™‚

slipset 2018-12-06T16:29:54.050500Z

@borkdude doc string somewhat poor english šŸ˜‰

slipset 2018-12-06T16:30:11.051Z

You might be missing ā€œusedā€

borkdude 2018-12-06T16:30:16.051200Z

yes

borkdude 2018-12-06T16:30:32.051400Z

updated

borkdude 2018-12-06T16:31:13.051800Z

Iā€™m considering pulling speculative.test out as a separate lib

borkdude 2018-12-06T16:31:38.052200Z

not sure about it yet

borkdude 2018-12-06T16:32:15.052900Z

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

slipset 2018-12-06T16:32:40.053300Z

so that speculative-test depends on speculative?

borkdude 2018-12-06T16:32:47.053600Z

no, the other way around

borkdude 2018-12-06T16:33:22.054200Z

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

slipset 2018-12-06T16:33:28.054400Z

cool

slipset 2018-12-06T16:33:37.054600Z

go for it!

borkdude 2018-12-06T16:34:54.054900Z

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

borkdude 2018-12-06T16:35:03.055100Z

(or some other name for the org)

borkdude 2018-12-06T16:36:17.055500Z

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

slipset 2018-12-06T16:43:33.055700Z

Hmm.

slipset 2018-12-06T16:44:29.056300Z

That hmm, was to myselfā€¦ I might have found somethingā€¦

slipset 2018-12-06T16:48:27.056500Z

Ha! a bug (maybe)

slipset 2018-12-06T16:49:49.057Z

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=>

borkdude 2018-12-06T16:49:55.057200Z

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

slipset 2018-12-06T16:50:06.057400Z

No, go ahead!

slipset 2018-12-06T16:50:37.058300Z

@alexmiller would the above be considered a bug?

borkdude 2018-12-06T16:50:47.058600Z

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

slipset 2018-12-06T16:51:08.059Z

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

slipset 2018-12-06T16:51:37.059600Z

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

slipset 2018-12-06T16:54:00.060Z

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

borkdude 2018-12-06T16:54:15.060200Z

stopped speculative or your project?

slipset 2018-12-06T16:54:29.060500Z

stopped speculative on my project.

borkdude 2018-12-06T16:55:42.060700Z

interesting. https://groups.google.com/forum/#!topic/clojure/BBWc3c40RDI

slipset 2018-12-06T16:56:44.061Z

Hmmm.

alexmiller 2018-12-06T17:46:59.061400Z

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

alexmiller 2018-12-06T17:47:06.061700Z

donā€™t remember if anyone actually logged it or not

alexmiller 2018-12-06T17:47:12.061900Z

if not, feel free to do so

alexmiller 2018-12-06T17:47:22.062200Z

and happy to fix as well, just havenā€™t looked at it

alexmiller 2018-12-06T17:48:16.062600Z

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