11open Pp
22
3+ let solution_file = " /workspace/Solution.v"
4+
5+ let passed msg = Feedback. msg_notice (str (" \n <PASSED::> " ^ msg ^ " \n " ))
6+
7+ let failed msg = Feedback. msg_notice (str (" \n <FAILED::> " ^ msg ^ " \n " ))
8+
39(* unused *)
4- let extract_axioms s =
10+ (* let extract_axioms s =
511 let fold t typ accu =
612 match t with
713 | Printer.Variable _ -> failwith "Variable"
814 | Printer.Opaque _ -> failwith "Opaque"
915 | Printer.Transparent _ -> failwith "Transparent"
1016 | Printer.Axiom _ -> typ :: accu
1117 in
12- Printer.ContextObjectMap. fold fold s []
18+ Printer.ContextObjectMap.fold fold s [] *)
1319
1420(* TODO: compare axiom names (constants) also *)
1521let test_assumptions msg env sigma s ax_tys =
@@ -24,7 +30,7 @@ let test_assumptions msg env sigma s ax_tys =
2430 let ety = EConstr. of_constr ty in
2531 if List. exists (unify ety) ax_tys then ()
2632 else begin
27- Feedback. msg_notice (str ( " \n <FAILED::> " ^ msg ^ " \n " )) ;
33+ failed msg;
2834 CErrors. user_err (str " Axiom: " ++ Printer. pr_econstr_env env sigma ety)
2935 end
3036 | _ -> ()
@@ -51,4 +57,35 @@ let test ?(msg = "Axioms") c_ref ax_refs =
5157 let sigma, ty = Typing. type_of env sigma (EConstr. of_constr c) in
5258 sigma, ty :: tys) (sigma, [] ) ax_grs_cstrs in
5359 test_assumptions msg env sigma assumptions ax_tys;
54- Feedback. msg_notice (str (" \n <PASSED::> " ^ msg ^ " \n " ))
60+ passed msg
61+
62+ (* * Tests that the file size is less than a given number *)
63+ let test_file_size ?(fname = solution_file) size =
64+ try
65+ let stats = Unix. stat fname in
66+ if stats.Unix. st_size < size then
67+ passed (Format. sprintf " Size %d < %d" stats.Unix. st_size size)
68+ else begin
69+ let msg = Format. sprintf " Size %d >= %d" stats.Unix. st_size size in
70+ failed msg;
71+ CErrors. user_err (str msg)
72+ end
73+ with Unix. Unix_error _ -> CErrors. user_err (str (" Bad file name: " ^ fname))
74+
75+ (* * Tests that the file's content matches a given regular expression*)
76+ let test_file_regex ?(fname = solution_file) match_flag regex =
77+ let re = Str. regexp regex in
78+ let ic = open_in fname in
79+ let n = in_channel_length ic in
80+ let s = really_input_string ic n in
81+ let () = close_in ic in
82+ let matched = try ignore (Str. search_forward re s 0 ); true
83+ with Not_found -> false in
84+ if matched = match_flag then
85+ passed " OK"
86+ else begin
87+ failed " Bad match" ;
88+ CErrors. user_err (str " Bad match" )
89+ end
90+
91+
0 commit comments