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