diff --git a/hosts/ocaml/bin/run_tests.ml b/hosts/ocaml/bin/run_tests.ml index 4f9e891a..3b3ec8f4 100644 --- a/hosts/ocaml/bin/run_tests.ml +++ b/hosts/ocaml/bin/run_tests.ml @@ -1072,6 +1072,25 @@ let run_spec_tests env test_files = (* Pre-load test-handlers.sx so its mock definitions (reset-mocks!, helper, etc.) are available to test-examples.sx which loads before it alphabetically *) load_module "test-handlers.sx" web_tests_dir; + + (* Re-bind render-to-sx AFTER adapter-sx.sx has loaded, wrapping the SX version. + The SX render-to-sx handles AST inputs; we add string→parse→aser support. *) + let sx_render_to_sx = try Some (Sx_types.env_get env "render-to-sx") with _ -> None in + ignore (Sx_types.env_bind env "render-to-sx" (NativeFn ("render-to-sx", fun args -> + match args with + | [String src] -> + (* String input: parse then evaluate via aser *) + let exprs = Sx_parser.parse_all src in + let expr = match exprs with [e] -> e | es -> List (Symbol "do" :: es) in + let result = eval_expr (List [Symbol "aser"; expr; Env env]) (Env env) in + (match result with SxExpr s -> String s | String s -> String s | _ -> String (Sx_runtime.value_to_str result)) + | _ -> + (* AST input: delegate to the SX render-to-sx *) + match sx_render_to_sx with + | Some (NativeFn (_, f)) -> f args + | Some (Lambda _ as fn) -> Sx_ref.cek_call fn (List args) + | _ -> String ""))); + let files = if test_files = [] then begin (* Spec tests (core language — always run) *) let spec_entries = Sys.readdir spec_tests_dir in