File tree Expand file tree Collapse file tree 4 files changed +34
-3
lines changed Expand file tree Collapse file tree 4 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,14 @@ From CW Require Import Loader.
44
55CWGroup "Tests for solution.solution".
66 CWTestCase "Type test".
7- Example solution_test : 1 + 1 = 3 .
8- Proof . exact solution.solution. Qed .
7+ Fail CWAssert "Should fail" solution.solution : ( 1 + 1 = 2) .
8+ CWAssert solution.solution : (1 + 1 = 3) .
99 CWTestCase "Assumptions test".
1010 CWAssert "Testing solution" solution.solution Assumes test_axiom.
1111CWEndGroup.
1212
13+ Definition solution_test := solution.solution.
14+
1315CWGroup "Another test
1416with line breaks".
1517 CWAssert "Testing solution_test
Original file line number Diff line number Diff line change @@ -42,6 +42,27 @@ let begin_group tag name =
4242 group_stack := mk_group tag t :: ! group_stack;
4343 display tag name
4444
45+ let locate r =
46+ try
47+ let gr = Smartlocate. locate_global_with_alias r in
48+ (gr, Globnames. printable_constr_of_global gr)
49+ with Not_found -> CErrors. user_err (str " Not found: " ++ Libnames. pr_qualid r)
50+
51+ let test_type ?(msg = " Type Test" ) r c_ty =
52+ let env = Global. env() in
53+ let sigma = Evd. from_env env in
54+ let tm = EConstr. of_constr (snd (locate r)) in
55+ let sigma, expected_ty = Constrintern. interp_constr_evars env sigma c_ty in
56+ let actual_ty = Retyping. get_type_of ~lax: true env sigma tm in
57+ match Reductionops. infer_conv env sigma actual_ty expected_ty with
58+ | Some _ -> passed msg
59+ | None ->
60+ let p_actual = Printer. pr_econstr_env env sigma actual_ty in
61+ let p_expected = Printer. pr_econstr_env env sigma expected_ty in
62+ failed (Printf. sprintf " %s\n Actual type = %s\n Expected type = %s"
63+ msg (string_of_ppcmds p_actual) (string_of_ppcmds p_expected));
64+ CErrors. user_err (str " Incorrect Type: " ++ Printer. pr_econstr_env env sigma tm)
65+
4566(* Based on the PrintAssumptions code from vernac/vernacentries.ml *)
4667let assumptions r =
4768 try
Original file line number Diff line number Diff line change 11val test_axioms : ?msg : string -> Libnames .qualid -> Libnames .qualid list -> unit
22
3+ val test_type : ?msg : string -> Libnames .qualid -> Constrexpr .constr_expr -> unit
4+
35val test_file_size : ?fname : string -> int -> unit
46
57val test_file_regex : ?fname : string -> bool -> string -> unit
Original file line number Diff line number Diff line change @@ -2,7 +2,13 @@ DECLARE PLUGIN "coq_cw_plugin"
22
33open Stdarg
44
5- VERNAC COMMAND EXTEND CWAssert CLASSIFIED AS QUERY
5+ VERNAC COMMAND EXTEND CWAssertType CLASSIFIED AS QUERY
6+ | [ " CWAssert" string_opt(msg) ref (r) " :" constr(ty)] -> [
7+ Coq_cw. test_type ?msg r ty
8+ ]
9+ END
10+
11+ VERNAC COMMAND EXTEND CWAssertAssumptions CLASSIFIED AS QUERY
612| [ " CWAssert" string_opt(msg) ref (e) " Assumes" ref_list(axioms)] -> [
713 Coq_cw. test_axioms ?msg e axioms
814 ]
You can’t perform that action at this time.
0 commit comments