clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
johanatan 2020-08-09T22:19:18.077200Z

hi, i have a spec'd function that is taking as input a collection of data where the individual elements have attached metadata via a with-gen for their spec. however, because stest/check conforms these inputs to their constituent components (specified via s/cat) the metadata which was attached to the outer element is lost. what is the recommended way around this? perhaps a way to override "conform" or otherwise propagate the metadata? something else?

johanatan 2020-08-09T22:21:05.078800Z

i could manually attach the metadata rather than to the outer value to one of its constituents but this doesn't feel like the proper data modeling for the actual situation. i could also add an extra component to the s/alt but that isn't desirable as it would expose "test-only" data to the code under test (and also generally violate one's tastes with respect to the actual modeling).

seancorfield 2020-08-09T22:25:09.080300Z

@johanatan Are you saying that stest/check is passing conformed data into the function under test? That doesn't seem right since the conformed shape won't necessarily match the input shape...

johanatan 2020-08-09T22:25:47.080700Z

no, it's passing it into the :fn verifier

johanatan 2020-08-09T22:26:06.081300Z

sorry wasn't clear. stest/check is passing the generated data to the actual function

johanatan 2020-08-09T22:26:22.081900Z

but that data is slightly deformed via conform to the actual :fn checker

seancorfield 2020-08-09T22:26:29.082200Z

Oh, right. So you're trying to rely on input metadata in the :fn verifier?

johanatan 2020-08-09T22:26:30.082300Z

(per the labeling)

johanatan 2020-08-09T22:26:33.082500Z

yea

seancorfield 2020-08-09T22:27:13.083200Z

I wouldn't expect metadata to be preserved through that. It doesn't seem like something you should be relying on in :fn.

johanatan 2020-08-09T22:27:27.083500Z

it would be very useful for testing purposes

johanatan 2020-08-09T22:27:44.084Z

the generators can then inform the tests what the expected behavior should be

johanatan 2020-08-09T22:27:51.084300Z

I can't imagine any better way to accomplish that in fact

johanatan 2020-08-09T22:28:20.084800Z

and as long as the generators don't use s/alt s/cat and the like, this is entirely possible

johanatan 2020-08-09T22:28:28.085Z

(i've done it previously)

johanatan 2020-08-09T22:29:01.085400Z

i have to step out now so will respond back later this evening. thx

seancorfield 2020-08-09T22:31:59.086Z

Could you use s/conformer in the spec to thread the metadata into the conformed result I wonder?