ocamltest: introduce the action_name variable

This variable makes the name of the currently executed action available in
the ocamltest environment.
master
Sébastien Hinderer 2019-06-05 14:11:44 +02:00
parent 529b9132d8
commit 0912ecde6f
3 changed files with 10 additions and 0 deletions

View File

@ -21,14 +21,17 @@ ocamltest_stdlib_stubs.$(O): ocamltest_stdlib_stubs.c \
../runtime/caml/alloc.h ../runtime/caml/signals.h \ ../runtime/caml/alloc.h ../runtime/caml/signals.h \
../runtime/caml/osdeps.h ../runtime/caml/memory.h ../runtime/caml/osdeps.h ../runtime/caml/memory.h
actions.cmo : \ actions.cmo : \
variables.cmi \
result.cmi \ result.cmi \
environments.cmi \ environments.cmi \
actions.cmi actions.cmi
actions.cmx : \ actions.cmx : \
variables.cmx \
result.cmx \ result.cmx \
environments.cmx \ environments.cmx \
actions.cmi actions.cmi
actions.cmi : \ actions.cmi : \
variables.cmi \
result.cmi \ result.cmi \
environments.cmi environments.cmi
actions_helpers.cmo : \ actions_helpers.cmo : \

View File

@ -25,6 +25,8 @@ type t = {
let name a = a.name let name a = a.name
let action_name = Variables.make ("action_name", "Name of the current action")
let make n c = { name = n; body = c; hook = None } let make n c = { name = n; body = c; hook = None }
let update action code = { action with body = code } let update action code = { action with body = code }
@ -61,6 +63,7 @@ let run log env action =
let code = match action.hook with let code = match action.hook with
| None -> action.body | None -> action.body
| Some code -> code in | Some code -> code in
let env = Environments.add action_name action.name env in
code log env code log env
module ActionSet = Set.Make module ActionSet = Set.Make
@ -68,3 +71,5 @@ module ActionSet = Set.Make
type nonrec t = t type nonrec t = t
let compare = compare let compare = compare
end) end)
let _ = Variables.register_variable action_name

View File

@ -21,6 +21,8 @@ type t
val name : t -> string val name : t -> string
val action_name : Variables.t
val update : t -> code -> t val update : t -> code -> t
val make : string -> code -> t val make : string -> code -> t