Build information library for monopam tools.
0
fork

Configure Feed

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

monopam-info: add empty-monorepo tests for the index module

E605 (Missing Test File) was flagging lib/index/monopam_info_index.ml.
Cover the public API by building an index over an empty temp directory
and asserting the package/library/module lookups all return empty.

+63
+1
dune-project
··· 18 18 (dune (>= 3.0)) 19 19 (mdx :with-test) 20 20 (alcotest :with-test) 21 + (eio_main :with-test) 21 22 (fmt :with-test) 22 23 dune-build-info 23 24 eio
+1
monopam-info.opam
··· 12 12 "dune" {>= "3.21" & >= "3.0"} 13 13 "mdx" {with-test} 14 14 "alcotest" {with-test} 15 + "eio_main" {with-test} 15 16 "fmt" {with-test} 16 17 "dune-build-info" 17 18 "eio"
+3
test/index/dune
··· 1 + (test 2 + (name test) 3 + (libraries monopam-info.index alcotest eio_main unix))
+1
test/index/test.ml
··· 1 + let () = Alcotest.run "monopam-info.index" [ Test_monopam_info_index.suite ]
+53
test/index/test_monopam_info_index.ml
··· 1 + (* Sanity tests for Monopam_info_index against an empty monorepo: build 2 + should succeed and report no packages, no libraries, no modules. *) 3 + 4 + let with_temp_dir f = 5 + let dir = Filename.temp_file "monopam_info_index_test" "" in 6 + Sys.remove dir; 7 + Unix.mkdir dir 0o755; 8 + Fun.protect 9 + ~finally:(fun () -> 10 + let rec rm path = 11 + match Unix.lstat path with 12 + | { st_kind = Unix.S_DIR; _ } -> 13 + Sys.readdir path 14 + |> Array.iter (fun n -> rm (Filename.concat path n)); 15 + Unix.rmdir path 16 + | _ -> Sys.remove path 17 + | exception _ -> () 18 + in 19 + rm dir) 20 + (fun () -> f dir) 21 + 22 + let build_empty () = 23 + with_temp_dir (fun monorepo -> 24 + Eio_main.run @@ fun env -> 25 + let fs = Eio.Stdenv.fs env in 26 + Monopam_info_index.build ~fs ~monorepo:(Fpath.v monorepo)) 27 + 28 + let test_empty_monorepo_no_packages () = 29 + let idx = build_empty () in 30 + Alcotest.(check (list string)) 31 + "no packages found in an empty monorepo" [] 32 + (Monopam_info_index.packages idx) 33 + 34 + let test_empty_monorepo_unknown_package () = 35 + let idx = build_empty () in 36 + Alcotest.(check (list string)) 37 + "unknown package has no libraries" [] 38 + (Monopam_info_index.libraries idx "nonexistent"); 39 + Alcotest.(check (list string)) 40 + "unknown library has no modules" [] 41 + (Monopam_info_index.modules idx "nonexistent"); 42 + Alcotest.(check (option string)) 43 + "unknown library has no owning package" None 44 + (Monopam_info_index.package_of idx "nonexistent") 45 + 46 + let suite = 47 + ( "monopam_info_index", 48 + [ 49 + Alcotest.test_case "empty monorepo: no packages" `Quick 50 + test_empty_monorepo_no_packages; 51 + Alcotest.test_case "empty monorepo: unknown library lookups" `Quick 52 + test_empty_monorepo_unknown_package; 53 + ] )
+4
test/index/test_monopam_info_index.mli
··· 1 + (** {!Monopam_info_index} tests. *) 2 + 3 + val suite : string * unit Alcotest.test_case list 4 + (** [suite] is the alcotest suite for {!Monopam_info_index}. *)