Something went wrong. Try again.
Dockerfile eDSL, combinators, printer and parser forked from gazagnaire.org/ocaml-dockerfile
Something went wrong. Try again.
1.6 kB · 47 lines
OCaml
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748(* Tests for the Dockerfile error facade over Loc.Error: typed kinds carry their payload into the rendered message, raisers raise the shared exception, and [relocate] stamps a source location onto a location-less error. *)
open Dockerfile.Error
let contains s sub = Re.execp Re.(compile (str sub)) s
let test_unsupported_instruction () = let s = to_string (unsupported_instruction Loc.Meta.none "FROOBLE") in Alcotest.(check bool) "names the keyword" true (contains s "FROOBLE"); Alcotest.(check bool) "says unsupported" true (contains s "unsupported")
let test_fail_raises () = let raised = try ignore (fail_unsupported_instruction Loc.Meta.none "FROOBLE"); false with Loc.Error _ -> true in Alcotest.(check bool) "fail_unsupported_instruction raises Loc.Error" true raised
let test_msg () = Alcotest.(check bool) "carries the message" true (contains (to_string (msg Loc.Meta.none "boom")) "boom")
let test_relocate () = let loc = Loc.v ~file:"d" ~first_byte:0 ~last_byte:0 ~first_line_num:7 ~first_line_byte:0 ~last_line_num:7 ~last_line_byte:0 in let e = relocate (Loc.Meta.v loc) (msg Loc.Meta.none "x") in Alcotest.(check int) "stamps the source line" 7 (Loc.first_line_num (Loc.Meta.loc e.Loc.Error.meta))
let suite = ( "error", [ Alcotest.test_case "unsupported_instruction" `Quick test_unsupported_instruction; Alcotest.test_case "fail_ raises" `Quick test_fail_raises; Alcotest.test_case "msg" `Quick test_msg; Alcotest.test_case "relocate" `Quick test_relocate; ] )