mirage / alcotest

A lightweight and colourful test framework
ISC License
443 stars 81 forks source link

Support arbitrary nesting of test groups #275

Open craigfe opened 3 years ago

craigfe commented 3 years ago

The current Alcotest API exposes a rigid test structure:

type 'a test_case = string * speed_level * ('a -> return)
type 'a test      = string * 'a test_case list
type 'a suite     = 'a test list

In particular, there is one level of nesting with each leaf being assigned a speed_level.

Beyond ease of implementation, I don't see any reason why we couldn't support arbitrary nesting of test groups. For example, bechamel uses an API like the following:

module Test : sig
  type 'a t
  val v     : name:string -> ('a -> return) -> 'a t
  val group : name:string -> 'a t list -> 'a t
end

Something like this would probably support a wider range of test suite sizes. We could implement the older API in terms of the new one inside an Alcotest.V1.

Making the Test.t abstract would also allow making the [ `Quick | `Slow ] distinction optional / customizable.

emillon commented 3 years ago

:+1:, the canonical example would be ounit's (>::) (name a test) and (>:::) (name a test group).