From be85e6f73903f91a04ed4e137e6dd1baaa6d44d0 Mon Sep 17 00:00:00 2001 From: hhugo Date: Tue, 17 Dec 2024 13:22:49 +0100 Subject: [PATCH] Tests: better constraint for tests (#1773) --- compiler/tests-check-prim/dune | 127 +++--------------- compiler/tests-check-prim/dune.inc | 90 +++++++++++++ compiler/tests-check-prim/gen_dune.ml | 106 +++++++++++++++ .../{main.output => main.4.14.output} | 0 .../{main.output5 => main.5.2.output} | 0 ...unix-unix.output => unix-Unix.4.14.output} | 0 ...unix-unix.output5 => unix-Unix.5.2.output} | 0 ...ix-win32.output => unix-Win32.4.14.output} | 0 ...ix-win32.output5 => unix-Win32.5.2.output} | 0 9 files changed, 216 insertions(+), 107 deletions(-) create mode 100644 compiler/tests-check-prim/dune.inc create mode 100644 compiler/tests-check-prim/gen_dune.ml rename compiler/tests-check-prim/{main.output => main.4.14.output} (100%) rename compiler/tests-check-prim/{main.output5 => main.5.2.output} (100%) rename compiler/tests-check-prim/{unix-unix.output => unix-Unix.4.14.output} (100%) rename compiler/tests-check-prim/{unix-unix.output5 => unix-Unix.5.2.output} (100%) rename compiler/tests-check-prim/{unix-win32.output => unix-Win32.4.14.output} (100%) rename compiler/tests-check-prim/{unix-win32.output5 => unix-Win32.5.2.output} (100%) diff --git a/compiler/tests-check-prim/dune b/compiler/tests-check-prim/dune index 5a0767a948..6db8e86676 100644 --- a/compiler/tests-check-prim/dune +++ b/compiler/tests-check-prim/dune @@ -1,119 +1,32 @@ -(executables - (names main) +(include dune.inc) + +(rule + (action + (with-stdout-to + dune.inc.gen + (run ./gen_dune.exe)))) + +(rule + (alias runtest) + (action + (diff dune.inc dune.inc.gen))) + +(executable + (name main) (libraries js_of_ocaml num str) (link_flags (:standard -linkall)) (modules main) (modes byte)) -(executables - (names unix) +(executable + (name unix) (libraries js_of_ocaml num str unix) (link_flags (:standard -linkall)) (modules unix) (modes byte)) -(rule - (targets main.output) - (mode - (promote (until-clean))) - (enabled_if - (< %{ocaml_version} 5)) - (action - (with-stdout-to - %{targets} - (run - %{bin:js_of_ocaml} - check-runtime - +dynlink.js - +toplevel.js - %{dep:main.bc})))) - -(rule - (targets unix-unix.output) - (enabled_if - (and - (< %{ocaml_version} 5) - (= %{os_type} Unix))) - (mode - (promote (until-clean))) - (action - (with-stdout-to - %{targets} - (run - %{bin:js_of_ocaml} - check-runtime - +dynlink.js - +toplevel.js - %{dep:unix.bc})))) - -(rule - (targets unix-win32.output) - (enabled_if - (and - (< %{ocaml_version} 5) - (= %{os_type} Win32))) - (mode - (promote (until-clean))) - (action - (with-stdout-to - %{targets} - (run - %{bin:js_of_ocaml} - check-runtime - +dynlink.js - +toplevel.js - %{dep:unix.bc})))) - -(rule - (targets main.output5) - (mode - (promote (until-clean))) - (enabled_if - (>= %{ocaml_version} 5)) - (action - (with-stdout-to - %{targets} - (run - %{bin:js_of_ocaml} - check-runtime - +dynlink.js - +toplevel.js - %{dep:main.bc})))) - -(rule - (targets unix-unix.output5) - (enabled_if - (and - (>= %{ocaml_version} 5) - (= %{os_type} Unix))) - (mode - (promote (until-clean))) - (action - (with-stdout-to - %{targets} - (run - %{bin:js_of_ocaml} - check-runtime - +dynlink.js - +toplevel.js - %{dep:unix.bc})))) - -(rule - (targets unix-win32.output5) - (enabled_if - (and - (>= %{ocaml_version} 5) - (= %{os_type} Win32))) - (mode - (promote (until-clean))) - (action - (with-stdout-to - %{targets} - (run - %{bin:js_of_ocaml} - check-runtime - +dynlink.js - +toplevel.js - %{dep:unix.bc})))) +(executable + (name gen_dune) + (modules gen_dune)) diff --git a/compiler/tests-check-prim/dune.inc b/compiler/tests-check-prim/dune.inc new file mode 100644 index 0000000000..c81755b8a7 --- /dev/null +++ b/compiler/tests-check-prim/dune.inc @@ -0,0 +1,90 @@ +(rule + (targets main.4.14.output) + (mode + (promote (until-clean))) + (enabled_if (and (>= %{ocaml_version} 4.14)(< %{ocaml_version} 5.0))) + (action + (with-stdout-to + %{targets} + (run + %{bin:js_of_ocaml} + check-runtime + +dynlink.js + +toplevel.js + %{dep:main.bc})))) + +(rule + (targets unix-Win32.4.14.output) + (mode + (promote (until-clean))) + (enabled_if (and (>= %{ocaml_version} 4.14)(< %{ocaml_version} 5.0)(= %{os_type} Win32))) + (action + (with-stdout-to + %{targets} + (run + %{bin:js_of_ocaml} + check-runtime + +dynlink.js + +toplevel.js + %{dep:unix.bc})))) + +(rule + (targets unix-Unix.4.14.output) + (mode + (promote (until-clean))) + (enabled_if (and (>= %{ocaml_version} 4.14)(< %{ocaml_version} 5.0)(= %{os_type} Unix))) + (action + (with-stdout-to + %{targets} + (run + %{bin:js_of_ocaml} + check-runtime + +dynlink.js + +toplevel.js + %{dep:unix.bc})))) + +(rule + (targets main.5.2.output) + (mode + (promote (until-clean))) + (enabled_if (and (>= %{ocaml_version} 5.2)(< %{ocaml_version} 5.3))) + (action + (with-stdout-to + %{targets} + (run + %{bin:js_of_ocaml} + check-runtime + +dynlink.js + +toplevel.js + %{dep:main.bc})))) + +(rule + (targets unix-Win32.5.2.output) + (mode + (promote (until-clean))) + (enabled_if (and (>= %{ocaml_version} 5.2)(< %{ocaml_version} 5.3)(= %{os_type} Win32))) + (action + (with-stdout-to + %{targets} + (run + %{bin:js_of_ocaml} + check-runtime + +dynlink.js + +toplevel.js + %{dep:unix.bc})))) + +(rule + (targets unix-Unix.5.2.output) + (mode + (promote (until-clean))) + (enabled_if (and (>= %{ocaml_version} 5.2)(< %{ocaml_version} 5.3)(= %{os_type} Unix))) + (action + (with-stdout-to + %{targets} + (run + %{bin:js_of_ocaml} + check-runtime + +dynlink.js + +toplevel.js + %{dep:unix.bc})))) + diff --git a/compiler/tests-check-prim/gen_dune.ml b/compiler/tests-check-prim/gen_dune.ml new file mode 100644 index 0000000000..a39bb727c6 --- /dev/null +++ b/compiler/tests-check-prim/gen_dune.ml @@ -0,0 +1,106 @@ +(** *) + +type version = + [ `V4_08 + | `V4_09 + | `V4_10 + | `V4_11 + | `V4_12 + | `V4_13 + | `V4_14 + | `V5_0 + | `V5_1 + | `V5_2 + | `V5_3 + | `V5_4 + ] + +let string_of_version : version -> string = function + | `V4_08 -> "4.08" + | `V4_09 -> "4.09" + | `V4_10 -> "4.10" + | `V4_11 -> "4.11" + | `V4_12 -> "4.12" + | `V4_13 -> "4.13" + | `V4_14 -> "4.14" + | `V5_0 -> "5.0" + | `V5_1 -> "5.1" + | `V5_2 -> "5.2" + | `V5_3 -> "5.3" + | `V5_4 -> "5.4" + +let next_version : version -> version option = function + | `V4_08 -> Some `V4_09 + | `V4_09 -> Some `V4_10 + | `V4_10 -> Some `V4_11 + | `V4_11 -> Some `V4_12 + | `V4_12 -> Some `V4_13 + | `V4_13 -> Some `V4_14 + | `V4_14 -> Some `V5_0 + | `V5_0 -> Some `V5_1 + | `V5_1 -> Some `V5_2 + | `V5_2 -> Some `V5_3 + | `V5_3 -> Some `V5_4 + | `V5_4 -> None + +type os_type = + | Unix + | Win32 + +let string_of_os_type = function + | Unix -> "Unix" + | Win32 -> "Win32" + +let rule bc ocaml_version os_type = + let vl = + [ Printf.sprintf "(>= %%{ocaml_version} %s)" (string_of_version ocaml_version) ] + in + let vu = + match next_version ocaml_version with + | None -> [] + | Some up -> [ Printf.sprintf "(< %%{ocaml_version} %s)" (string_of_version up) ] + in + let os = + match os_type with + | None -> [] + | Some os_type -> [ Printf.sprintf "(= %%{os_type} %s)" (string_of_os_type os_type) ] + in + let enabled_if = Printf.sprintf "(and %s)" (String.concat "" (vl @ vu @ os)) in + + let target = + Filename.chop_extension bc + ^ (match os_type with + | None -> "" + | Some os_type -> "-" ^ string_of_os_type os_type) + ^ "." + ^ string_of_version ocaml_version + ^ ".output" + in + Printf.sprintf + {|(rule + (targets %s) + (mode + (promote (until-clean))) + (enabled_if %s) + (action + (with-stdout-to + %%{targets} + (run + %%{bin:js_of_ocaml} + check-runtime + +dynlink.js + +toplevel.js + %%{dep:%s})))) +|} + target + enabled_if + bc + +let () = + let versions : version list = [ `V4_14; `V5_2 ] in + List.iter + (fun ocaml_version -> + List.iter + (fun (bc, os_type) -> print_endline (rule bc ocaml_version os_type)) + [ "main.bc", None; "unix.bc", Some Win32; "unix.bc", Some Unix ]) + versions diff --git a/compiler/tests-check-prim/main.output b/compiler/tests-check-prim/main.4.14.output similarity index 100% rename from compiler/tests-check-prim/main.output rename to compiler/tests-check-prim/main.4.14.output diff --git a/compiler/tests-check-prim/main.output5 b/compiler/tests-check-prim/main.5.2.output similarity index 100% rename from compiler/tests-check-prim/main.output5 rename to compiler/tests-check-prim/main.5.2.output diff --git a/compiler/tests-check-prim/unix-unix.output b/compiler/tests-check-prim/unix-Unix.4.14.output similarity index 100% rename from compiler/tests-check-prim/unix-unix.output rename to compiler/tests-check-prim/unix-Unix.4.14.output diff --git a/compiler/tests-check-prim/unix-unix.output5 b/compiler/tests-check-prim/unix-Unix.5.2.output similarity index 100% rename from compiler/tests-check-prim/unix-unix.output5 rename to compiler/tests-check-prim/unix-Unix.5.2.output diff --git a/compiler/tests-check-prim/unix-win32.output b/compiler/tests-check-prim/unix-Win32.4.14.output similarity index 100% rename from compiler/tests-check-prim/unix-win32.output rename to compiler/tests-check-prim/unix-Win32.4.14.output diff --git a/compiler/tests-check-prim/unix-win32.output5 b/compiler/tests-check-prim/unix-Win32.5.2.output similarity index 100% rename from compiler/tests-check-prim/unix-win32.output5 rename to compiler/tests-check-prim/unix-Win32.5.2.output