From e5d5b76bdf7ec2f90fe53fc23b6b502d6b95ef55 Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Thu, 27 Jan 2022 17:41:17 +0100 Subject: [PATCH] mdx stanza: record env var dependency Since realworldocaml/mdx#366, the executable output by `ocaml-mdx dune-gen` supports `MDX_RUN_NON_DETERMINISTIC` like `ocaml-mdx test` itself. Dune needs to know about that to rerun the tests if the variable has been set in the meantime. Signed-off-by: Etienne Millon --- CHANGES.md | 2 +- Makefile | 2 +- src/dune_rules/mdx.ml | 2 + .../test-cases/mdx-stanza/env-variables.t | 59 +++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 test/blackbox-tests/test-cases/mdx-stanza/env-variables.t diff --git a/CHANGES.md b/CHANGES.md index 0740a43bc15..e560563b67d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -256,7 +256,7 @@ Unreleased - Introduce mdx stanza 0.2, requiring mdx >= 1.9.0, with a new generic `deps` field and the possibility to statically link `libraries` in the test - executable. (#3956, fixes #3955) + executable. (#3956, #5391, fixes #3955) - Improve lookup of optional or disabled binaries. Previously, we'd treat every executable with missing libraries as optional. Now, we treat make sure to diff --git a/Makefile b/Makefile index f5970d596ab..077c30b27c5 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ core_bench \ "csexp>=1.3.0" \ js_of_ocaml \ js_of_ocaml-compiler \ -mdx \ +"mdx>=2.1.0" \ menhir \ "merlin>=3.4.0" \ ocamlfind \ diff --git a/src/dune_rules/mdx.ml b/src/dune_rules/mdx.ml index 03ecc25f111..a2dc775e73f 100644 --- a/src/dune_rules/mdx.ml +++ b/src/dune_rules/mdx.ml @@ -258,6 +258,8 @@ let gen_rules_for_single_file stanza ~sctx ~dir ~expander ~mdx_prog Dep_conf_eval.unnamed ~expander (mdx_package_deps @ mdx_generic_deps) in Action_builder.with_no_targets deps + >>> Action_builder.with_no_targets + (Action_builder.env_var "MDX_RUN_NON_DETERMINISTIC") >>> Action_builder.with_no_targets (Action_builder.dyn_deps dyn_deps) >>> Command.run ~dir:(Path.build dir) ~stdout_to:files.corrected executable command_line diff --git a/test/blackbox-tests/test-cases/mdx-stanza/env-variables.t b/test/blackbox-tests/test-cases/mdx-stanza/env-variables.t new file mode 100644 index 00000000000..189cd65e912 --- /dev/null +++ b/test/blackbox-tests/test-cases/mdx-stanza/env-variables.t @@ -0,0 +1,59 @@ +Dune should know about the fact that mdx reads the MDX_RUN_NON_DETERMINISTIC +variable. When using the stanza 0.2, it is the mdx driver that reads that +variable. This is only the case since mdx 2.1.0. + + $ cat > dune-project << EOF + > (lang dune 3.0) + > (using mdx 0.2) + > EOF + + $ cat > dune << EOF + > (mdx (files README.md)) + > EOF + + $ cat > README.md << 'EOF' + > ```ocaml + > # "a";; + > ``` + > + > ```ocaml non-deterministic + > # "b";; + > ``` + > EOF + + $ dune runtest --auto-promote + File "README.md", line 1, characters 0-0: + Error: Files _build/default/README.md and + _build/default/.mdx/README.md.corrected differ. + Promoting _build/default/.mdx/README.md.corrected to README.md. + [1] + + $ cat README.md + ```ocaml + # "a";; + - : string = "a" + ``` + + ```ocaml non-deterministic + # "b";; + ``` + + $ dune runtest + + $ MDX_RUN_NON_DETERMINISTIC=1 dune runtest --auto-promote + File "README.md", line 1, characters 0-0: + Error: Files _build/default/README.md and + _build/default/.mdx/README.md.corrected differ. + Promoting _build/default/.mdx/README.md.corrected to README.md. + [1] + + $ cat README.md + ```ocaml + # "a";; + - : string = "a" + ``` + + ```ocaml non-deterministic + # "b";; + - : string = "b" + ```