Pure OCaml Yaml 1.2 reader and writer using Bytesrw

run yaml-test-suite in ci

+104 -10
+3
.gitignore
··· 6 6 # Third-party sources (fetch locally with opam source) 7 7 third_party/ 8 8 9 + # YAML test suite (clone manually to tests/ for running test suite) 10 + tests/yaml-test-suite/ 11 + 9 12 # Editor and OS files 10 13 .DS_Store 11 14 *.swp
+8 -1
.tangled/workflows/build.yml
··· 36 36 opam install . --confirm-level=unsafe-yes --deps-only 37 37 - name: build 38 38 command: | 39 - opam exec -- dune build 39 + opam exec -- dune build yamlrw.install yamlrw-unix.install yamlrw-eio.install 40 40 - name: switch-test 41 41 command: | 42 42 opam install . --confirm-level=unsafe-yes --deps-only --with-test ··· 47 47 command: | 48 48 opam install -y odoc 49 49 opam exec -- dune build @doc 50 + - name: yaml-test-suite-setup 51 + command: | 52 + git clone --depth 1 -b data https://github.com/yaml/yaml-test-suite tests/yaml-test-suite 53 + - name: yaml-test-suite 54 + command: | 55 + opam exec -- dune build @yaml-test-suite 56 + opam exec -- dune build @yaml-test-suite-eio
+46
README.md
··· 79 79 yamlcat input.yaml 80 80 ``` 81 81 82 + ## Testing 83 + 84 + Yamlrw is tested against the official [YAML Test Suite](https://github.com/yaml/yaml-test-suite), a comprehensive collection of YAML test cases. 85 + 86 + ### Running the Full Test Suite 87 + 88 + To run the complete YAML test suite with HTML report generation: 89 + 90 + 1. **Clone the test suite** (one-time setup): 91 + ```bash 92 + cd tests 93 + git clone --depth 1 --branch data https://github.com/yaml/yaml-test-suite 94 + cd .. 95 + ``` 96 + 97 + 2. **Run the tests**: 98 + ```bash 99 + # Standard tests with HTML report 100 + opam exec -- dune build @yaml-test-suite 101 + 102 + # Eio-based tests with HTML report 103 + opam exec -- dune build @yaml-test-suite-eio 104 + ``` 105 + 106 + **View the results**: 107 + - The HTML reports are generated in `_build/default/tests/yaml-test-results.html` and `_build/default/tests/yaml-test-results-eio.html` 108 + - Open them in a browser to see detailed test results with filtering and search capabilities 109 + 110 + ### Running Unit Tests 111 + 112 + Run the standard unit tests: 113 + 114 + ```bash 115 + opam exec -- dune runtest 116 + ``` 117 + 118 + ### CI Integration 119 + 120 + The CI pipeline automatically: 121 + - Runs all unit tests 122 + - Clones the YAML test suite 123 + - Executes the full test suite 124 + - Generates HTML reports 125 + 126 + All tests must pass before merging changes. 127 + 82 128 ## API Documentation 83 129 84 130 Build the documentation with:
+2
dune-project
··· 3 3 4 4 (generate_opam_files true) 5 5 6 + (using directory-targets 0.1) 7 + 6 8 (license ISC) 7 9 (authors "Anil Madhavapeddy") 8 10 (homepage "https://tangled.org/@anil.recoil.org/ocaml-yamlrw")
+31
tests/dune
··· 1 + ; Test executables for the full YAML test suite 2 + 3 + (executable 4 + (name run_all_tests) 5 + (modules run_all_tests test_yamlrw) 6 + (libraries yamlrw test_suite_lib alcotest)) 7 + 8 + (executable 9 + (name run_all_tests_eio) 10 + (modules run_all_tests_eio) 11 + (libraries yamlrw test_suite_lib_eio eio_main)) 12 + 13 + ; Alias to run the full YAML test suite and generate HTML report 14 + ; Requires yaml-test-suite to be cloned to tests/yaml-test-suite 15 + (rule 16 + (alias yaml-test-suite) 17 + (deps (source_tree yaml-test-suite)) 18 + (targets yaml-test-results.html) 19 + (action 20 + (run %{exe:run_all_tests.exe} 21 + --test-suite-path %{workspace_root}/tests/yaml-test-suite 22 + --html yaml-test-results.html))) 23 + 24 + (rule 25 + (alias yaml-test-suite-eio) 26 + (deps (source_tree yaml-test-suite)) 27 + (targets yaml-test-results-eio.html) 28 + (action 29 + (run %{exe:run_all_tests_eio.exe} 30 + --test-suite-path %{workspace_root}/tests/yaml-test-suite 31 + --html yaml-test-results-eio.html)))
+6 -3
tests/run_all_tests.ml
··· 9 9 module JF = Test_suite_lib.Json_format 10 10 module JC = Test_suite_lib.Json_compare 11 11 12 - let test_suite_path = "../yaml-test-suite" 12 + let test_suite_path = "yaml-test-suite" 13 13 14 14 (* HTML escape function *) 15 15 let html_escape s = ··· 424 424 let () = 425 425 let html_output = ref None in 426 426 let show_skipped = ref false in 427 + let test_suite_path_ref = ref test_suite_path in 427 428 let args = [ 428 429 "--html", Arg.String (fun s -> html_output := Some s), 429 430 "<file> Generate HTML report to file"; 430 431 "--show-skipped", Arg.Set show_skipped, 431 432 " Show details of skipped tests"; 433 + "--test-suite-path", Arg.Set_string test_suite_path_ref, 434 + "<path> Path to yaml-test-suite directory"; 432 435 ] in 433 - Arg.parse args (fun _ -> ()) "Usage: run_all_tests [--html <file>] [--show-skipped]"; 436 + Arg.parse args (fun _ -> ()) "Usage: run_all_tests [--html <file>] [--show-skipped] [--test-suite-path <path>]"; 434 437 435 - let all_tests = TL.load_directory test_suite_path in 438 + let all_tests = TL.load_directory !test_suite_path_ref in 436 439 Printf.printf "Total tests loaded: %d\n%!" (List.length all_tests); 437 440 438 441 let results = List.map run_test all_tests in
+8 -6
tests/run_all_tests_eio.ml
··· 11 11 module JF = Test_suite_lib.Json_format 12 12 module JC = Test_suite_lib.Json_compare 13 13 14 - let test_suite_path = "../yaml-test-suite" 14 + let test_suite_path = "yaml-test-suite" 15 15 16 16 (* HTML escape function *) 17 17 let html_escape s = ··· 437 437 let html_output = ref None in 438 438 let show_skipped = ref false in 439 439 let sequential = ref false in 440 + let test_suite_path_ref = ref test_suite_path in 440 441 let args = [ 441 442 "--html", Arg.String (fun s -> html_output := Some s), 442 443 "<file> Generate HTML report to file"; ··· 444 445 " Show details of skipped tests"; 445 446 "--sequential", Arg.Set sequential, 446 447 " Run tests sequentially instead of in parallel"; 448 + "--test-suite-path", Arg.Set_string test_suite_path_ref, 449 + "<path> Path to yaml-test-suite directory"; 447 450 ] in 448 - Arg.parse args (fun _ -> ()) "Usage: run_all_tests_eio [--html <file>] [--show-skipped] [--sequential]"; 451 + Arg.parse args (fun _ -> ()) "Usage: run_all_tests_eio [--html <file>] [--show-skipped] [--sequential] [--test-suite-path <path>]"; 449 452 450 453 Eio_main.run @@ fun env -> 451 454 (* Use fs (full filesystem) rather than cwd (sandboxed) to allow ".." navigation *) 452 455 let fs = Eio.Stdenv.fs env in 453 456 (* Get the absolute path to the test suite *) 454 - let cwd = Sys.getcwd () in 455 - let test_suite_abs = if Filename.is_relative test_suite_path then 456 - Filename.concat cwd test_suite_path 457 + let test_suite_abs = if Filename.is_relative !test_suite_path_ref then 458 + Filename.concat (Sys.getcwd ()) !test_suite_path_ref 457 459 else 458 - test_suite_path 460 + !test_suite_path_ref 459 461 in 460 462 461 463 let start_time = Unix.gettimeofday () in