Skip to content

Commit

Permalink
Adds a new 'instrumentation' setting in env stanza
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Lasson <[email protected]>
  • Loading branch information
mlasson committed Jul 19, 2019
1 parent 4b63343 commit 6b731d1
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
- Do not put the `<package>.install` files in the source tree unless
`-p` or `--promote-install-files` is passed on the command line (#..., @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)


1.11.0 (unreleased)
-------------------

Expand Down
5 changes: 5 additions & 0 deletions doc/dune-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,11 @@ Fields supported in ``<settings>`` are:
be inferred from the basename of ``<filepath>`` by dropping the ``.exe``
suffix if it exists.

- ``(inline-tests <state>)`` 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)
Expand Down
28 changes: 28 additions & 0 deletions src/dune_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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"
Expand All @@ -48,11 +74,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 =
Expand Down
11 changes: 11 additions & 0 deletions src/dune_env.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
20 changes: 19 additions & 1 deletion src/env_node.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 =
Expand Down Expand Up @@ -121,6 +123,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
Expand Down
2 changes: 2 additions & 0 deletions src/env_node.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion src/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,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
Expand All @@ -174,7 +178,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)
Expand Down
4 changes: 3 additions & 1 deletion test/blackbox-tests/test-cases/inline_tests/run.t
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/inline_tests/simple/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6b731d1

Please sign in to comment.