alcotest icon indicating copy to clipboard operation
alcotest copied to clipboard

document testable

Open martindemello opened this issue 3 years ago • 5 comments

I found out about adding new testable types from this blogpost; there is nothing in the project docs about it.

martindemello avatar Aug 21 '21 03:08 martindemello

Hi @martindemello,

By "the project docs", do you mean the README in this repository? The generated docs at http://mirage.github.io/alcotest/alcotest/Alcotest/ do reference the Alcotest.testable helper function for building testable values, as well as the implementation of the Alcotest.testable type (which is concrete, so can be constructed directly).

craigfe avatar Aug 22 '21 11:08 craigfe

yeah, i meant the README and the examples. i didn't see the generated docs because they are also not linked to from the README :) but the package was easy enough to get up to speed with once i got the basic idea; i'll try to contribute some more docs once i've used it for a bit.

martindemello avatar Aug 22 '21 11:08 martindemello

yeah, i meant the README and the examples. i didn't see the generated docs because they are also not linked to from the README :)

Good point! They are linked from a little docs badge, but it's not very visible – hopefully #320 will improve that.

i'll try to contribute some more docs once i've used it for a bit.

Thanks!

craigfe avatar Aug 22 '21 15:08 craigfe

The approach using a first-class module of type TESTABLE requires a lot of mental gymnastics to simply provide a pair ~~to_string/of_string~~ to_string/equal. Please include an example in the API docs.

mjambon avatar Sep 07 '23 00:09 mjambon

Here's an example for a fictitious module Fizz providing a to_string function and an equal function with the obvious types:

let fizz = Alcotest.testable (Fmt.of_to_string Fizz.to_string) Fizz.equal
...
let test_something () =
  Alcotest.check fizz "equal" Fizz.zero (Fizz.of_string "0")

mjambon avatar Sep 07 '23 01:09 mjambon