package octez-alcotezt

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Wrapper to run Alcotest tests with Tezt as a backend.

This module provides a subset of the interface of the Alcotest module of the real Alcotest library. But instead of using Alcotest to run the tests, it uses Tezt. This allows to transition from Alcotest to Tezt without having to actually change the code. In turn, this allows to benefit from Tezt features such as auto-balancing in the CI. One can then use Tezt's modules in the test, to gradually migrate the test to Tezt and stop using this wrapper.

This module is intended as a way to help transition from Alcotest to Tezt, not to use both at the same time forever. First use Alcotezt to have the test runnable using Tezt, as a quick win to get auto-balancing etc. Then stop using Alcotest functions and migrate existing calls at the pace that is convenient for you.

type return = unit

Return type for tests.

type speed_level = [
  1. | `Quick
  2. | `Slow
]

Speed levels.

In Alcotest, one can ask not to run slow tests with -q from the command-line. In Tezt, the equivalent is quick.

Tests registered with `Slow or `Quick will have respectively the tag "slow" or "quick". "slow" tag may have consequences on how the test will be handled by the CI. More information is given in src/lib_test/tag.mli.

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

Test cases.

The name of the Alcotest test case appears in Tezt's logs, but it is not used in the Tezt test title, nor as a tag.

val test_case : string -> speed_level -> ('a -> return) -> 'a test_case

Make a test case.

exception Test_error

Can be raised to fail a test.

type 'a test = string * 'a test_case list

Tests.

In Tezt, the name of the test is used as the title of the test.

val run : __FILE__:string -> string -> unit test list -> return

Run a test suite.

In Tezt, this calls Test.register but does not actually run the test suite. The name of the test suite is used as the filename for the Tezt test.

module type TESTABLE = sig ... end
type 'a testable = (module TESTABLE with type t = 'a)

Values that can be tested with check.

val testable : (Stdlib.Format.formatter -> 'a -> unit) -> ('a -> 'a -> bool) -> 'a testable

testable pp eq is a new testable with the pretty-printer pp and equality eq.

val pp : 'a testable -> Stdlib.Format.formatter -> 'a -> return

pp t is t's pretty-printer.

val of_pp : (Stdlib.Format.formatter -> 'a -> return) -> 'a testable

of_pp pp tests values which can be printed using pp and compared using Stdlib.compare

val equal : 'a testable -> 'a -> 'a -> bool

equal t is t's equality.

val unit : unit testable

The unit testable type.

val string : string testable

The string testable type.

val bool : bool testable

The boolean testable type.

val bytes : bytes testable

The bytes testable type.

val int64 : int64 testable

The int64 testable type.

val int32 : int32 testable

The int32 testable type.

val int : int testable

The int testable type.

val float : float -> float testable

The float testable type.

val list : 'a testable -> 'a list testable

The list testable type.

val array : 'a testable -> 'a array testable

The array testable type.

val pair : 'a testable -> 'b testable -> ('a * 'b) testable

The pair testable type.

val triple : 'a testable -> 'b testable -> 'c testable -> ('a * 'b * 'c) testable

The triple testable type.

val result : 'a testable -> 'e testable -> ('a, 'e) Stdlib.result testable

The result testable type.

val option : 'a testable -> 'a option testable

The option testable type.

val check : 'a testable -> string -> 'a -> 'a -> return

Check that two values are equal.

In Tezt, this becomes Check.(=) where ~error_msg is msg ^ ": expected %L, got %R" where msg is the string given to check.

val check' : 'a testable -> msg:string -> expected:'a -> actual:'a -> return

Check that two values are equal (labeled variant of check).

val check_raises : string -> exn -> (unit -> unit) -> return

Check that an exception is raised.

val fail : string -> 'a

Fail the current test (string version).

val failf : ('a, Stdlib.Format.formatter, return, 'b) Stdlib.format4 -> 'a

Fail the current test (format version).

OCaml

Innovation. Community. Security.