My aggregated monorepo of OCaml code, automaintained
0
fork

Configure Feed

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

Add blessing tests: compiler tiebreaker and compute_blessed_universes

- Test that newer compiler wins when deps_count and revdeps_count tie
- Test that compute_blessed_universes returns entries for all packages

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

+43
+43
day11/batch/test/test_batch.ml
··· 54 54 let blessings = Blessing.compute_blessings [] in 55 55 Alcotest.(check int) "empty" 0 (List.length blessings) 56 56 57 + let test_blessing_compiler_tiebreaker () = 58 + (* Two solutions with same deps_count for c.1 but different compilers. 59 + Should prefer the newer compiler. *) 60 + let sol_old = 61 + OpamPackage.Map.empty 62 + |> OpamPackage.Map.add (pkg "ocaml-base-compiler.4.14.0") 63 + OpamPackage.Set.empty 64 + |> OpamPackage.Map.add (pkg "c.1") 65 + (OpamPackage.Set.singleton (pkg "ocaml-base-compiler.4.14.0")) 66 + in 67 + let sol_new = 68 + OpamPackage.Map.empty 69 + |> OpamPackage.Map.add (pkg "ocaml-base-compiler.5.4.1") 70 + OpamPackage.Set.empty 71 + |> OpamPackage.Map.add (pkg "c.1") 72 + (OpamPackage.Set.singleton (pkg "ocaml-base-compiler.5.4.1")) 73 + in 74 + let blessings = Blessing.compute_blessings 75 + [ (pkg "a.1", sol_old); (pkg "b.1", sol_new) ] in 76 + (* c.1 has 1 dep in both — tiebreaker should pick 5.4.1 *) 77 + let _, map_new = List.nth blessings 1 in 78 + Alcotest.(check bool) "c blessed in newer compiler solution" 79 + true (Blessing.is_blessed map_new (pkg "c.1")) 80 + 81 + let test_blessed_universes () = 82 + let sol = 83 + OpamPackage.Map.empty 84 + |> OpamPackage.Map.add (pkg "c.1") OpamPackage.Set.empty 85 + |> OpamPackage.Map.add (pkg "b.1") 86 + (OpamPackage.Set.singleton (pkg "c.1")) 87 + in 88 + let blessed = Blessing.compute_blessed_universes 89 + [ (pkg "b.1", sol) ] in 90 + (* Both packages should have blessed universes *) 91 + Alcotest.(check bool) "b has blessed universe" 92 + true (Hashtbl.mem blessed (pkg "b.1")); 93 + Alcotest.(check bool) "c has blessed universe" 94 + true (Hashtbl.mem blessed (pkg "c.1")) 95 + 57 96 (* ── Dag_executor tests ──────────────────────────────────────────── *) 58 97 59 98 let test_dag_executor_basic () = with_eio @@ fun env -> ··· 284 323 Alcotest.test_case "two universes" `Quick 285 324 test_blessing_two_universes; 286 325 Alcotest.test_case "empty" `Quick test_blessing_empty; 326 + Alcotest.test_case "compiler tiebreaker" `Quick 327 + test_blessing_compiler_tiebreaker; 328 + Alcotest.test_case "blessed universes" `Quick 329 + test_blessed_universes; 287 330 ] ); 288 331 ( "Dag_executor", 289 332 [