|
| 1 | +(*********************************************************************************) |
| 2 | +(* Volgo - A Versatile OCaml Library for Git Operations *) |
| 3 | +(* SPDX-FileCopyrightText: 2024-2026 Mathieu Barbin <mathieu.barbin@gmail.com> *) |
| 4 | +(* SPDX-License-Identifier: LGPL-3.0-or-later WITH LGPL-3.0-linking-exception *) |
| 5 | +(*********************************************************************************) |
| 6 | + |
| 7 | +module Unix = UnixLabels |
| 8 | + |
| 9 | +let toplevel_exe = "./volgo_toplevel.exe" |
| 10 | + |
| 11 | +let eval ~code = |
| 12 | + let code = String.trim code in |
| 13 | + print_endline "```ocaml"; |
| 14 | + print_endline code; |
| 15 | + print_endline "```"; |
| 16 | + print_endline ""; |
| 17 | + print_endline "```terminal"; |
| 18 | + let cmd = toplevel_exe ^ " -noprompt -no-version -color always" in |
| 19 | + let ic, oc, ec = Unix.open_process_full cmd ~env:[||] in |
| 20 | + output_string oc code; |
| 21 | + output_char oc '\n'; |
| 22 | + close_out oc; |
| 23 | + let stdout_content = In_channel.input_all ic in |
| 24 | + let stderr_content = In_channel.input_all ec in |
| 25 | + let status = Unix.close_process_full (ic, oc, ec) in |
| 26 | + let stdout_trimmed = String.trim stdout_content in |
| 27 | + if not (String.is_empty stdout_trimmed) then print_endline stdout_trimmed; |
| 28 | + let stderr_trimmed = String.trim stderr_content in |
| 29 | + if not (String.is_empty stderr_trimmed) |
| 30 | + then print_endline stderr_trimmed [@coverage off]; |
| 31 | + (match status with |
| 32 | + | WEXITED 0 -> () |
| 33 | + | _ -> |
| 34 | + (match[@coverage off] status with |
| 35 | + | WEXITED n -> Printf.printf "[%d]\n" n |
| 36 | + | WSIGNALED n -> Printf.printf "[signal %d]\n" n |
| 37 | + | WSTOPPED n -> Printf.printf "[stopped %d]\n" n)); |
| 38 | + print_endline "```" |
| 39 | +;; |
0 commit comments