My aggregated monorepo of OCaml code, automaintained
0
fork

Configure Feed

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

Add tests for Targets.resolve and Generate.find_compiler/unique_compilers

Targets: small_universe nonempty, has odoc, resolve single target.
Generate: find_compiler with base/variants/none, unique_compilers
dedup across solutions, empty case.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+105
+27
day11/batch/test/test_batch.ml
··· 256 256 257 257 (* ── Test registration ───────────────────────────────────────────── *) 258 258 259 + (* ── Targets tests ──────────────────────────────────────────────── *) 260 + 261 + let test_small_universe_nonempty () = 262 + Alcotest.(check bool) "non-empty" true 263 + (List.length Targets.small_universe > 0) 264 + 265 + let test_small_universe_has_odoc () = 266 + Alcotest.(check bool) "has odoc" true 267 + (List.mem "odoc" Targets.small_universe) 268 + 269 + let test_resolve_single_target () = 270 + (* resolve with an explicit target returns exactly that *) 271 + let dummy_packages = Day11_solver.Git_packages.empty in 272 + let result = Targets.resolve dummy_packages (Some "astring.0.8.5") in 273 + Alcotest.(check int) "one target" 1 (List.length result); 274 + Alcotest.(check string) "correct" "astring.0.8.5" 275 + (OpamPackage.to_string (List.hd result)) 276 + 259 277 let () = 260 278 Alcotest.run "day11_batch" 261 279 [ ··· 294 312 test_find_previous_sha_dir; 295 313 Alcotest.test_case "find previous SHA dir none" `Quick 296 314 test_find_previous_sha_dir_none; 315 + ] ); 316 + ( "Targets", 317 + [ 318 + Alcotest.test_case "small universe nonempty" `Quick 319 + test_small_universe_nonempty; 320 + Alcotest.test_case "small universe has odoc" `Quick 321 + test_small_universe_has_odoc; 322 + Alcotest.test_case "resolve single target" `Quick 323 + test_resolve_single_target; 297 324 ] ); 298 325 ]
+78
day11/doc/test/test_doc.ml
··· 232 232 false (Bos.OS.Dir.exists Fpath.(html_dir / "u" / "orphaned") 233 233 |> Result.get_ok) 234 234 235 + (* ── Generate tests ──────────────────────────────────────────────── *) 236 + 237 + let pkg s = OpamPackage.of_string s 238 + 239 + let test_find_compiler_base () = 240 + let solution = 241 + OpamPackage.Map.empty 242 + |> OpamPackage.Map.add (pkg "ocaml-base-compiler.5.4.1") OpamPackage.Set.empty 243 + |> OpamPackage.Map.add (pkg "ocaml.5.4.1") OpamPackage.Set.empty 244 + |> OpamPackage.Map.add (pkg "dune.3.21.1") OpamPackage.Set.empty 245 + in 246 + match Generate.find_compiler solution with 247 + | Some c -> Alcotest.(check string) "found" "ocaml-base-compiler.5.4.1" 248 + (OpamPackage.to_string c) 249 + | None -> Alcotest.fail "expected compiler" 250 + 251 + let test_find_compiler_variants () = 252 + let solution = 253 + OpamPackage.Map.empty 254 + |> OpamPackage.Map.add (pkg "ocaml-variants.5.2.0+ox") OpamPackage.Set.empty 255 + |> OpamPackage.Map.add (pkg "ocaml.5.2.0") OpamPackage.Set.empty 256 + in 257 + match Generate.find_compiler solution with 258 + | Some c -> Alcotest.(check string) "found" "ocaml-variants.5.2.0+ox" 259 + (OpamPackage.to_string c) 260 + | None -> Alcotest.fail "expected compiler" 261 + 262 + let test_find_compiler_none () = 263 + let solution = 264 + OpamPackage.Map.empty 265 + |> OpamPackage.Map.add (pkg "dune.3.21.1") OpamPackage.Set.empty 266 + in 267 + Alcotest.(check bool) "none" true 268 + (Generate.find_compiler solution = None) 269 + 270 + let test_unique_compilers () = 271 + let sol1 = 272 + OpamPackage.Map.empty 273 + |> OpamPackage.Map.add (pkg "ocaml-base-compiler.5.4.1") OpamPackage.Set.empty 274 + |> OpamPackage.Map.add (pkg "astring.0.8.5") OpamPackage.Set.empty 275 + in 276 + let sol2 = 277 + OpamPackage.Map.empty 278 + |> OpamPackage.Map.add (pkg "ocaml-base-compiler.4.14.2") OpamPackage.Set.empty 279 + |> OpamPackage.Map.add (pkg "dune.3.21.1") OpamPackage.Set.empty 280 + in 281 + let sol3 = 282 + OpamPackage.Map.empty 283 + |> OpamPackage.Map.add (pkg "ocaml-base-compiler.5.4.1") OpamPackage.Set.empty 284 + |> OpamPackage.Map.add (pkg "fmt.0.11.0") OpamPackage.Set.empty 285 + in 286 + let compilers = Generate.unique_compilers 287 + [ (pkg "astring.0.8.5", sol1); 288 + (pkg "distributed.0.6.0", sol2); 289 + (pkg "fmt.0.11.0", sol3) ] in 290 + Alcotest.(check int) "two unique" 2 (List.length compilers); 291 + let strs = List.map OpamPackage.to_string compilers 292 + |> List.sort String.compare in 293 + Alcotest.(check (list string)) "versions" 294 + [ "ocaml-base-compiler.4.14.2"; "ocaml-base-compiler.5.4.1" ] strs 295 + 296 + let test_unique_compilers_empty () = 297 + let compilers = Generate.unique_compilers [] in 298 + Alcotest.(check int) "empty" 0 (List.length compilers) 299 + 235 300 (* ── Test registration ───────────────────────────────────────────── *) 236 301 237 302 let () = ··· 296 361 test_universe_package_refs_roundtrip; 297 362 Alcotest.test_case "gc removes unreferenced" `Quick 298 363 test_universe_gc; 364 + ] ); 365 + ( "Generate", 366 + [ 367 + Alcotest.test_case "find_compiler base" `Quick 368 + test_find_compiler_base; 369 + Alcotest.test_case "find_compiler variants" `Quick 370 + test_find_compiler_variants; 371 + Alcotest.test_case "find_compiler none" `Quick 372 + test_find_compiler_none; 373 + Alcotest.test_case "unique_compilers" `Quick 374 + test_unique_compilers; 375 + Alcotest.test_case "unique_compilers empty" `Quick 376 + test_unique_compilers_empty; 299 377 ] ); 300 378 ]