diff --git a/hosts/ocaml/bin/run_tests.ml b/hosts/ocaml/bin/run_tests.ml index b4632ff0..4f9e891a 100644 --- a/hosts/ocaml/bin/run_tests.ml +++ b/hosts/ocaml/bin/run_tests.ml @@ -308,6 +308,18 @@ let make_test_env () = | [expr] -> eval_expr expr (Env env) | _ -> raise (Eval_error "eval-expr: expected (expr env)")); bind "set-render-active!" (fun _args -> Nil); + (* render-to-sx wrapper: if called with a string, parse and aser it *) + bind "render-to-sx" (fun args -> + match args with + | [String src] -> + 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)) + | [expr; Env e] -> + let result = eval_expr (List [Symbol "aser"; expr; Env e]) (Env e) in + (match result with SxExpr s -> String s | String s -> String s | _ -> String (Sx_runtime.value_to_str result)) + | _ -> String ""); (* Scope primitives — use a local scope stacks table. Must match the same pattern as sx_server.ml's _scope_stacks. *) let _scope_stacks : (string, Sx_types.value list) Hashtbl.t = Hashtbl.create 8 in @@ -1056,6 +1068,10 @@ let run_spec_tests env test_files = (* Determine test files — scan spec/tests/, lib/tests/, web/tests/ *) let lib_tests_dir = Filename.concat project_dir "lib/tests" in let web_tests_dir = Filename.concat project_dir "web/tests" in + + (* 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; let files = if test_files = [] then begin (* Spec tests (core language — always run) *) let spec_entries = Sys.readdir spec_tests_dir in