dune/test/unit-tests/tests.mlt

119 lines
2.4 KiB
Plaintext
Raw Normal View History

2017-03-29 16:12:18 +00:00
(* -*- tuareg -*- *)
#warnings "-40";;
open Dune
open Import
2017-03-29 16:12:18 +00:00
let () =
Path.set_root (Path.External.cwd ());
Path.set_build_dir (Path.Kind.of_string "_build")
;;
2017-03-29 16:12:18 +00:00
let print_pkg ppf pkg =
2018-02-07 17:51:40 +00:00
Format.fprintf ppf "<package:%s>" (Findlib.Package.name pkg)
2017-03-29 16:12:18 +00:00
;;
#install_printer print_pkg;;
#install_printer String_map.pp;;
2017-03-29 16:12:18 +00:00
[%%expect{|
val print_pkg : Format.formatter -> Findlib.Package.t -> unit = <fun>
2017-03-29 16:12:18 +00:00
|}]
let findlib =
let cwd = Path.of_filename_relative_to_initial_cwd (Sys.getcwd ()) in
2017-03-29 16:12:18 +00:00
Findlib.create
~stdlib_dir:cwd
~path:[Path.relative cwd "test/unit-tests/findlib-db"]
2017-03-29 16:12:18 +00:00
;;
[%%expect{|
val findlib : Findlib.t = <abstr>
2017-03-29 16:12:18 +00:00
|}]
Refactor library management (#516) Lib module ---------- We have a new module Lib that replaces Lib, parts of Lib_db and parts of Findlib. It is used to manage all libraries (internal and extrernal). Lib.t represent a completely resolved library, i.e. where all the dependencies have been resolved. Lib.Compile is used to provide what is necessary to build the library itself. Lib.Meta provides what is necessary to generate the META file for the library. We also have library databases represented as Lib.DB.t. A library database is simply a mapping from names to Lib.t values and and created from a resolve function that looks up a name and return a Lib.Info.t. A Lib.Info.t is the same as a Lib.t except that dependencies are not resolved. A library database can have a parent database that is used to lookup names that are not found in the current database. In practice we have the following hierarchy: 1. For every scope, we have a library database that holds all the libraries of this scope. In this DB, a library can be referred by either it's name or public name 2. the parent of each of these databases is a database that holds all the public libraries of the workspace. In this DB libraries must be referred by their public name 3. the parent of this DB is for installed libraries (1) databases are accessible via Scope.libs (Super_context.find_scope_by_{name,dir} sctx xxx) (2) is accessible via Super_context.public_libs sctx (3) is accessible via Super_context.installed_libs sctx The dependencies of a library are always resolved inside the DB it is part of. When we compute a transitive closure, we check that we don't have two libraries from two different DB with the same name. So for instance linting Base should now supported. Jbuild.Scope_info ----------------- Jbuild.Scope was renamed Jbuild.Scope_info Scope module ------------ This replaces Lib_db. A Scope.t is now just a pair of a Jbuild.Scope_info.t and a Lib.DB.t. Scope.DB.t is an object used to lookup scopes by either name or directory. We no longer have an external scope or special anonymous scope. Instead one should use Super_context.installed_libs or Super_context.public_libs depending on the context.
2018-02-20 11:46:10 +00:00
let pkg =
match Findlib.find findlib "foo" with
| Ok x -> x
| Error _ -> assert false;;
2017-03-29 16:12:18 +00:00
[%%expect{|
val pkg : Findlib.Package.t = <package:foo>
2017-03-29 16:12:18 +00:00
|}]
(* "foo" should depend on "baz" *)
Refactor library management (#516) Lib module ---------- We have a new module Lib that replaces Lib, parts of Lib_db and parts of Findlib. It is used to manage all libraries (internal and extrernal). Lib.t represent a completely resolved library, i.e. where all the dependencies have been resolved. Lib.Compile is used to provide what is necessary to build the library itself. Lib.Meta provides what is necessary to generate the META file for the library. We also have library databases represented as Lib.DB.t. A library database is simply a mapping from names to Lib.t values and and created from a resolve function that looks up a name and return a Lib.Info.t. A Lib.Info.t is the same as a Lib.t except that dependencies are not resolved. A library database can have a parent database that is used to lookup names that are not found in the current database. In practice we have the following hierarchy: 1. For every scope, we have a library database that holds all the libraries of this scope. In this DB, a library can be referred by either it's name or public name 2. the parent of each of these databases is a database that holds all the public libraries of the workspace. In this DB libraries must be referred by their public name 3. the parent of this DB is for installed libraries (1) databases are accessible via Scope.libs (Super_context.find_scope_by_{name,dir} sctx xxx) (2) is accessible via Super_context.public_libs sctx (3) is accessible via Super_context.installed_libs sctx The dependencies of a library are always resolved inside the DB it is part of. When we compute a transitive closure, we check that we don't have two libraries from two different DB with the same name. So for instance linting Base should now supported. Jbuild.Scope_info ----------------- Jbuild.Scope was renamed Jbuild.Scope_info Scope module ------------ This replaces Lib_db. A Scope.t is now just a pair of a Jbuild.Scope_info.t and a Lib.DB.t. Scope.DB.t is an object used to lookup scopes by either name or directory. We no longer have an external scope or special anonymous scope. Instead one should use Super_context.installed_libs or Super_context.public_libs depending on the context.
2018-02-20 11:46:10 +00:00
Findlib.Package.requires pkg;;
2017-03-29 16:12:18 +00:00
[%%expect{|
Refactor library management (#516) Lib module ---------- We have a new module Lib that replaces Lib, parts of Lib_db and parts of Findlib. It is used to manage all libraries (internal and extrernal). Lib.t represent a completely resolved library, i.e. where all the dependencies have been resolved. Lib.Compile is used to provide what is necessary to build the library itself. Lib.Meta provides what is necessary to generate the META file for the library. We also have library databases represented as Lib.DB.t. A library database is simply a mapping from names to Lib.t values and and created from a resolve function that looks up a name and return a Lib.Info.t. A Lib.Info.t is the same as a Lib.t except that dependencies are not resolved. A library database can have a parent database that is used to lookup names that are not found in the current database. In practice we have the following hierarchy: 1. For every scope, we have a library database that holds all the libraries of this scope. In this DB, a library can be referred by either it's name or public name 2. the parent of each of these databases is a database that holds all the public libraries of the workspace. In this DB libraries must be referred by their public name 3. the parent of this DB is for installed libraries (1) databases are accessible via Scope.libs (Super_context.find_scope_by_{name,dir} sctx xxx) (2) is accessible via Super_context.public_libs sctx (3) is accessible via Super_context.installed_libs sctx The dependencies of a library are always resolved inside the DB it is part of. When we compute a transitive closure, we check that we don't have two libraries from two different DB with the same name. So for instance linting Base should now supported. Jbuild.Scope_info ----------------- Jbuild.Scope was renamed Jbuild.Scope_info Scope module ------------ This replaces Lib_db. A Scope.t is now just a pair of a Jbuild.Scope_info.t and a Lib.DB.t. Scope.DB.t is an object used to lookup scopes by either name or directory. We no longer have an external scope or special anonymous scope. Instead one should use Super_context.installed_libs or Super_context.public_libs depending on the context.
2018-02-20 11:46:10 +00:00
- : string list = ["baz"]
|}]
(* +-----------------------------------------------------------------+
| Meta parsing/simplification |
+-----------------------------------------------------------------+ *)
open Meta
#install_printer Simplified.pp;;
let meta =
Path.in_source "test/unit-tests/findlib-db/foo/META"
2018-04-24 20:25:27 +00:00
|> Meta.load ~name:"foo"
[%%expect{|
val meta : Simplified.t =
{ name = "foo"
; vars =
(requires =
{ set_rules =
[ { var = "requires"
; predicates = []
; action = Set
; value = "bar"
}
; { var = "requires"
; predicates = [ "+ppx_driver" ]
; action = Set
; value = "baz"
}
]
; add_rules = []
})
; subs = []
}
2017-03-29 16:12:18 +00:00
|}]
#install_printer Findlib.Config.pp;;
let conf =
Findlib.Config.load (Path.in_source "test/unit-tests/toolchain")
~toolchain:"tlc" ~context:"<context>"
[%%expect{|
val conf : Findlib.Config.t =
{ vars =
[ (FOO_BAR, { set_rules =
[ { preds_required = [ "tlc"; "env" ]
; preds_forbidden = []
; value = "my variable"
}
]
; add_rules = []
})
]
; preds = [ "tlc" ]
}
|}]
let env_pp fmt env = Sexp.pp Dune fmt (Env.sexp_of_t env);;
#install_printer env_pp;;
[%%expect{|
val env_pp : Format.formatter -> Env.t -> unit = <fun>
|}]
let env = Findlib.Config.env conf
[%%expect{|
val env : Env.t = ((FOO_BAR "my variable"))
|}]