Skip to content

Commit 0ef1588

Browse files
committed
CWFile commands
1 parent 033b4f5 commit 0ef1588

File tree

4 files changed

+74
-6
lines changed

4 files changed

+74
-6
lines changed

src/coq_cw.ml

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
open 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 *)
1521
let 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+

src/coq_cw.mli

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
val test : ?msg:string -> Libnames.qualid -> Libnames.qualid list -> unit
1+
val test : ?msg:string -> Libnames.qualid -> Libnames.qualid list -> unit
2+
3+
val test_file_size : ?fname:string -> int -> unit
4+
5+
val test_file_regex : ?fname:string -> bool -> string -> unit

src/g_coq_cw.ml4

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,21 @@ VERNAC COMMAND EXTEND CWEndGroup CLASSIFIED AS QUERY
2020
Feedback.msg_notice (str "\n<COMPLETEDIN::>\n")
2121
]
2222
END
23+
24+
VERNAC COMMAND EXTEND CWFileSize CLASSIFIED AS QUERY
25+
| [ "CWFile" string_opt(fname) "Size" "<" int(size)] -> [
26+
Coq_cw.test_file_size ?fname size
27+
]
28+
END
29+
30+
VERNAC COMMAND EXTEND CWFileMatch CLASSIFIED AS QUERY
31+
| [ "CWFile" string_opt(fname) "Matches" string(regex)] -> [
32+
Coq_cw.test_file_regex ?fname true regex
33+
]
34+
END
35+
36+
VERNAC COMMAND EXTEND CWFileNegMatch CLASSIFIED AS QUERY
37+
| [ "CWFile" string_opt(fname) "Does" "Not" "Match" string(regex)] -> [
38+
Coq_cw.test_file_regex ?fname false regex
39+
]
40+
END

theories/Demo.v

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ CWTest "lemma2" lemma2 Assumes my_ax.
2929
CWTest lemma3 Assumes classic my_ax.
3030
Fail CWTest lemma3 Assumes my_ax.
3131

32-
CWEndGroup.
32+
CWEndGroup.
33+
34+
CWFile "theories/Demo.v" Size < 1000.
35+
Fail CWFile "theories/Demo.v" Size < 200.
36+
37+
CWFile "theories/Demo.v" Matches "Axiom".
38+
Fail CWFile "theories/Demo.v" Matches "$Theorem".
39+
40+
Fail CWFile "theories/Demo.v" Does Not Match "Axiom".
41+
CWFile "theories/Demo.v" Does Not Match "$Theorem".

0 commit comments

Comments
 (0)