@@ -54,7 +54,8 @@ module For_tests = struct
5454
5555 let dyn_of_block = function
5656 | Cram_lexer. Comment lines -> Dyn. variant " Comment" [ Dyn. list Dyn. string lines ]
57- | Command lines -> Dyn. variant " Command" [ Dyn. list Dyn. string lines ]
57+ | Command (loc , lines ) ->
58+ Dyn. variant " Command" [ Loc. to_dyn loc; Dyn. list Dyn. string lines ]
5859 ;;
5960end
6061
@@ -178,10 +179,10 @@ let read_and_attach_exit_codes (sh_script : sh_script)
178179 | [] , [] -> List. rev acc
179180 | (Cram_lexer. Comment _ as comment ) :: blocks , _ ->
180181 loop (comment :: acc) entries blocks
181- | Command block_result :: blocks , metadata_entry :: entries ->
182- loop (Command (block_result, Present metadata_entry) :: acc) entries blocks
183- | Cram_lexer. Command block_result :: blocks , [] ->
184- loop (Command (block_result, Missing_unreachable ) :: acc) entries blocks
182+ | Command ( loc , block_result ) :: blocks , metadata_entry :: entries ->
183+ loop (Command (loc, ( block_result, Present metadata_entry) ) :: acc) entries blocks
184+ | Cram_lexer. Command ( loc , block_result ) :: blocks , [] ->
185+ loop (Command (loc, ( block_result, Missing_unreachable ) ) :: acc) entries blocks
185186 | [] , _ :: _ -> Code_error. raise " more blocks than metadata" []
186187 in
187188 loop [] metadata_entries sh_script.cram_to_output
@@ -238,7 +239,7 @@ let sanitize ~parent_script cram_to_output : command_out Cram_lexer.block list =
238239 List. map cram_to_output ~f: (fun (t : (block_result * _) Cram_lexer.block ) ->
239240 match t with
240241 | Cram_lexer. Comment t -> Cram_lexer. Comment t
241- | Command (block_result , metadata ) ->
242+ | Command (loc , ( block_result , metadata ) ) ->
242243 let output =
243244 match metadata with
244245 | Missing_unreachable -> " ***** UNREACHABLE *****"
@@ -250,7 +251,7 @@ let sanitize ~parent_script cram_to_output : command_out Cram_lexer.block list =
250251 ~command_script: block_result.script
251252 build_path_prefix_map
252253 in
253- Command { command = block_result.command; metadata; output })
254+ Command (loc, { command = block_result.command; metadata; output }) )
254255;;
255256
256257(* Compose user written cram stanzas to output *)
@@ -267,7 +268,7 @@ let compose_cram_output (cram_to_output : _ Cram_lexer.block list) =
267268 List. iter cram_to_output ~f: (fun block ->
268269 match (block : _ Cram_lexer.block ) with
269270 | Comment lines -> List. iter lines ~f: add_line
270- | Command { command; metadata; output } ->
271+ | Command ( _loc , { command; metadata; output } ) ->
271272 List. iteri command ~f: (fun i line ->
272273 let line = sprintf " %c %s" (if i = 0 then '$' else '>' ) line in
273274 add_line_prefixed_with_two_space line);
@@ -314,7 +315,7 @@ let create_sh_script cram_stanzas ~temp_dir : sh_script Fiber.t =
314315 let loop block =
315316 match (block : _ Cram_lexer.block ) with
316317 | Comment _ as comment -> Fiber. return comment
317- | Command lines ->
318+ | Command ( loc , lines ) ->
318319 incr i;
319320 let i = ! i in
320321 let file ~ext = file (sprintf " %d%s" i ext) in
@@ -340,10 +341,11 @@ let create_sh_script cram_stanzas ~temp_dir : sh_script Fiber.t =
340341 Dune_util.Build_path_prefix_map. _BUILD_PATH_PREFIX_MAP
341342 metadata_file_sh_path;
342343 Cram_lexer. Command
343- { command = lines
344- ; output_file = user_shell_code_output_file
345- ; script = user_shell_code_file
346- }
344+ ( loc
345+ , { command = lines
346+ ; output_file = user_shell_code_output_file
347+ ; script = user_shell_code_file
348+ } )
347349 in
348350 fprln oc " trap 'exit 0' EXIT" ;
349351 let + cram_to_output = Fiber. sequential_map ~f: loop cram_stanzas in
@@ -433,7 +435,7 @@ let run_cram_test env ~src ~script ~cram_stanzas ~temp_dir ~cwd ~timeout =
433435 let command_blocks_only =
434436 List. filter_map sh_script.cram_to_output ~f: (function
435437 | Cram_lexer. Comment _ -> None
436- | Cram_lexer. Command block_result -> Some block_result)
438+ | Cram_lexer. Command ( _ , block_result ) -> Some block_result)
437439 in
438440 let total_commands = List. length command_blocks_only in
439441 if completed_count < total_commands
@@ -486,7 +488,7 @@ let run_and_produce_output ~src ~env ~dir:cwd ~script ~dst ~timeout =
486488 let + commands =
487489 run_cram_test env ~src ~script ~cram_stanzas ~temp_dir ~cwd ~timeout
488490 >> | List. filter_map ~f: (function
489- | Cram_lexer. Command c -> Some c
491+ | Cram_lexer. Command ( _ , c ) -> Some c
490492 | Comment _ -> None )
491493 in
492494 let dst = Path. build dst in
@@ -552,7 +554,7 @@ module Make_script = struct
552554 |> cram_stanzas
553555 |> List. filter_map ~f: (function
554556 | Cram_lexer. Comment _ -> None
555- | Command s -> Some s)
557+ | Command ( _ , s ) -> Some s)
556558 |> cram_commmands
557559 in
558560 Io. write_file ~binary: false (Path. build dst) commands;
@@ -596,10 +598,11 @@ module Diff = struct
596598 | [] -> acc
597599 | Cram_lexer. Comment x :: current ->
598600 loop (Cram_lexer. Comment x :: acc) current expected
599- | Command _ :: current ->
601+ | Command ( loc , _ ) :: current ->
600602 (match expected with
601603 | [] -> acc
602- | out :: expected -> loop (Cram_lexer. Command out :: acc) current expected)
604+ | out :: expected ->
605+ loop (Cram_lexer. Command (loc, out) :: acc) current expected)
603606 in
604607 loop [] current_stanzas out |> List. rev
605608 in
0 commit comments