Allow to specify additional libraries for the test runner (#600)

This commit is contained in:
Jérémie Dimino 2018-03-09 19:51:02 +00:00 committed by GitHub
parent b604871aab
commit 1feab6b2a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 8 deletions

View File

@ -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
------------------------------------

View File

@ -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