Skip to content

Instantly share code, notes, and snippets.

@erhangundogan
Last active July 1, 2021 12:53
Show Gist options
  • Save erhangundogan/5d11eb7896987388f5681dbcf3c89225 to your computer and use it in GitHub Desktop.
Save erhangundogan/5d11eb7896987388f5681dbcf3c89225 to your computer and use it in GitHub Desktop.
ocaml alcotest example
(*
utop # Alcotest.check Alcotest.string "foo" "abc" "abc";;
ASSERT foo
- : unit = ()
*)
(* A module with functions to test *)
module To_test = struct
let lowercase = String.lowercase_ascii
let list_concat = List.append
end
(* The tests *)
let test_lowercase () =
Alcotest.(check string) "same string" "hello!" (To_test.lowercase "hElLO!")
let test_list_concat () =
Alcotest.(check (list int)) "same lists" [1; 2; 3] (To_test.list_concat [1] [2; 3])
(* Run it *)
let () =
let open Alcotest in
run "test module" [
"string-case", [
test_case "Lower case" `Quick test_lowercase
];
"list-concat", [
test_case "List mashing" `Slow test_list_concat
]
]
;;
(*
Testing `test module'.
This run has ID `22D39A4E-CE5C-4FE4-BA92-A2B0F6CA5CCD'.
[OK] string-case 0 Lower case.
[OK] list-concat 0 List mashing.
Full test results in `~/_build/_tests/test module'.
Test Successful in 0.000s. 2 tests run.
*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment