From c05dbdfce76e5292a5d0712f8623ec3ceff9a082 Mon Sep 17 00:00:00 2001 From: Marc Lasson Date: Tue, 25 Jun 2019 11:22:12 +0200 Subject: [PATCH 1/7] Adds a new 'instrumentation' setting in env stanza Signed-off-by: Marc Lasson --- CHANGES.md | 3 ++ doc/dune-files.rst | 5 ++++ src/dune_env.ml | 28 +++++++++++++++++++ src/dune_env.mli | 11 ++++++++ src/env_node.ml | 20 ++++++++++++- src/env_node.mli | 2 ++ src/super_context.ml | 15 +++++++++- .../test-cases/inline_tests/run.t | 4 ++- .../test-cases/inline_tests/simple/dune | 2 +- 9 files changed, 86 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1dda534b6f8..2d3f851868d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,9 @@ - Do not put the `.install` files in the source tree unless `-p` or `--promote-install-files` is passed on the command line (#2329, @diml) +- Add a new `inline-tests` field in the env stanza to control inline-tests + framework with a variable (#2313, @mlasson review and original idea by @diml) + - Change `implicit_transive_deps` to be false. Implicit transitive deps now must be manually enabled (#2306, @rgrinberg) diff --git a/doc/dune-files.rst b/doc/dune-files.rst index 4a4be480b02..5fa85aafee4 100644 --- a/doc/dune-files.rst +++ b/doc/dune-files.rst @@ -814,6 +814,11 @@ Fields supported in ```` are: be inferred from the basename of ```` by dropping the ``.exe`` suffix if it exists. +- ``(inline-tests )`` where state is either ``enabled``, ``disabled`` or + ``ignored``. This field controls the value of the variable ``%{inline-tests}`` + that is read by the inline test framework. The default value is ``disabled`` + for the ``release`` profile and ``enabled`` otherwise. + .. _dune-subdirs: dirs (since 1.6) diff --git a/src/dune_env.ml b/src/dune_env.ml index 705a4bad453..1758f71f4ca 100644 --- a/src/dune_env.ml +++ b/src/dune_env.ml @@ -14,11 +14,31 @@ module Stanza = struct in C.Kind.Dict.make ~c ~cxx + module Inline_tests = struct + type t = + | Enabled + | Disabled + | Ignored + + let decode = + enum + [ "enabled", Enabled + ; "disabled", Disabled + ; "ignored", Ignored ] + + let to_string = function + | Enabled -> "enabled" + | Disabled -> "disabled" + | Ignored -> "ignored" + + end + type config = { flags : Ocaml_flags.Spec.t ; c_flags : Ordered_set_lang.Unexpanded.t C.Kind.Dict.t ; env_vars : Env.t ; binaries : File_binding.Unexpanded.t list + ; inline_tests : Inline_tests.t option } type pattern = @@ -30,6 +50,12 @@ module Stanza = struct ; rules : (pattern * config) list } + let inline_tests_field = + field_o + "inline-tests" + (Syntax.since Stanza.syntax (1, 11) >>> + Inline_tests.decode) + let env_vars_field = field "env-vars" @@ -49,11 +75,13 @@ module Stanza = struct and+ binaries = field ~default:[] "binaries" (Syntax.since Stanza.syntax (1, 6) >>> File_binding.Unexpanded.L.decode) + and+ inline_tests = inline_tests_field in { flags ; c_flags ; env_vars ; binaries + ; inline_tests } let rule = diff --git a/src/dune_env.mli b/src/dune_env.mli index 558d7ff3e6d..5a33aeef173 100644 --- a/src/dune_env.mli +++ b/src/dune_env.mli @@ -3,11 +3,22 @@ open! Stdune type stanza = Stanza.t = .. module Stanza : sig + + module Inline_tests: sig + type t = + | Enabled + | Disabled + | Ignored + val decode: t Dune_lang.Decoder.t + val to_string: t -> string + end + type config = { flags : Ocaml_flags.Spec.t ; c_flags : Ordered_set_lang.Unexpanded.t C.Kind.Dict.t ; env_vars : Env.t ; binaries : File_binding.Unexpanded.t list + ; inline_tests : Inline_tests.t option } type pattern = diff --git a/src/env_node.ml b/src/env_node.ml index dafb3236769..2dbb5282673 100644 --- a/src/env_node.ml +++ b/src/env_node.ml @@ -9,7 +9,8 @@ type t = ; mutable ocaml_flags : Ocaml_flags.t option ; mutable c_flags : (unit, string list) Build.t C.Kind.Dict.t option ; mutable external_ : Env.t option - ; mutable bin_artifacts : Artifacts.Bin.t option + ; mutable bin_artifacts : Artifacts.Bin.t option + ; mutable inline_tests : Dune_env.Stanza.Inline_tests.t option; } let scope t = t.scope @@ -24,6 +25,7 @@ let make ~dir ~inherit_from ~scope ~config = ; external_ = None ; bin_artifacts = None ; local_binaries = None + ; inline_tests = None } let find_config t ~profile = @@ -123,6 +125,22 @@ let rec ocaml_flags t ~profile ~expander = t.ocaml_flags <- Some flags; flags +let inline_tests t ~profile = + match t.inline_tests with + | Some x -> x + | None -> + let state : Dune_env.Stanza.Inline_tests.t = + match find_config t ~profile with + | None | Some {inline_tests = None; _} -> + if profile = "release" then + Disabled + else + Enabled + | Some {inline_tests = Some s; _} -> s + in + t.inline_tests <- Some state; + state + let rec c_flags t ~profile ~expander ~default_context_flags = match t.c_flags with | Some x -> x diff --git a/src/env_node.mli b/src/env_node.mli index 9da9d480f2d..e8c1eb98afd 100644 --- a/src/env_node.mli +++ b/src/env_node.mli @@ -18,6 +18,8 @@ val external_ : t -> profile:string -> default:Env.t -> Env.t val ocaml_flags : t -> profile:string -> expander:Expander.t -> Ocaml_flags.t +val inline_tests : t -> profile:string -> Dune_env.Stanza.Inline_tests.t + val c_flags : t -> profile:string diff --git a/src/super_context.ml b/src/super_context.ml index 4bbe7200311..3b376716442 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -153,6 +153,10 @@ end = struct in Env_node.local_binaries node ~profile:t.profile ~expander + let inline_tests ({profile; _} as t) ~dir = + let node = get t ~dir in + Env_node.inline_tests node ~profile + let bin_artifacts t ~dir = let expander = expander_for_artifacts t ~context_expander:t.expander ~dir @@ -177,7 +181,16 @@ end = struct expander_for_artifacts t ~context_expander:t.expander ~dir in let bin_artifacts_host = bin_artifacts_host t ~dir in - Expander.set_bin_artifacts expander ~bin_artifacts_host + let bindings = + let str = + inline_tests t ~dir + |> Dune_env.Stanza.Inline_tests.to_string + in + Pform.Map.singleton "inline-tests" (Values [String str]) + in + expander + |> Expander.add_bindings ~bindings + |> Expander.set_bin_artifacts ~bin_artifacts_host let ocaml_flags t ~dir = Env_node.ocaml_flags (get t ~dir) diff --git a/test/blackbox-tests/test-cases/inline_tests/run.t b/test/blackbox-tests/test-cases/inline_tests/run.t index 8ce063764d3..b195bb48c07 100644 --- a/test/blackbox-tests/test-cases/inline_tests/run.t +++ b/test/blackbox-tests/test-cases/inline_tests/run.t @@ -1,9 +1,11 @@ $ env -u OCAMLRUNPARAM dune runtest simple run alias simple/runtest (exit 2) (cd _build/default/simple && .foo_simple.inline-tests/run.exe) - Fatal error: exception File "simple/.foo_simple.inline-tests/run.ml-gen", line 1, characters 10-16: Assertion failed + Fatal error: exception File "simple/.foo_simple.inline-tests/run.ml-gen", line 1, characters 40-46: Assertion failed [1] + $ env -u OCAMLRUNPARAM dune runtest simple --profile release + $ dune runtest missing-backend File "missing-backend/dune", line 3, characters 1-15: 3 | (inline_tests)) diff --git a/test/blackbox-tests/test-cases/inline_tests/simple/dune b/test/blackbox-tests/test-cases/inline_tests/simple/dune index 8e2f4f99236..0a1b293f529 100644 --- a/test/blackbox-tests/test-cases/inline_tests/simple/dune +++ b/test/blackbox-tests/test-cases/inline_tests/simple/dune @@ -2,7 +2,7 @@ (name backend_simple) (modules ()) (inline_tests.backend - (generate_runner (run sed "s/(\\*TEST:\\(.*\\)\\*)/let () = \\1;;/" %{impl-files}) + (generate_runner (run sed "s/(\\*TEST:\\(.*\\)\\*)/let () = if \"%{inline-tests}\" = \"enabled\" then \\1;;/" %{impl-files}) ))) (library From c9c0e7c772e6fe1cac88b7c1c7c22f1817058537 Mon Sep 17 00:00:00 2001 From: Marc Lasson Date: Mon, 22 Jul 2019 10:18:23 +0200 Subject: [PATCH 2/7] Default to the parent node Signed-off-by: Marc Lasson --- src/env_node.ml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/env_node.ml b/src/env_node.ml index 2dbb5282673..ca455e28d84 100644 --- a/src/env_node.ml +++ b/src/env_node.ml @@ -125,17 +125,21 @@ let rec ocaml_flags t ~profile ~expander = t.ocaml_flags <- Some flags; flags -let inline_tests t ~profile = +let rec inline_tests t ~profile = match t.inline_tests with | Some x -> x | None -> let state : Dune_env.Stanza.Inline_tests.t = match find_config t ~profile with | None | Some {inline_tests = None; _} -> - if profile = "release" then - Disabled - else - Enabled + begin match t.inherit_from with + | None -> + if profile = "release" then + Disabled + else + Enabled + | Some (lazy t) -> inline_tests t ~profile + end | Some {inline_tests = Some s; _} -> s in t.inline_tests <- Some state; From ab71f06917487232518a0343873c831a4447fba2 Mon Sep 17 00:00:00 2001 From: Marc Lasson Date: Mon, 22 Jul 2019 11:03:19 +0200 Subject: [PATCH 3/7] Rename iniline-tests -> inline_tests Signed-off-by: Marc Lasson --- CHANGES.md | 2 +- doc/dune-files.rst | 4 ++-- src/dune_env.ml | 2 +- src/super_context.ml | 2 +- test/blackbox-tests/test-cases/inline_tests/simple/dune | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 2d3f851868d..5d4f6dd8678 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,7 +8,7 @@ - Do not put the `.install` files in the source tree unless `-p` or `--promote-install-files` is passed on the command line (#2329, @diml) -- Add a new `inline-tests` field in the env stanza to control inline-tests +- Add a new `inline_tests` field in the env stanza to control inline_tests framework with a variable (#2313, @mlasson review and original idea by @diml) - Change `implicit_transive_deps` to be false. Implicit transitive deps now must diff --git a/doc/dune-files.rst b/doc/dune-files.rst index 5fa85aafee4..0057b33d1f3 100644 --- a/doc/dune-files.rst +++ b/doc/dune-files.rst @@ -814,8 +814,8 @@ Fields supported in ```` are: be inferred from the basename of ```` by dropping the ``.exe`` suffix if it exists. -- ``(inline-tests )`` where state is either ``enabled``, ``disabled`` or - ``ignored``. This field controls the value of the variable ``%{inline-tests}`` +- ``(inline_tests )`` where state is either ``enabled``, ``disabled`` or + ``ignored``. This field controls the value of the variable ``%{inline_tests}`` that is read by the inline test framework. The default value is ``disabled`` for the ``release`` profile and ``enabled`` otherwise. diff --git a/src/dune_env.ml b/src/dune_env.ml index 1758f71f4ca..6dcc8df4e21 100644 --- a/src/dune_env.ml +++ b/src/dune_env.ml @@ -52,7 +52,7 @@ module Stanza = struct let inline_tests_field = field_o - "inline-tests" + "inline_tests" (Syntax.since Stanza.syntax (1, 11) >>> Inline_tests.decode) diff --git a/src/super_context.ml b/src/super_context.ml index 3b376716442..02a3da42336 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -186,7 +186,7 @@ end = struct inline_tests t ~dir |> Dune_env.Stanza.Inline_tests.to_string in - Pform.Map.singleton "inline-tests" (Values [String str]) + Pform.Map.singleton "inline_tests" (Values [String str]) in expander |> Expander.add_bindings ~bindings diff --git a/test/blackbox-tests/test-cases/inline_tests/simple/dune b/test/blackbox-tests/test-cases/inline_tests/simple/dune index 0a1b293f529..bd1aa94dee0 100644 --- a/test/blackbox-tests/test-cases/inline_tests/simple/dune +++ b/test/blackbox-tests/test-cases/inline_tests/simple/dune @@ -2,7 +2,7 @@ (name backend_simple) (modules ()) (inline_tests.backend - (generate_runner (run sed "s/(\\*TEST:\\(.*\\)\\*)/let () = if \"%{inline-tests}\" = \"enabled\" then \\1;;/" %{impl-files}) + (generate_runner (run sed "s/(\\*TEST:\\(.*\\)\\*)/let () = if \"%{inline_tests}\" = \"enabled\" then \\1;;/" %{impl-files}) ))) (library From 8010f8151185f435c8b80d54ef053ee1cc6bf790 Mon Sep 17 00:00:00 2001 From: Marc Lasson Date: Mon, 22 Jul 2019 11:11:34 +0200 Subject: [PATCH 4/7] inline_tests field in env since 1.11 Signed-off-by: Marc Lasson --- CHANGES.md | 7 ++++--- doc/dune-files.rst | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 5d4f6dd8678..44b8de4c6ac 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,9 +8,6 @@ - Do not put the `.install` files in the source tree unless `-p` or `--promote-install-files` is passed on the command line (#2329, @diml) -- Add a new `inline_tests` field in the env stanza to control inline_tests - framework with a variable (#2313, @mlasson review and original idea by @diml) - - Change `implicit_transive_deps` to be false. Implicit transitive deps now must be manually enabled (#2306, @rgrinberg) @@ -107,6 +104,10 @@ - Do not warn about merlin files pre 1.9. This warning can only be disabled in 1.9 (#2421, fixes #2399, @emillon) +- Add a new `inline_tests` field in the env stanza to control inline_tests + framework with a variable (#2313, @mlasson, original idea by @diml, revinw + by @rgrinberg). + 1.10.0 (04/06/2019) ------------------- diff --git a/doc/dune-files.rst b/doc/dune-files.rst index 0057b33d1f3..b416eb5b11d 100644 --- a/doc/dune-files.rst +++ b/doc/dune-files.rst @@ -815,9 +815,10 @@ Fields supported in ```` are: suffix if it exists. - ``(inline_tests )`` where state is either ``enabled``, ``disabled`` or - ``ignored``. This field controls the value of the variable ``%{inline_tests}`` - that is read by the inline test framework. The default value is ``disabled`` - for the ``release`` profile and ``enabled`` otherwise. + ``ignored``. This field is available since Dune 1.11. It controls the value + of the variable ``%{inline_tests}`` that is read by the inline test framework. + The default value is ``disabled`` for the ``release`` profile and ``enabled`` + otherwise. .. _dune-subdirs: From 87f5816bfbb599aeabaafe2d971d477129203246 Mon Sep 17 00:00:00 2001 From: Marc Lasson Date: Mon, 22 Jul 2019 11:15:06 +0200 Subject: [PATCH 5/7] Typo Signed-off-by: Marc Lasson --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 44b8de4c6ac..dd28336b1bf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -105,7 +105,7 @@ 1.9 (#2421, fixes #2399, @emillon) - Add a new `inline_tests` field in the env stanza to control inline_tests - framework with a variable (#2313, @mlasson, original idea by @diml, revinw + framework with a variable (#2313, @mlasson, original idea by @diml, review by @rgrinberg). 1.10.0 (04/06/2019) From 3dbe5f13b9bbb90bb1152092896ce86be5c11b64 Mon Sep 17 00:00:00 2001 From: Marc Lasson Date: Mon, 22 Jul 2019 11:58:42 +0200 Subject: [PATCH 6/7] Adds a few tests Signed-off-by: Marc Lasson --- .../test-cases/inline_tests/dune-project | 2 +- test/blackbox-tests/test-cases/inline_tests/run.t | 10 ++++++++++ .../blackbox-tests/test-cases/inline_tests/simple/dune | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/test/blackbox-tests/test-cases/inline_tests/dune-project b/test/blackbox-tests/test-cases/inline_tests/dune-project index de4fc209200..0636ab6acf4 100644 --- a/test/blackbox-tests/test-cases/inline_tests/dune-project +++ b/test/blackbox-tests/test-cases/inline_tests/dune-project @@ -1 +1 @@ -(lang dune 1.0) +(lang dune 1.11) diff --git a/test/blackbox-tests/test-cases/inline_tests/run.t b/test/blackbox-tests/test-cases/inline_tests/run.t index b195bb48c07..712f522eeac 100644 --- a/test/blackbox-tests/test-cases/inline_tests/run.t +++ b/test/blackbox-tests/test-cases/inline_tests/run.t @@ -6,6 +6,16 @@ $ env -u OCAMLRUNPARAM dune runtest simple --profile release + $ env -u OCAMLRUNPARAM dune runtest simple --profile disable-inline-tests + + $ env -u OCAMLRUNPARAM dune runtest simple --profile ignore-inline-tests + + $ env -u OCAMLRUNPARAM dune runtest simple --profile enable-inline-tests + run alias simple/runtest (exit 2) + (cd _build/default/simple && .foo_simple.inline-tests/run.exe) + Fatal error: exception File "simple/.foo_simple.inline-tests/run.ml-gen", line 1, characters 40-46: Assertion failed + [1] + $ dune runtest missing-backend File "missing-backend/dune", line 3, characters 1-15: 3 | (inline_tests)) diff --git a/test/blackbox-tests/test-cases/inline_tests/simple/dune b/test/blackbox-tests/test-cases/inline_tests/simple/dune index bd1aa94dee0..e823a7f85b6 100644 --- a/test/blackbox-tests/test-cases/inline_tests/simple/dune +++ b/test/blackbox-tests/test-cases/inline_tests/simple/dune @@ -8,3 +8,7 @@ (library (name foo_simple) (inline_tests (backend backend_simple))) + +(env (ignore-inline-tests (inline_tests ignored)) + (enable-inline-tests (inline_tests enabled)) + (disable-inline-tests (inline_tests disabled))) From 05f9a9e21c8398042334a6a8f92f260694b3c9de Mon Sep 17 00:00:00 2001 From: Marc Lasson Date: Mon, 22 Jul 2019 14:21:50 +0200 Subject: [PATCH 7/7] Adds a comment to explain why no output Signed-off-by: Marc Lasson --- test/blackbox-tests/test-cases/inline_tests/run.t | 1 + 1 file changed, 1 insertion(+) diff --git a/test/blackbox-tests/test-cases/inline_tests/run.t b/test/blackbox-tests/test-cases/inline_tests/run.t index 712f522eeac..79b1be5f41d 100644 --- a/test/blackbox-tests/test-cases/inline_tests/run.t +++ b/test/blackbox-tests/test-cases/inline_tests/run.t @@ -4,6 +4,7 @@ Fatal error: exception File "simple/.foo_simple.inline-tests/run.ml-gen", line 1, characters 40-46: Assertion failed [1] +The expected behavior for the following three tests is to output nothing: the tests are disabled or ignored. $ env -u OCAMLRUNPARAM dune runtest simple --profile release $ env -u OCAMLRUNPARAM dune runtest simple --profile disable-inline-tests