(** Tests for precommit. *) let contains s sub = let len = String.length sub in let rec check i = if i + len > String.length s then false else if String.sub s i len = sub then true else check (i + 1) in check 0 let test_pre_commit_hook_valid () = let hook = Precommit.pre_commit_hook in Alcotest.(check bool) "is shell script" true (String.sub hook 0 2 = "#!"); Alcotest.(check bool) "runs dune fmt" true (contains hook "dune fmt"); Alcotest.(check bool) "checks staged files" true (contains hook "git diff --cached") let test_commit_msg_hook_valid () = let hook = Precommit.commit_msg_hook in Alcotest.(check bool) "is shell script" true (String.sub hook 0 2 = "#!"); Alcotest.(check bool) "filters AI lines" true (contains hook "Co-Authored-By"); Alcotest.(check bool) "checks emojis" true (contains hook "emoji") let suite = ( "precommit", [ Alcotest.test_case "pre_commit_hook valid" `Quick test_pre_commit_hook_valid; Alcotest.test_case "commit_msg_hook valid" `Quick test_commit_msg_hook_valid; ] )