Remove dependency on Janestreet Core

Core doubles the closure size and adds 8mb to the binary size for dubious benefit.
This adds FileUtils to do the file interaction bits that aren't in the
stdlib and removes Core in preference to the bundled Stdlib.

Tests are passing, but I want to investigate the nix build before I
commit to this approach
This commit is contained in:
Bryan Bennett 2024-08-12 12:13:53 -04:00
parent 3f5f7a602d
commit 5c01142933
No known key found for this signature in database
GPG key ID: EE149E4215408DE9
11 changed files with 184 additions and 232 deletions

View file

@ -1,21 +1,32 @@
open Core;
module Unix = Core_unix;
open Lib.Util;
open Unix;
let _pp_exit_or_signal = (pp_fmt, e) =>
Fmt.pf(pp_fmt, "%s", Unix.Exit_or_signal.to_string_hum(e));
let _exit_or_signal_eq = (a, b) => Unix.Exit_or_signal.compare(a, b) == 0;
let testable_exit_or_signal =
Alcotest.testable(_pp_exit_or_signal, _exit_or_signal_eq);
let _pp_process_status = (pp_fmt, proc_stat) =>
switch (proc_stat) {
| WEXITED(i) => Fmt.pf(pp_fmt, "Exited normally with status %d", i)
| WSIGNALED(i) => Fmt.pf(pp_fmt, "Killed by signal %d", i)
| WSTOPPED(i) => Fmt.pf(pp_fmt, "Stopped by signal %d", i)
};
let _process_status_eq = (a, b) => {
switch (a, b) {
| (WEXITED(a_i), WEXITED(b_i)) when a_i == b_i => true
| (WSIGNALED(a_i), WSIGNALED(b_i)) when a_i == b_i => true
| (WSTOPPED(a_i), WSTOPPED(b_i)) when a_i == b_i => true
| _ => false
};
};
let testable_process_status =
Alcotest.testable(_pp_process_status, _process_status_eq);
let _syst_to_bool =
fun
| `Yes => true
| _ => false;
let check_exit_or_signal =
Alcotest.(check(Alcotest.pair(testable_exit_or_signal, string)));
let check_process_status =
Alcotest.(check(Alcotest.pair(testable_process_status, string)));
let testable_result_string =
Alcotest.testable(
(pp_fmt, elem) => {
@ -32,7 +43,6 @@ let testable_result_string =
},
);
let check_result_string = Alcotest.(check(testable_result_string));
let check_bool = Alcotest.(check(bool));
let check_get_args =
Alcotest.(
check(
@ -41,23 +51,23 @@ let check_get_args =
);
let test_run_process_success = () =>
check_exit_or_signal(
check_process_status(
"Returns expected",
(Ok(), ""),
(WEXITED(0), ""),
run_process("true", []),
);
let test_run_process_failure = () =>
check_exit_or_signal(
check_process_status(
"Returns expected",
(Error(`Exit_non_zero(1)), ""),
(WEXITED(1), ""),
run_process("false", []),
);
let test_run_process_stdout = () =>
check_exit_or_signal(
check_process_status(
"Returns expected",
(Ok(), "echoed\n"),
(WEXITED(0), "echoed\n"),
run_process("echo", ["echoed"]),
);
@ -85,30 +95,6 @@ let test_hash_filters_nonexistent = () => {
);
};
let test_rmrf_file = () => {
let tmp_file_name = Filename_unix.temp_file("test", "txt");
rmrf(tmp_file_name);
check_bool(
"File removed",
false,
_syst_to_bool(Sys_unix.is_file(tmp_file_name)),
);
};
let test_rmrf_dir = () => {
let temp_dir_name = Filename_unix.temp_dir("test", "d");
let _ = Filename_unix.temp_file(~in_dir=temp_dir_name, "test", "txt");
rmrf(temp_dir_name);
check_bool(
"File removed",
false,
_syst_to_bool(Sys_unix.file_exists(temp_dir_name)),
);
};
let test_get_args_simple = () => {
check_get_args(
"Parses successfully",
@ -158,13 +144,6 @@ let () =
),
],
),
(
"rmrf helper",
[
test_case("Removes file", `Quick, test_rmrf_file),
test_case("Removes dir", `Quick, test_rmrf_dir),
],
),
(
"get_args",
[