[mercury-users] Compiler test-case generation, Re: Meta programming
Ian MacLarty
maclarty at cs.mu.OZ.AU
Thu Feb 2 10:23:24 AEDT 2006
On 1 Feb 2006, at 21:43, doug.auclair at logicaltypes.com wrote:
> Dear Ian, you wrote:
>
>> Another option is to add a compiler option that causes the compiler
>> to produce random test cases for the code it compiles (since the
>> compiler has access to all the necessary info).
>
> Brilliant! I could then add a '--quickcheck-exported-predicates' flag
> that would then generate the test cases as a new module and then
> execute that module's main/2 when the system compiles successfully.
> There are a couple of consequences that I need to work through,
> however:
>
> 1. a new version release will destroy the changes I've made to the
> compiler (as I have discover on the rapid turnaround of releases
> 0.12.1 to 0.12.2 for my op/3 addition);
If you made such a change I don't see why it can't be applied to the
main branch (after review). Then it would be in the compiler forever.
> 2. automatic test case generation is more of an assistant to the test
> writer: writing a comprehesive test case generation tool costs too
> much verses the payoff of providing base cases to assist the test
> writer complete the system. So, the compile cycle needs to include a
> phase for user intervention to guide the compiler to writing
> appropriate test cases (quickcheck requires this). This devolves into
> a chicken-or-egg problem, as either a domain specific language must be
> provided (yuck!) to associate specific tests to specific clauses a
> priori or an interactive (yuck!) environment (like the very nice
> declarative debugger) must be set up to allow the user to shepherd the
> compilation/testing process.
>
Perhaps the compiler could generate a set of predicates like the
following:
:- pred call_exported_pred(module::in, name::in, arity::in,
list(univ)::in, result(list(univ))::out) is det.
:- pred exported_pred(module::out, name::out, arity::out) is multi.
:- pred pred_arg_types(module::in, name::in, arity::in,
list(type_desc)::out) is semidet.
(An I/O version of call_exported_pred might also be useful).
call_exported_pred/5 would call the named predicate, passing the the
list of arguments. It would then return the result in the last
argument.
exported_pred/3 would give you all the exported preds in a module (the
first argument is probably unnecessary).
pred_arg_types/4 would give you the argument types for the named
predicate.
I think given these three predicates you could write any kind of
automatic test case generator you wanted - interactive or not.
There would, however, be a problem with predicates that used modes
besides in and out (and possible di and uo for I/O).
Ian.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list