-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test:
(modules_without_implementation)
expansion (#10280)
Signed-off-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>
- Loading branch information
1 parent
67d9830
commit f271143
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
test/blackbox-tests/test-cases/modules-without-implementation-expansion.t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
Test the ability of `(modules_without_implementation)` to contain dynamic | ||
forms such as `(:include)` and variables such as `"%{read-lines:}"`. | ||
|
||
$ cat >dune-project <<EOF | ||
> (lang dune 3.11) | ||
> EOF | ||
|
||
As we will see later in the test, it is imperative that build dependencies | ||
needed to evaluate the `(modules)` field not live in the same directory as the | ||
containing stanza. We will put them in a subdirectory: | ||
|
||
$ mkdir -p gen | ||
|
||
We define a rule that creates a file (in sexp syntax, to be passed to | ||
`(:include)`) containing a single name: | ||
|
||
$ cat >gen/dune <<EOF | ||
> (rule (with-stdout-to lst (echo mod))) | ||
> EOF | ||
|
||
The unit `mod.mli` is present in the working tree, `lib.ml` uses it: | ||
|
||
$ cat >mod.mli <<EOF | ||
> type t = | A | B | ||
> EOF | ||
|
||
$ cat >main.ml <<EOF | ||
> let f (x: Mod.t) = match x with A -> "a" | B -> "b" | ||
> let () = print_endline (f A) | ||
> EOF | ||
|
||
We declare a `library` where the list of modules_without_implementation is read | ||
from the (generated) | ||
|
||
file `gen/lst`: | ||
|
||
$ cat >dune <<EOF | ||
> (executable | ||
> (name main) | ||
> (modes byte) | ||
> (modules main (:include gen/lst)) | ||
> (modules_without_implementation (:include gen/lst))) | ||
> EOF | ||
|
||
Let's check that it fails in the current version of Dune: | ||
|
||
$ dune exec ./main.exe | ||
File "dune", line 5, characters 1-52: | ||
5 | (modules_without_implementation (:include gen/lst))) | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
Error: the ability to specify non-constant module lists is only available | ||
since version 3.13 of the dune language. Please update your dune-project file | ||
to have (lang dune 3.13). | ||
[1] | ||
|
||
Update the version... | ||
|
||
$ cat >dune-project <<EOF | ||
> (lang dune 3.13) | ||
> EOF | ||
|
||
... and it works! | ||
|
||
$ dune exec ./main.exe | ||
a | ||
|
||
Let's do some examples using libraries: | ||
|
||
$ cat >dune <<EOF | ||
> (library | ||
> (name lib) | ||
> (modes byte) | ||
> (modules (:include gen/lst)) | ||
> (modules_without_implementation (:include gen/lst))) | ||
> EOF | ||
$ dune build lib.cma | ||
|
||
We can also use special forms such as `%{read-lines:}`: | ||
|
||
$ cat >dune <<EOF | ||
> (library | ||
> (name lib) | ||
> (modes byte) | ||
> (modules %{read-lines:gen/lst}) | ||
> (modules_without_implementation %{read-lines:gen/lst})) | ||
> EOF | ||
|