Monorepo management for opam overlays
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

monopam: add lint tests for fuzz and with-test scopes

Two more cases for the private-stanza attribution rule:

- A fuzz/ private executable referencing alcobar: lint must flag it
(alcobar must be declared in opam, even as {with-test} or build).
This matches the original publicsuffix-style bug semantics — any
library referenced from any dune stanza must appear in opam depends.

- A fuzz/ private executable referencing alcobar with alcobar declared
as {with-test}: lint must NOT flag it. The opam scope is irrelevant
for "missing"; only "is the package named anywhere in depends" is
checked.

Both pass with the existing single-package fallback. The earlier draft
that tried to skip fuzz/ stanzas was wrong: alcobar in cookie's fuzz
without alcobar in cookie.opam IS a real missing dep, not a false
positive.

+58 -11
+58 -11
test/test_lint.ml
··· 84 84 in 85 85 f result) 86 86 87 + let issue_for ~subtree ~package (i : Monopam.Lint.issue) = 88 + i.subtree = subtree && i.kind = Monopam.Lint.Missing && i.package = package 89 + 87 90 (** A subtree whose only opam package is [test-pkg]. The library proper has no 88 91 extra deps, but a sibling private [(executable)] in [gen/] uses [re]. 89 - Since [re] is not in [test-pkg.opam], a [dune build -p test-pkg @install] 90 - would fail to compile [gen.exe] — and the lint should flag it. *) 92 + Since [re] is not in [test-pkg.opam], the lint should flag it. *) 91 93 let test_missing_dep_via_private_executable () = 92 94 with_temp_monorepo 93 95 (fun ~mkdir ~write -> ··· 101 103 write "test-pkg/gen/dune" 102 104 "(executable\n (name gen)\n (libraries re))\n") 103 105 (fun (result : Monopam.Lint.result) -> 104 - let re_missing = 105 - List.exists 106 - (fun (i : Monopam.Lint.issue) -> 107 - i.subtree = "test-pkg" 108 - && i.kind = Monopam.Lint.Missing 109 - && i.package = "re") 110 - result.issues 111 - in 112 106 Alcotest.(check bool) 113 107 "private executable's library deps are attributed to the subtree's \ 114 108 single opam package" 115 - true re_missing) 109 + true 110 + (List.exists (issue_for ~subtree:"test-pkg" ~package:"re") 111 + result.issues)) 112 + 113 + (** A private executable in [fuzz/] still references a library, and that 114 + library still needs to be declared somewhere in opam (with-test, build, 115 + or runtime). The lint must flag it like any other missing dep. *) 116 + let test_missing_dep_via_fuzz_executable () = 117 + with_temp_monorepo 118 + (fun ~mkdir ~write -> 119 + mkdir "test-pkg"; 120 + mkdir "test-pkg/lib"; 121 + mkdir "test-pkg/fuzz"; 122 + write "test-pkg/test-pkg.opam" 123 + "opam-version: \"2.0\"\ndepends: [ \"dune\" {>= \"3.21\"} ]\n"; 124 + write "test-pkg/lib/dune" 125 + "(library\n (name test_pkg)\n (public_name test-pkg))\n"; 126 + write "test-pkg/fuzz/dune" 127 + "(executable\n (name fuzz)\n (libraries alcobar))\n") 128 + (fun (result : Monopam.Lint.result) -> 129 + Alcotest.(check bool) 130 + "fuzz exec's libs are flagged when missing from opam" 131 + true 132 + (List.exists (issue_for ~subtree:"test-pkg" ~package:"alcobar") 133 + result.issues)) 134 + 135 + (** When a library referenced from any private stanza IS declared in opam 136 + (even as [{with-test}]), the lint must NOT flag it. *) 137 + let test_with_test_dep_not_flagged () = 138 + with_temp_monorepo 139 + (fun ~mkdir ~write -> 140 + mkdir "test-pkg"; 141 + mkdir "test-pkg/lib"; 142 + mkdir "test-pkg/fuzz"; 143 + write "test-pkg/test-pkg.opam" 144 + "opam-version: \"2.0\"\n\ 145 + depends: [\n\ 146 + \ \"dune\" {>= \"3.21\"}\n\ 147 + \ \"alcobar\" {with-test}\n\ 148 + ]\n"; 149 + write "test-pkg/lib/dune" 150 + "(library\n (name test_pkg)\n (public_name test-pkg))\n"; 151 + write "test-pkg/fuzz/dune" 152 + "(executable\n (name fuzz)\n (libraries alcobar))\n") 153 + (fun (result : Monopam.Lint.result) -> 154 + Alcotest.(check bool) 155 + "with-test dep declared in opam is not flagged as missing" 156 + false 157 + (List.exists (issue_for ~subtree:"test-pkg" ~package:"alcobar") 158 + result.issues)) 116 159 117 160 let suite = 118 161 ( "lint", ··· 124 167 Alcotest.test_case "run type" `Quick test_run_type; 125 168 Alcotest.test_case "missing dep via private executable" `Quick 126 169 test_missing_dep_via_private_executable; 170 + Alcotest.test_case "missing dep via fuzz executable" `Quick 171 + test_missing_dep_via_fuzz_executable; 172 + Alcotest.test_case "with-test dep not flagged" `Quick 173 + test_with_test_dep_not_flagged; 127 174 ] )