Pure OCaml Yaml 1.2 reader and writer using Bytesrw
1(*---------------------------------------------------------------------------
2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
3 SPDX-License-Identifier: ISC
4 ---------------------------------------------------------------------------*)
5
6(** Load yaml-test-suite test cases using standard OCaml I/O *)
7
8(** Synchronous file I/O implementation *)
9module Sync_io : Test_suite_loader_generic.FILE_IO with type ctx = unit = struct
10 type ctx = unit
11
12 let read_file () path =
13 try
14 let ic = open_in path in
15 let n = in_channel_length ic in
16 let s = really_input_string ic n in
17 close_in ic;
18 Some s
19 with _ -> None
20
21 let file_exists () path =
22 Sys.file_exists path
23
24 let is_directory () path =
25 Sys.file_exists path && Sys.is_directory path
26
27 let read_dir () path =
28 Array.to_list (Sys.readdir path)
29end
30
31(** Internal loader module *)
32module Loader = Test_suite_loader_generic.Make(Sync_io)
33
34(** Re-export test_case type from loader *)
35type test_case = Loader.test_case = {
36 id : string;
37 name : string;
38 yaml : string;
39 tree : string option;
40 json : string option;
41 fail : bool;
42}
43
44(** Load tests without needing to pass a context *)
45let load_directory path : test_case list = Loader.load_directory () path