@@ -18,6 +18,7 @@ open Mdx
1818open Compat
1919open Result
2020open Astring
21+ open Migrate_ast
2122open Mdx.Util.Result.Infix
2223
2324let src = Logs.Src. create " cram.test"
@@ -84,14 +85,12 @@ let run_test ?root blacklist temp_file t =
8485 match snd (Unix. waitpid [] pid) with WEXITED n -> n | _ -> 255
8586
8687let root_dir ?root ?block () =
87- match block with
88- | Some t -> (
89- match Mdx.Block. directory t with
90- | Some d -> (
91- match root with
92- | Some r -> Some (r / d)
93- | None -> Some (Filename. dirname t.file / d) )
94- | None -> root )
88+ match (block : Block.t option ) with
89+ | Some { dir = None ; _ } -> root
90+ | Some { dir = Some d ; loc = { loc_start = { pos_fname; _ } ; _ } ; _ } -> (
91+ match root with
92+ | Some r -> Some (r / d)
93+ | None -> Some (Filename. dirname pos_fname / d) )
9594 | None -> root
9695
9796let resolve_root file dir root =
@@ -123,11 +122,10 @@ let run_cram_tests ?syntax t ?root ppf temp_file pad tests =
123122 tests;
124123 Block. pp_footer ?syntax ppf t
125124
126- let eval_test ?block ?root c test =
127- Log. debug (fun l ->
128- l " eval_test %a" Fmt. (Dump. list (Fmt. fmt " %S" )) (Toplevel. command test));
125+ let eval_test ?block ?root c cmd =
126+ Log. debug (fun l -> l " eval_test %a" Fmt. (Dump. list (Fmt. fmt " %S" )) cmd);
129127 let root = root_dir ?root ?block () in
130- with_dir root (fun () -> Mdx_top. eval c ( Toplevel. command test) )
128+ with_dir root (fun () -> Mdx_top. eval c cmd )
131129
132130let err_eval ~cmd lines =
133131 Fmt. epr " Got an error while evaluating:\n ---\n %a\n ---\n %a\n %!"
@@ -137,13 +135,10 @@ let err_eval ~cmd lines =
137135 lines;
138136 exit 1
139137
140- let eval_raw ?block ?root c ~line lines =
141- let test =
142- Toplevel. { vpad = 0 ; hpad = 0 ; line; command = lines; output = [] }
143- in
144- match eval_test ?block ?root c test with
138+ let eval_raw ?block ?root c cmd =
139+ match eval_test ?block ?root c cmd with
145140 | Ok _ -> ()
146- | Error e -> err_eval ~cmd: lines e
141+ | Error e -> err_eval ~cmd e
147142
148143let split_lines lines =
149144 let aux acc s =
@@ -153,17 +148,14 @@ let split_lines lines =
153148 in
154149 List. fold_left aux [] (List. rev lines)
155150
156- let eval_ocaml ~block ?syntax ?root c ppf ~line lines errors =
157- let test =
158- Toplevel. { vpad = 0 ; hpad = 0 ; line; command = lines; output = [] }
159- in
151+ let eval_ocaml ~block ?syntax ?root c ppf cmd errors =
160152 let update ~errors = function
161153 | { Block. value = OCaml v ; _ } as b ->
162154 { b with value = OCaml { v with errors } }
163155 (* [eval_ocaml] only called on OCaml blocks *)
164156 | _ -> assert false
165157 in
166- match eval_test ?root ~block c test with
158+ match eval_test ?root ~block c cmd with
167159 | Ok _ -> Block. pp ?syntax ppf (update ~errors: [] block)
168160 | Error lines ->
169161 let errors =
@@ -184,8 +176,8 @@ let lines = function Ok x | Error x -> x
184176let run_toplevel_tests ?syntax ?root c ppf tests t =
185177 Block. pp_header ?syntax ppf t;
186178 List. iter
187- (fun test ->
188- let lines = lines (eval_test ?root ~block: t c test) in
179+ (fun ( test : Toplevel.t ) ->
180+ let lines = lines (eval_test ?root ~block: t c test.command ) in
189181 let lines = split_lines lines in
190182 let output =
191183 let output = List. map output_from_line lines in
@@ -304,8 +296,7 @@ let run_exn (`Setup ()) (`Non_deterministic non_deterministic)
304296 let det () =
305297 assert (syntax <> Some Cram );
306298 Mdx_top. in_env env (fun () ->
307- eval_ocaml ~block: t ?syntax ?root c ppf ~line: t.line t.contents
308- errors)
299+ eval_ocaml ~block: t ?syntax ?root c ppf t.contents errors)
309300 in
310301 with_non_det non_deterministic non_det ~command: print_block
311302 ~output: det ~det
@@ -323,18 +314,17 @@ let run_exn (`Setup ()) (`Non_deterministic non_deterministic)
323314 | Toplevel { non_det; env } ->
324315 let tests =
325316 let syntax = Util.Option. value syntax ~default: Normal in
326- Toplevel. of_lines ~syntax ~file: t.file ~line: t.line ~column: t.column
327- t.contents
317+ Toplevel. of_lines ~syntax ~loc: t.loc t.contents
328318 in
329319 with_non_det non_deterministic non_det ~command: print_block
330320 ~output: (fun () ->
331321 assert (syntax <> Some Cram );
332322 print_block () ;
333323 List. iter
334- (fun test ->
324+ (fun ( test : Toplevel.t ) ->
335325 match
336326 Mdx_top. in_env env (fun () ->
337- eval_test ~block: t ?root c test)
327+ eval_test ~block: t ?root c test.command )
338328 with
339329 | Ok _ -> ()
340330 | Error e ->
@@ -354,7 +344,7 @@ let run_exn (`Setup ()) (`Non_deterministic non_deterministic)
354344 let buf = Buffer. create (String. length file_contents + 1024 ) in
355345 let ppf = Format. formatter_of_buffer buf in
356346 let envs = Document. envs items in
357- let eval lines () = eval_raw ?root c ~line: 0 lines in
347+ let eval lines () = eval_raw ?root c lines in
358348 let eval_in_env lines env = Mdx_top. in_env env (eval lines) in
359349 List. iter
360350 (function
@@ -391,8 +381,8 @@ let report_error_in_block block msg =
391381 | Cram _ -> " cram "
392382 | Toplevel _ -> " toplevel "
393383 in
394- Fmt. epr " Error in the %scode block in %s at line %d: @]\n %s\n " kind block.file
395- block.line msg
384+ Fmt. epr " %a: Error in the %scode block@]\n %s\n " Location. print_loc block.loc
385+ kind msg
396386
397387let run setup non_deterministic silent_eval record_backtrace syntax silent
398388 verbose_findlib prelude prelude_str file section root force_output output :
0 commit comments