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 Eio for file I/O *)
7
8module Generic = Test_suite_lib.Test_suite_loader_generic
9
10(** Eio file I/O implementation *)
11module Eio_io : Generic.FILE_IO with type ctx = Eio.Fs.dir_ty Eio.Path.t =
12struct
13 type ctx = Eio.Fs.dir_ty Eio.Path.t
14
15 let read_file fs path =
16 try Some (Eio.Path.load Eio.Path.(fs / path)) with _ -> None
17
18 let file_exists fs path =
19 match Eio.Path.kind ~follow:true Eio.Path.(fs / path) with
20 | `Regular_file -> true
21 | _ -> false
22 | exception _ -> false
23
24 let is_directory fs path =
25 match Eio.Path.kind ~follow:true Eio.Path.(fs / path) with
26 | `Directory -> true
27 | _ -> false
28 | exception _ -> false
29
30 let read_dir fs path = Eio.Path.read_dir Eio.Path.(fs / path)
31end
32
33module Loader = Generic.Make (Eio_io)
34(** Internal loader module *)
35
36type test_case = Loader.test_case = {
37 id : string;
38 name : string;
39 yaml : string;
40 tree : string option;
41 json : string option;
42 fail : bool;
43}
44(** Re-export test_case type from loader *)
45
46(** Load tests with Eio filesystem context *)
47let load_directory ~fs path : test_case list = Loader.load_directory fs path
48
49(** Parallel loading of test directories - load all test IDs concurrently *)
50let load_directory_parallel ~fs test_suite_path : test_case list =
51 if not (Eio_io.is_directory fs test_suite_path) then []
52 else
53 let entries = Eio_io.read_dir fs test_suite_path in
54 let test_ids =
55 entries
56 |> List.filter (fun e ->
57 Eio_io.is_directory fs (Filename.concat test_suite_path e)
58 && String.length e >= 4
59 && e.[0] >= '0'
60 && e.[0] <= 'Z')
61 |> List.sort String.compare
62 in
63 (* Load each test ID in parallel using fibers with bounded concurrency *)
64 Eio.Fiber.List.map ~max_fibers:50
65 (fun test_id -> Loader.load_test_id fs test_suite_path test_id)
66 test_ids
67 |> List.concat