Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mdx_test: Lazily initialize OCaml toplevel #376

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/test/mdx_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,9 @@ let run_exn ~non_deterministic ~silent_eval ~record_backtrace ~syntax ~silent
match syntax with Some syntax -> Some syntax | None -> Syntax.infer ~file
in
let c =
Mdx_top.init ~verbose:(not silent_eval) ~silent ~verbose_findlib ~directives
~packages ~predicates ()
lazy
(Mdx_top.init ~verbose:(not silent_eval) ~silent ~verbose_findlib
~directives ~packages ~predicates ())
in
let preludes = preludes ~prelude ~prelude_str in

Expand All @@ -350,6 +351,7 @@ let run_exn ~non_deterministic ~silent_eval ~record_backtrace ~syntax ~silent
let new_content = read_part file_included None in
update_block_content ?syntax ppf t new_content
| OCaml { non_det; env; errors; header = _ } ->
let c = Lazy.force c in
let det () =
assert (syntax <> Some Cram);
Mdx_top.in_env env (fun () ->
Expand All @@ -369,6 +371,7 @@ let run_exn ~non_deterministic ~silent_eval ~record_backtrace ~syntax ~silent
~on_evaluation:(fun () ->
run_cram_tests ?syntax t ?root ppf temp_file tests)
| Toplevel { non_det; env } ->
let c = Lazy.force c in
let phrases = Toplevel.of_lines ~loc:t.loc t.contents in
with_non_det non_deterministic non_det ~on_skip_execution:print_block
~on_keep_old_output:(fun () ->
Expand Down Expand Up @@ -398,8 +401,11 @@ let run_exn ~non_deterministic ~silent_eval ~record_backtrace ~syntax ~silent
let buf = Buffer.create (String.length file_contents + 1024) in
let ppf = Format.formatter_of_buffer buf in
let envs = Document.envs items in
let eval lines () = eval_raw ?root c lines in
let eval_in_env lines env = Mdx_top.in_env env (eval lines) in
let eval c lines () = eval_raw ?root c lines in
let eval_in_env lines env =
let c = Lazy.force c in
Mdx_top.in_env env (eval c lines)
in
List.iter
(function
| `All, lines -> Ocaml_env.Set.iter (eval_in_env lines) envs
Expand Down
Loading