@@ -11,15 +11,15 @@ let format_msg =
1111let display tag msg =
1212 Feedback. msg_notice (str (Printf. sprintf " \n <%s::>%s\n " tag (format_msg msg)))
1313
14- let passed = display " PASSED"
15-
16- let failed = display " FAILED"
14+ let stop_on_failure_flag = ref true
1715
1816type group = {
1917 tag : string ;
2018 start_time : float
2119}
2220
21+ let stop_on_failure v = stop_on_failure_flag := v <> 0
22+
2323let mk_group tag t = { tag = tag; start_time = t }
2424
2525let group_stack = Summary. ref ~name: " open_groups" ([] : group list )
@@ -49,6 +49,15 @@ let rec end_all_groups () =
4949 | [] -> ()
5050 | {tag = tag } :: gs -> end_group tag; end_all_groups ()
5151
52+ let passed = display " PASSED"
53+
54+ let failed msg =
55+ display " FAILED" msg;
56+ if ! stop_on_failure_flag then begin
57+ end_all_groups () ;
58+ CErrors. user_err (str msg)
59+ end
60+
5261let locate r =
5362 try
5463 let gr = Smartlocate. locate_global_with_alias r in
@@ -67,9 +76,8 @@ let test_type ?(msg = "Type Test") r c_ty =
6776 let p_actual = Printer. pr_econstr_env env sigma actual_ty in
6877 let p_expected = Printer. pr_econstr_env env sigma expected_ty in
6978 failed (Printf. sprintf " %s\n Actual type = %s\n Expected type = %s"
70- msg (string_of_ppcmds p_actual) (string_of_ppcmds p_expected));
71- end_all_groups () ;
72- CErrors. user_err (str " Incorrect Type: " ++ Printer. pr_econstr_env env sigma tm)
79+ msg (string_of_ppcmds p_actual) (string_of_ppcmds p_expected))
80+ (* CErrors.user_err (str "Incorrect Type: " ++ Printer.pr_econstr_env env sigma tm) *)
7381
7482(* Based on the PrintAssumptions code from vernac/vernacentries.ml *)
7583let assumptions r =
@@ -106,9 +114,8 @@ let test_axioms ?(msg = "Axiom Test") c_ref ax_refs =
106114 | Printer. Axiom (ax , _ ) ->
107115 if Printer.ContextObjectSet. mem t ax_set then ()
108116 else begin
109- failed msg;
110- end_all_groups () ;
111- CErrors. user_err (str " Prohibited Axiom: " ++ pr_axiom env sigma ax ty)
117+ let p_axiom = pr_axiom env sigma ax ty in
118+ failed (Printf. sprintf " %s\n Prohibited Axiom: %s" msg (string_of_ppcmds p_axiom))
112119 end
113120 | _ -> ()
114121 in
@@ -123,9 +130,7 @@ let test_file_size ?(fname = solution_file) size =
123130 passed (Format. sprintf " Size %d < %d" stats.Unix. st_size size)
124131 else begin
125132 let msg = Format. sprintf " Size %d >= %d" stats.Unix. st_size size in
126- failed msg;
127- end_all_groups () ;
128- CErrors. user_err (str msg)
133+ failed msg
129134 end
130135 with Unix. Unix_error _ -> CErrors. user_err (str (" Bad file name: " ^ fname))
131136
@@ -140,22 +145,15 @@ let test_file_regex ?(fname = solution_file) match_flag regex =
140145 with Not_found -> false in
141146 if matched = match_flag then
142147 passed " OK"
143- else begin
144- failed " Bad match" ;
145- end_all_groups () ;
146- CErrors. user_err (str " Bad match" )
147- end
148+ else
149+ failed " Bad match"
148150
149- let run_system_command ?err_msg args =
151+ let run_system_command ?( err_msg = " Failed " ) args =
150152 let cmd = String. concat " " args in
151153 Printf. printf " Running: %s" cmd;
152- match Unix. system cmd with
153- | Unix. WEXITED 0 -> ()
154- | _ ->
155- let msg = match err_msg with None -> " Failed" | Some msg -> msg in
156- failed msg;
157- end_all_groups () ;
158- CErrors. user_err (str msg)
154+ match Unix. system (cmd ^ " 2>&1" ) with
155+ | Unix. WEXITED 0 -> true
156+ | _ -> (failed err_msg; false )
159157
160158let write_file fname str =
161159 let oc = open_out fname in
@@ -165,7 +163,7 @@ let write_file fname str =
165163(* * Compiles and runs the given OCaml source files *)
166164let compile_and_run files ?(options = " " ) driver_code =
167165 write_file driver_file driver_code;
168- run_system_command ~err_msg: " Compilation failed" ([ocaml_compiler; options] @ files @ [driver_file]);
169- passed " OK" ;
170- run_system_command [" ./a.out" ];
171- passed " OK "
166+ if run_system_command ~err_msg: " Compilation failed" ([ocaml_compiler; options] @ files @ [driver_file]) then begin
167+ passed " OK" ;
168+ if run_system_command [" ./a.out" ] then passed " OK "
169+ end
0 commit comments