X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_test.ml;h=4d3287d88680a33223fb718ebf052e61ff92c117;hb=35dccbd3999a8c3bb1dc9e96e21b69a39f44fc6f;hp=0eafeca789295733bdd3c883d6c00bbb662611ea;hpb=1cf4e513b6ce826070535d29f58e8b708279f0f5;p=tiger.ml.git diff --git a/compiler/src/lib/tiger/tiger_test.ml b/compiler/src/lib/tiger/tiger_test.ml index 0eafeca..4d3287d 100644 --- a/compiler/src/lib/tiger/tiger_test.ml +++ b/compiler/src/lib/tiger/tiger_test.ml @@ -28,18 +28,7 @@ open Printf module List = ListLabels module String = StringLabels -module Option : sig - type 'a t = 'a option - - val map : 'a t -> ('a -> 'b) -> 'b t -end = struct - type 'a t = 'a option - - let map t f = - match t with - | None -> None - | Some x -> Some (f x) -end +module Opt = Tiger_opt (* TODO: ~expect:Output of 'a | Exception of (exn -> bool) *) type t = @@ -67,8 +56,6 @@ type 'a t_result = type color = | Red | Red_bold - | Yellow - | Green | Green_bold | Grey_bold @@ -77,8 +64,6 @@ let color_to_ansi_code = function | Grey_bold -> "\027[1;30m" | Red -> "\027[0;31m" | Red_bold -> "\027[1;31m" - | Yellow -> "\027[0;33m" - | Green -> "\027[0;32m" | Green_bold -> "\027[1;32m" let color_off = "\027[0m" @@ -102,11 +87,6 @@ let status_to_str = function | Fail -> "X" | Skip -> "-" -let status indicator info = - match info with - | "" -> indicator - | _ -> sprintf "%s: %s" indicator info - let case ?(out_lexing=None) ?(out_parsing=None) @@ -127,11 +107,6 @@ let bar_horiz_minor = color Grey_bold (String.make 80 '-') let bar_horiz_major = color Grey_bold (String.make 80 '=') let bar_vert = color Grey_bold "|" -let indent = - let unit_spaces = 2 in - fun n -> - String.make (n * unit_spaces) ' ' - let lexbuf_set_filename lb filename : unit = @@ -178,7 +153,7 @@ let pass_semant (absyn : Tiger_absyn.t) let str_exact str exact = let len = String.length str in let take = if len > exact then exact else len in - let str = String.sub str 0 take in + let str = String.sub str ~pos:0 ~len:take in let pad = exact - take in let pad = String.make pad ' ' in str ^ pad @@ -186,7 +161,6 @@ let str_exact str exact = let s = sprintf let p = printf let p_ln = print_newline -let p_indent n = p "%s" (indent n) let run tests = Printexc.record_backtrace true; @@ -229,7 +203,7 @@ let run tests = | Ok produced -> let (out_stat, out_msg) = match - Option.map expect_output (fun expected -> expected = produced) + Opt.map expect_output (fun expected -> expected = produced) with | None -> (Skip, "expected output not provided") @@ -248,13 +222,12 @@ let run tests = } in let test_case_count = ref 0 in - let col_1_width = 25 in - let col_i_width = 10 in + let col_1_width = 30 in let p_stat width (exe, out) = (* All this gymnastics to ignore color codes in cell width *) let min = 5 in let width = if width > min then width else min in - p "%s" (String.concat "" (List.init ~len:width ~f:(function + p "%s" (String.concat ~sep:"" (List.init ~len:width ~f:(function | 0 -> " " | 1 -> bar_vert | 2 -> " "