Pure OCaml Yaml 1.2 reader and writer using Bytesrw

run yaml-test-suite in ci

+3
.gitignore
···
# Third-party sources (fetch locally with opam source)
third_party/
+
# YAML test suite (clone manually to tests/ for running test suite)
+
tests/yaml-test-suite/
+
# Editor and OS files
.DS_Store
*.swp
+8 -1
.tangled/workflows/build.yml
···
opam install . --confirm-level=unsafe-yes --deps-only
- name: build
command: |
-
opam exec -- dune build
+
opam exec -- dune build yamlrw.install yamlrw-unix.install yamlrw-eio.install
- name: switch-test
command: |
opam install . --confirm-level=unsafe-yes --deps-only --with-test
···
command: |
opam install -y odoc
opam exec -- dune build @doc
+
- name: yaml-test-suite-setup
+
command: |
+
git clone --depth 1 -b data https://github.com/yaml/yaml-test-suite tests/yaml-test-suite
+
- name: yaml-test-suite
+
command: |
+
opam exec -- dune build @yaml-test-suite
+
opam exec -- dune build @yaml-test-suite-eio
+46
README.md
···
yamlcat input.yaml
```
+
## Testing
+
+
Yamlrw is tested against the official [YAML Test Suite](https://github.com/yaml/yaml-test-suite), a comprehensive collection of YAML test cases.
+
+
### Running the Full Test Suite
+
+
To run the complete YAML test suite with HTML report generation:
+
+
1. **Clone the test suite** (one-time setup):
+
```bash
+
cd tests
+
git clone --depth 1 --branch data https://github.com/yaml/yaml-test-suite
+
cd ..
+
```
+
+
2. **Run the tests**:
+
```bash
+
# Standard tests with HTML report
+
opam exec -- dune build @yaml-test-suite
+
+
# Eio-based tests with HTML report
+
opam exec -- dune build @yaml-test-suite-eio
+
```
+
+
**View the results**:
+
- The HTML reports are generated in `_build/default/tests/yaml-test-results.html` and `_build/default/tests/yaml-test-results-eio.html`
+
- Open them in a browser to see detailed test results with filtering and search capabilities
+
+
### Running Unit Tests
+
+
Run the standard unit tests:
+
+
```bash
+
opam exec -- dune runtest
+
```
+
+
### CI Integration
+
+
The CI pipeline automatically:
+
- Runs all unit tests
+
- Clones the YAML test suite
+
- Executes the full test suite
+
- Generates HTML reports
+
+
All tests must pass before merging changes.
+
## API Documentation
Build the documentation with:
+2
dune-project
···
(generate_opam_files true)
+
(using directory-targets 0.1)
+
(license ISC)
(authors "Anil Madhavapeddy")
(homepage "https://tangled.org/@anil.recoil.org/ocaml-yamlrw")
+31
tests/dune
···
+
; Test executables for the full YAML test suite
+
+
(executable
+
(name run_all_tests)
+
(modules run_all_tests test_yamlrw)
+
(libraries yamlrw test_suite_lib alcotest))
+
+
(executable
+
(name run_all_tests_eio)
+
(modules run_all_tests_eio)
+
(libraries yamlrw test_suite_lib_eio eio_main))
+
+
; Alias to run the full YAML test suite and generate HTML report
+
; Requires yaml-test-suite to be cloned to tests/yaml-test-suite
+
(rule
+
(alias yaml-test-suite)
+
(deps (source_tree yaml-test-suite))
+
(targets yaml-test-results.html)
+
(action
+
(run %{exe:run_all_tests.exe}
+
--test-suite-path %{workspace_root}/tests/yaml-test-suite
+
--html yaml-test-results.html)))
+
+
(rule
+
(alias yaml-test-suite-eio)
+
(deps (source_tree yaml-test-suite))
+
(targets yaml-test-results-eio.html)
+
(action
+
(run %{exe:run_all_tests_eio.exe}
+
--test-suite-path %{workspace_root}/tests/yaml-test-suite
+
--html yaml-test-results-eio.html)))
+6 -3
tests/run_all_tests.ml
···
module JF = Test_suite_lib.Json_format
module JC = Test_suite_lib.Json_compare
-
let test_suite_path = "../yaml-test-suite"
+
let test_suite_path = "yaml-test-suite"
(* HTML escape function *)
let html_escape s =
···
let () =
let html_output = ref None in
let show_skipped = ref false in
+
let test_suite_path_ref = ref test_suite_path in
let args = [
"--html", Arg.String (fun s -> html_output := Some s),
"<file> Generate HTML report to file";
"--show-skipped", Arg.Set show_skipped,
" Show details of skipped tests";
+
"--test-suite-path", Arg.Set_string test_suite_path_ref,
+
"<path> Path to yaml-test-suite directory";
] in
-
Arg.parse args (fun _ -> ()) "Usage: run_all_tests [--html <file>] [--show-skipped]";
+
Arg.parse args (fun _ -> ()) "Usage: run_all_tests [--html <file>] [--show-skipped] [--test-suite-path <path>]";
-
let all_tests = TL.load_directory test_suite_path in
+
let all_tests = TL.load_directory !test_suite_path_ref in
Printf.printf "Total tests loaded: %d\n%!" (List.length all_tests);
let results = List.map run_test all_tests in
+8 -6
tests/run_all_tests_eio.ml
···
module JF = Test_suite_lib.Json_format
module JC = Test_suite_lib.Json_compare
-
let test_suite_path = "../yaml-test-suite"
+
let test_suite_path = "yaml-test-suite"
(* HTML escape function *)
let html_escape s =
···
let html_output = ref None in
let show_skipped = ref false in
let sequential = ref false in
+
let test_suite_path_ref = ref test_suite_path in
let args = [
"--html", Arg.String (fun s -> html_output := Some s),
"<file> Generate HTML report to file";
···
" Show details of skipped tests";
"--sequential", Arg.Set sequential,
" Run tests sequentially instead of in parallel";
+
"--test-suite-path", Arg.Set_string test_suite_path_ref,
+
"<path> Path to yaml-test-suite directory";
] in
-
Arg.parse args (fun _ -> ()) "Usage: run_all_tests_eio [--html <file>] [--show-skipped] [--sequential]";
+
Arg.parse args (fun _ -> ()) "Usage: run_all_tests_eio [--html <file>] [--show-skipped] [--sequential] [--test-suite-path <path>]";
Eio_main.run @@ fun env ->
(* Use fs (full filesystem) rather than cwd (sandboxed) to allow ".." navigation *)
let fs = Eio.Stdenv.fs env in
(* Get the absolute path to the test suite *)
-
let cwd = Sys.getcwd () in
-
let test_suite_abs = if Filename.is_relative test_suite_path then
-
Filename.concat cwd test_suite_path
+
let test_suite_abs = if Filename.is_relative !test_suite_path_ref then
+
Filename.concat (Sys.getcwd ()) !test_suite_path_ref
else
-
test_suite_path
+
!test_suite_path_ref
in
let start_time = Unix.gettimeofday () in