Skip to content

Latest commit

 

History

History
34 lines (26 loc) · 1019 Bytes

File metadata and controls

34 lines (26 loc) · 1019 Bytes
title OCaml recipes for Codewars
tags
authoring
recipe
ocaml

Informative assertion messages

Default assertion messages of OCaml OUnit are usually very bad. OUnit assertons accept two optional, named arguments:

  • ~printer, used to stringify values presented by assertion messages.
  • ~msg, used to provide additional information about failure, if necessary.

With both arguments used, test output becomes more explicit:

"(square 3) should return 9" >:: (fun _ ->
  let actual = square 3 in
  assert_equal 9 actual ~printer: string_of_int ~msg: "Incorrect answer for n=3"
)
Tests for square
    (square 3) should return 9
        Incorrect answer for n=3
        expected: 9 but got: 10
    Completed in 0.22ms
Completed in 0.24ms

References