Skip to content

Commit c5fdb2f

Browse files
committed
New commands for test cases
1 parent 4e11126 commit c5fdb2f

File tree

4 files changed

+93
-10
lines changed

4 files changed

+93
-10
lines changed

cw_example/test.v

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,31 @@ Require solution.
22
Require Import preloaded.
33
From CW Require Import Loader.
44

5-
CWTest "Testing solution" solution.solution Assumes test_axiom.
5+
CWGroup "Tests for solution.solution".
6+
CWTestCase "Type test".
7+
Example solution_test : 1 + 1 = 3.
8+
Proof. exact solution.solution. Qed.
9+
CWTestCase "Assumptions test".
10+
CWAssert "Testing solution" solution.solution Assumes test_axiom.
11+
CWEndGroup.
612

13+
CWGroup "Another test
14+
with line breaks".
15+
CWAssert "Testing solution_test
16+
(line break)" solution_test Assumes test_axiom.
17+
CWEndGroup.
18+
19+
CWTestCase "Without group".
20+
CWAssert solution_test Assumes test_axiom.
21+
CWEnd.
22+
23+
CWGroup "Nested groups".
24+
CWGroup "Level 2".
25+
CWTestCase "Test 1".
26+
CWAssert solution_test Assumes test_axiom.
27+
CWEndGroup.
28+
CWTestCase "Test 2".
29+
CWAssert solution_test Assumes test_axiom.
30+
CWAssert solution_test Assumes test_axiom.
31+
CWEnd.
32+
CWEndGroup.

src/coq_cw.ml

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,45 @@ open Pp
22

33
let solution_file = "/workspace/Solution.v"
44

5-
let passed msg = Feedback.msg_notice (str ("\n<PASSED::> " ^ msg ^ "\n"))
5+
let format_msg =
6+
let re = Str.regexp_string "\n" in
7+
Str.global_replace re "<:LF:>"
68

7-
let failed msg = Feedback.msg_notice (str ("\n<FAILED::> " ^ msg ^ "\n"))
9+
let display tag msg =
10+
Feedback.msg_notice (str (Printf.sprintf "\n<%s::>%s\n" tag (format_msg msg)))
11+
12+
let passed = display "PASSED"
13+
14+
let failed = display "FAILED"
15+
16+
type group = {
17+
tag : string;
18+
start_time : float
19+
}
20+
21+
let mk_group tag t = { tag = tag; start_time = t }
22+
23+
let group_stack = Summary.ref ~name:"open_groups" ([] : group list)
24+
25+
let rec end_group tag =
26+
let e = Unix.gettimeofday() in
27+
match !group_stack with
28+
| [] -> CErrors.user_err (str "No open groups")
29+
| {tag = "IT"} :: g :: gs when tag <> "IT" ->
30+
end_group "IT"; end_group tag
31+
| g :: gs ->
32+
if g.tag <> tag then CErrors.user_err (str "Ending incorrect group");
33+
group_stack := gs;
34+
display "COMPLETEDIN" (Printf.sprintf "%.2f" ((e -. g.start_time) *. 1000.))
35+
36+
let begin_group tag name =
37+
let t = Unix.gettimeofday() in
38+
let () =
39+
match !group_stack with
40+
| {tag = "IT"} :: _ when tag = "IT" -> end_group "IT"
41+
| _ -> () in
42+
group_stack := mk_group tag t :: !group_stack;
43+
display tag name
844

945
(* Based on the PrintAssumptions code from vernac/vernacentries.ml *)
1046
let assumptions r =

src/coq_cw.mli

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ val test_axioms : ?msg:string -> Libnames.qualid -> Libnames.qualid list -> unit
22

33
val test_file_size : ?fname:string -> int -> unit
44

5-
val test_file_regex : ?fname:string -> bool -> string -> unit
5+
val test_file_regex : ?fname:string -> bool -> string -> unit
6+
7+
val begin_group : string -> string -> unit
8+
9+
val end_group : string -> unit

src/g_coq_cw.ml4

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
11
DECLARE PLUGIN "coq_cw_plugin"
22

3-
open Pp
43
open Stdarg
54

5+
VERNAC COMMAND EXTEND CWAssert CLASSIFIED AS QUERY
6+
| [ "CWAssert" string_opt(msg) ref(e) "Assumes" ref_list(axioms)] -> [
7+
Coq_cw.test_axioms ?msg e axioms
8+
]
9+
END
10+
611
VERNAC COMMAND EXTEND CWTest CLASSIFIED AS QUERY
712
| [ "CWTest" string_opt(msg) ref(e) "Assumes" ref_list(axioms)] -> [
813
Coq_cw.test_axioms ?msg e axioms
914
]
1015
END
1116

12-
VERNAC COMMAND EXTEND CWGroup CLASSIFIED AS QUERY
17+
VERNAC COMMAND EXTEND CWGroup CLASSIFIED AS SIDEFF
1318
| [ "CWGroup" string(msg)] -> [
14-
Feedback.msg_notice (str ("\n<DESCRIBE::> " ^ msg ^ "\n"))
19+
Coq_cw.begin_group "DESCRIBE" msg
20+
]
21+
END
22+
23+
VERNAC COMMAND EXTEND CWEndGroup CLASSIFIED AS SIDEFF
24+
| [ "CWEndGroup"] -> [
25+
Coq_cw.end_group "DESCRIBE"
26+
]
27+
END
28+
29+
VERNAC COMMAND EXTEND CWTestCase CLASSIFIED AS SIDEFF
30+
| [ "CWTestCase" string(msg)] -> [
31+
Coq_cw.begin_group "IT" msg
1532
]
1633
END
1734

18-
VERNAC COMMAND EXTEND CWEndGroup CLASSIFIED AS QUERY
19-
| [ "CWEndGroup"] -> [
20-
Feedback.msg_notice (str "\n<COMPLETEDIN::>\n")
35+
VERNAC COMMAND EXTEND CWEnd CLASSIFIED AS SIDEFF
36+
| [ "CWEnd"] -> [
37+
Coq_cw.end_group "IT"
2138
]
2239
END
2340

0 commit comments

Comments
 (0)