Something went wrong. Try again.
My own corner of monopam
Something went wrong. Try again.
1.6 kB · 45 lines
OCaml
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546let check_kind name e pred = if not (pred (Loc.Error.kind e)) then Alcotest.failf "%s: unexpected error: %s" name (Bsdiff.Error.to_string e)
let check_raises name f pred = match f () with | _ -> Alcotest.failf "%s: expected Loc.Error" name | exception Loc.Error e -> check_kind name e pred
let test_builders () = let open Bsdiff.Error in check_kind "magic_mismatch" (magic_mismatch "BADMAGIC") (function | Magic_mismatch "BADMAGIC" -> true | _ -> false); check_kind "truncated" (truncated "header") (function | Truncated "header" -> true | _ -> false); check_kind "corrupt" (corrupt "bad stream") (function | Corrupt "bad stream" -> true | _ -> false); check_kind "invalid" (invalid "overrun") (function | Invalid "overrun" -> true | _ -> false)
let test_raisers () = let open Bsdiff.Error in check_raises "fail_magic_mismatch" (fun () -> fail_magic_mismatch "BADMAGIC") (function Magic_mismatch "BADMAGIC" -> true | _ -> false); check_raises "fail_invalid" (fun () -> fail_invalid ~ctx:(ctx_with_triple 7) "target overrun") (function Invalid "target overrun" -> true | _ -> false)
let test_to_string () = let msg = Bsdiff.Error.(to_string (magic_mismatch "NO")) in if not (String.contains msg '4') then Alcotest.failf "formatted error does not mention BSDIFF40: %s" msg
let suite = ( "error", [ Alcotest.test_case "builders" `Quick test_builders; Alcotest.test_case "raisers" `Quick test_raisers; Alcotest.test_case "format" `Quick test_to_string; ] )