On 01/08/2014 11:11 AM, Anton Lavrik wrote:
> Agree -- that would be really cool! There could also be a mixed mode,
> when some values are set to known defaults and others are assigned
> randomly.
I realised while discussing with Motiejus that what is needed is more
like a "canonical example" flag `--canonical` which would pick either
defaults or explicitly provided values (via some extension like
`.example`). Otherwise this mashes up the meanings of "standard example
of a type" and "default value of a field".
> In fact, if I wanted something quick and practical, I'd look at
> generating it in Erlang. There's code in piqic-erlang that can
> generate real defaults in Erlang syntax. In fact, it is used for
> generating field defaults for Erlang records. I would also look at
> Proper -- it has a randomized generation mode that works based on
> Erlang types. This way it should be possible to use it for
> generating randomized values based on _piqi.hrl types. If you need
> JSON output, converting generated Erlang values to JSON is trivial.
Indeed if the intention would only be internal testing of Erlang code,
then piqic_erlang and PropEr would already do most of the work.
However, my goal is mocking, testing and benchmarking abstract
interfaces, so this will possibly be done using other languages /
tools, not only Erlang. Moreover, it would definitely be way hackier to
implement it in Erlang. I also want to take advantage of this when
generating documentation, so Erlang makes little sense again.
> On the other hand, if you are up to some OCaml hacking, this would
> be a really cool piqi feature. There are a couple of QuickCheck
> implementations for OCaml to use as inspiration. Also, hacking on
> Piqi has never been easier. I've recently made some changes in
> master that greatly simplified the code layout and the build process.
> I'll be happy to help if you have questions about Piqi internals.
QuickCheck is way too much for this! Though it could be re-used for the
primitive type generation.
I won't try to hack this into Erlang and have a go at OCaml... at
some point when my backlog is smaller. I'll let you know whether/when I
get anything done :-)
Thanks again,
Ignas