Skip to content

Commit 5fa4ca0

Browse files
authored
test: incremental rebuild guard for vlib impl with private_modules (ocaml#14392)
## Summary Adds `test-cases/virtual-libraries/impl-private-modules-incremental.t`, a companion to the existing `impl-private-modules.t`. The existing test verifies the static artifact layout of an `(implements vlib) (private_modules ...)` library; the new test mutates the impl's private module's body and asserts that a rebuild succeeds and a downstream consumer continues to type-check. ## Coverage gap `impl-private-modules.t` and the other tests under `virtual-libraries/` that combine `implements` and `private_modules` (`impl-lib-interface-module.t`, `impl-public-modules/wrapped.t`, `private-module-shadowing-github1855.t`, `private-modules-overlapping-names.t`, `private-modules-public-impl-github10635.t`) all exercise initial-build behaviour only. None verifies that subsequent edits to the impl's private module are correctly propagated through the rebuild graph. A regression in dune's wiring of the impl's private-module compile rule into incremental rebuilds — for example, if the private module's regenerated artifacts were not picked up by the consumer's compile, or if the impl library's archive were not re-linked — would not be caught. --------- Signed-off-by: Robin Bate Boerop <me@robinbb.com>
1 parent a0c508e commit 5fa4ca0

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
Incremental-build regression guard for [(implements vlib)
2+
(private_modules ...)]. Companion to [impl-private-modules.t], which
3+
only checks the initial build's artifact layout. Here we exercise
4+
the incremental case: editing the impl's private module's body must
5+
not break the rebuild, and a downstream consumer that depends on the
6+
[impl] library must continue to type-check.
7+
8+
$ make_dune_project 3.24
9+
10+
[vlib] declares one virtual module [Bar]:
11+
12+
$ mkdir vlib
13+
$ cat > vlib/dune <<EOF
14+
> (library
15+
> (name vlib)
16+
> (virtual_modules bar))
17+
> EOF
18+
$ cat > vlib/bar.mli <<EOF
19+
> val v : int
20+
> EOF
21+
22+
[impl] implements [vlib] and adds a private module [Priv]; [bar.ml]
23+
references [Priv.helper]:
24+
25+
$ mkdir impl
26+
$ cat > impl/dune <<EOF
27+
> (library
28+
> (name impl)
29+
> (implements vlib)
30+
> (private_modules priv))
31+
> EOF
32+
$ cat > impl/bar.ml <<EOF
33+
> let v = Priv.helper
34+
> EOF
35+
$ cat > impl/priv.ml <<EOF
36+
> let helper = 1
37+
> EOF
38+
39+
[consumer] uses [Vlib]'s interface (which routes to [impl]'s [bar.ml]),
40+
and a small executable observes the value [Vlib.Bar.v] resolves to
41+
at runtime:
42+
43+
$ mkdir consumer
44+
$ cat > consumer/dune <<EOF
45+
> (library
46+
> (name consumer)
47+
> (modules c)
48+
> (libraries impl))
49+
> (executable
50+
> (name main)
51+
> (modules main)
52+
> (libraries impl))
53+
> EOF
54+
$ cat > consumer/c.ml <<EOF
55+
> let _ = Vlib.Bar.v
56+
> EOF
57+
$ cat > consumer/main.ml <<EOF
58+
> let () = print_int Vlib.Bar.v; print_newline ()
59+
> EOF
60+
61+
Initial build succeeds (consumer type-checks; executable links and
62+
observes the initial value of [Priv.helper]):
63+
64+
$ dune build @check
65+
$ dune build ./consumer/main.exe
66+
$ ./_build/default/consumer/main.exe
67+
1
68+
69+
Mutate [priv.ml]'s body. The rebuild must succeed: the consumer
70+
continues to type-check via [Vlib.Bar] (asserted by [@check]),
71+
[main.exe] must re-link against the new [Priv.helper] (asserted by
72+
its rebuild), and running the binary must now observe the updated
73+
value (asserted by the runtime output below):
74+
75+
$ cat > impl/priv.ml <<EOF
76+
> let helper = 2
77+
> EOF
78+
$ dune build @check
79+
$ dune build ./consumer/main.exe
80+
$ ./_build/default/consumer/main.exe
81+
2

0 commit comments

Comments
 (0)