Fork me on GitHub
#clojure-spec
<
2018-07-30
>
djtango17:07:03

So I am pretty sure this is absolutely not how spec was intended to be used, but has anyone gotten mileage from leaving stest/instrument turned on in production to use spec for runtime contract assertion? Even more so with jeaye/orchestra

djtango17:07:59

One reason I can think of why this may not be such a great idea is that stest/instrument validates fspec using generated inputs

djtango17:07:38

are there any other reasons not to leave stest/instrument turned on?

seancorfield17:07:45

@djtango The generative validation of fspec is one reason. Performance is another. You'll also get bare AssertionError exceptions instead of anything meaningful you might normally catch and handle (assuming you try to (catch Exception e ...))

noisesmith17:07:02

yeah, my understanding is that AssertionError is for things you expect to throw during development - the vm even has a flag to ignore them

djtango18:07:47

I suppose, to give more context on my usecase, it is useful (for me) to declare some invariants about a function (e.g. a relationship between it's args and return value) but in a sufficiently large project, it's possible for inputs in runtime to fail that invariant and it's nicer when that failure comes at the point of the invariant failing rather than some arbitrary of steps later like a null pointer error

djtango18:07:22

spec happens to be a great way for declaring properties about lots of things, and while generative testing is meant to give better guarantees about over your testing space, the associated complexity with them is a harder sell for the team

djtango18:07:41

If that makes sense?

djtango18:07:10

Coming from Racket, I'm kind of used to contracts always being on

noisesmith18:07:58

the pragmatic thing might just be overriding fspecs for the instrumenting

noprompt21:07:19

it’d be great if there were a spec-impl that “merged” two s/ors or s/alts without having to reify the protocols (which is a dangerous game as i understand it).

noprompt22:07:41

for example, if you want to express that clojure.core/unquote-splicing forms are not permitted at the top level you’d have a union for your legal top level forms and then another union for your subforms in, say, a list that includes unquote-splicing forms in addition to what is legal at the top level.

noprompt22:07:35

to fully leverage all of spec, including explanations, it seems like i have to spell this out entirely in both cases if i want to avoid an additional layer of rettags.

seancorfield22:07:04

@noprompt Or wrap s/or in s/nonconforming I guess...?

noprompt22:07:20

@seancorfield that’s not quite the ticket. lemme demonstrate.

noprompt22:07:49

(s/def :clj.form/top-level
  (s/or :list :clj.form/list
        :number number?))

(s/def :clj.form/list
  (s/coll-of
   (s/or :a :clj.form/top-level
         :b (s/or :unquote-splicing unquote-splicing-form?))
   :kind list?))

(s/conform :clj.form/top-level '(1 ~@[1]))
;; =>
[:list
 ([:a [:number 1]]
  [:a [:number 2]]
  [:b [:unquote-splicing (clojure.core/unquote-splicing [1])]])]

noprompt22:07:08

what i do not want is the :a and :b tags. i still want to retain the :number and :unquote-splicing tags.

noprompt22:07:22

by using s/nonconforming i lose the tags. 😕

noprompt22:07:08

essentially, i want to extend the :clj.form/top-level union without adding an additional layer of rettags.

noprompt22:07:59

of course, i can do this by using s/with-gen, s/conformer, etc. but i lose out on s/explain-data.

noprompt22:07:56

if there was an s/explainer this’d be a done deal. 🙂

noprompt22:07:48

in short, i think what i want is an or-spec-impl or an alt-spec-impl that does not require tagging the options.

noprompt22:07:35

when it conforms returns whatever the conformers it’s compose of returns.

noprompt22:07:27

i think there was previous discussion along same lines but for s/cat with an s/concat conformer..

seancorfield22:07:44

Alex has talked several times about the possibility of adding a specific non-conforming or variant so you'd have that sort of level of control...

arohner22:07:42

I have a big complicated s/keys, and I’m getting "Couldn't satisfy such-that predicate after 100 tries.". How do I discover which predicate is failing?

gfredericks22:07:25

if you're using a new enough test.check, the ex-data should have the generator and predicate attached, at least