From 1feab6b2a635a8c8b623e3c564a24c1cb951b6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Dimino?= Date: Fri, 9 Mar 2018 19:51:02 +0000 Subject: [PATCH] Allow to specify additional libraries for the test runner (#600) --- doc/tests.rst | 15 +++++++++++++++ src/inline_tests.ml | 25 +++++++++++++++++-------- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/doc/tests.rst b/doc/tests.rst index a91838ea..05269894 100644 --- a/doc/tests.rst +++ b/doc/tests.rst @@ -212,6 +212,21 @@ as: The argument of the ``flags`` field follows the :ref:`ordered-set-language`. +Using additional libraries in the test runner +--------------------------------------------- + +When tests are not part of the library code, it is possible that tests +require additional libraries than the library being tested. This is +the case with qtest_ as tests are written in comments. You can specify +such libraries using a ``libraries`` field, such as: + +.. code:: ocaml + + (library + ((name foo) + (inline_tests ((backend qtest) + (libraries (bar)))))) + Defining you own inline test backend ------------------------------------ diff --git a/src/inline_tests.ml b/src/inline_tests.ml index b313677b..e30fc315 100644 --- a/src/inline_tests.ml +++ b/src/inline_tests.ml @@ -111,19 +111,21 @@ include Sub_system.Register_end_point( let name = Sub_system_name.make "inline_tests" type t = - { loc : Loc.t - ; deps : Dep_conf.t list - ; flags : Ordered_set_lang.Unexpanded.t - ; backend : (Loc.t * string) option + { loc : Loc.t + ; deps : Dep_conf.t list + ; flags : Ordered_set_lang.Unexpanded.t + ; backend : (Loc.t * string) option + ; libraries : (Loc.t * string) list } type Jbuild.Sub_system_info.t += T of t let empty loc = { loc - ; deps = [] - ; flags = Ordered_set_lang.Unexpanded.standard - ; backend = None + ; deps = [] + ; flags = Ordered_set_lang.Unexpanded.standard + ; backend = None + ; libraries = [] } let loc t = t.loc @@ -138,11 +140,14 @@ include Sub_system.Register_end_point( field "deps" (list Dep_conf.t) ~default:[] >>= fun deps -> Ordered_set_lang.Unexpanded.field "flags" >>= fun flags -> field_o "backend" (located string) >>= fun backend -> + field "libraries" (list (located string)) ~default:[] + >>= fun libraries -> return { loc ; deps ; flags ; backend + ; libraries }) let parsers = @@ -198,7 +203,11 @@ include Sub_system.Register_end_point( >>= fun libs -> Lib.DB.find_many (Scope.libs scope) [lib.name] >>= fun lib -> - Ok (lib @ libs)) + Result.all + (List.map info.libraries + ~f:(Lib.DB.resolve (Scope.libs scope))) + >>= fun more_libs -> + Ok (lib @ libs @ more_libs)) |> Super_context.Libs.requires sctx ~dir ~has_dot_merlin:false in