Writing your cram tests in OCaml can be quite nice too

I’ve seen some discuss around cram these days, and find it generally exciting that folks are talking about this form of testing.

I wanted to make a small remark, based on a past experience. At some point I worked on a system that grew quite a large amount of cli tests in cram files and syntax. There quickly came a scale where we started factorizing code and utility abstractions, like you would with any normal non-testing code, and effectively ended up with bash as our programming language.

It’s possible some of the frustration felt by the devs around that time contributed to inspire expect-test (I don’t remember the exact timeline).

At any rate, I’ve seen developed alternate designs where cram cli tests are written with the use of OCaml helpers, using the ppx_expect library + some lib to deal with processes, wrapped as dedicated helpers for doing this.

You can see an example of this sort of things here. I’m sure there are many others out there.

Among the things I like about that example, is that in the same test you end up with the possibly of exercising side by side the cli endpoint along with connectivity via an OCaml client library. See this example.

I’m mentioning this because in my experience, using OCaml to test commands is not a pattern that one would immediately think of, when starting to grow a cram code base. But this is an interesting one to consider in some situation. The editor UX is quite nice!

Please let me know what you think, and happy OCaml craming!

4 Likes