vincent-hugot / qtest

Inline (Unit) Tests for OCaml
GNU General Public License v3.0
67 stars 8 forks source link

A test-only code injector #25

Closed gasche closed 8 years ago

gasche commented 8 years ago

I would have had a use recently for a feature allowing me to define a small auxiliary function to be used in tests, but not be part of the code of the main module. The offending tests are there, basically I am doing a sequence of tests of the form

    nsplit (of_string bar) (of_string foo) |> List.map to_string = [...]

It would be convenient to be able to write something like

(*${ let nsplit_string bar foo = nsplit (of_string bar) (of_string foo) |> List.map to_string }*)

and be able to use nsplit_string in tests. I do not wish to include this code in the module itself, so it is not equivalent to (*${ *) let nsplit_string ... (*$}*).

gasche commented 8 years ago

Also, (*${ is currently undocumented; this PR might be an occasion to motivate someone to do so (I would normally send a PR myself, but I don't have any time for now).

vincent-hugot commented 8 years ago

I think this should already be possible -- no time right now, I'll look at it this WE.

gasche commented 8 years ago

Indeed, there is no hurry. Thanks!

vincent-hugot commented 8 years ago

Ok, there is indeed already a way to do what you want:

(*$inject 
let nsplit_string ... 
*)

Injections in general are very badly documented, I know... (though the devil's advocate on my shoulder compels me to argue that they are not completely _un_documented, as both forms appear in the doc. Once. If you know where to look).

Since, sadly, I don't program at all these days, and am otherwise rather busy, I never really have a good opportunity or motivation to get back on qtest, and I somewhat lost touch with the proverbial itch it scratches.

That may change in a year or two, as I may have some prototyping to do. Meanwhile, I would be very grateful for and absolutely delighted to merge documentation PRs.

c-cube commented 8 years ago

Should be fixed by 86ff409. Please re-open if you're not satisfying :-)