let rawsep = "###"
let sep = Pcre.regexp (sprintf "^%s" rawsep)
-let print s = print_string s
+let print s = print_string s; flush stdout
let print_endline s = print_endline s
let print_endline_to_channel ch s = output_string ch (s ^ "\n")
ereduced: string; (* expected reduced term *)
}
-let print_test test fname =
+let print_test tests fname =
let oc = open_out fname in
- output_string oc
- (String.concat ""
- [ test.term;
- sprintf "%s (* METASENV after disambiguation *)\n" rawsep;
- test.emetasenv;
- sprintf "%s (* TERM after disambiguation *)\n" rawsep;
- test.eterm;
- sprintf "%s (* TYPE_OF the disambiguated term *)\n" rawsep;
- test.etype;
- sprintf "%s (* REDUCED disambiguated term *)\n" rawsep;
- test.ereduced ]);
+ output_string oc (List.hd tests).term;
+ let i = ref 0 in
+ List.iter
+ (function test ->
+ incr i ;
+ output_string oc
+ (String.concat ""
+ [ sprintf "INTERPRETATION NUMBER %d\n" !i;
+ sprintf "%s (* METASENV after disambiguation *)\n" rawsep;
+ test.emetasenv;
+ sprintf "%s (* TERM after disambiguation *)\n" rawsep;
+ test.eterm;
+ sprintf "%s (* TYPE_OF the disambiguated term *)\n" rawsep;
+ test.etype;
+ sprintf "%s (* REDUCED disambiguated term *)\n" rawsep;
+ test.ereduced;
+ "\n" ])
+ ) tests;
close_out oc
let parse_regtest =
| l -> Buffer.add_string (buffer_of_state !state) (line ^ "\n")
done
with End_of_file -> ());
- { term = Buffer.contents term;
+ [{ term = Buffer.contents term;
emetasenv = Buffer.contents emetasenv;
eterm = Buffer.contents eterm;
etype = Buffer.contents etype;
- ereduced = Buffer.contents ereduced }
+ ereduced = Buffer.contents ereduced }]
-let as_expected report_fname expected found = (* ignores "term" field *)
+let as_expected_one och expected found = (* ignores "term" field *)
let eterm_ok = expected.eterm = found.eterm in
let emetasenv_ok = expected.emetasenv = found.emetasenv in
let etype_ok = expected.etype = found.etype in
let ereduced_ok = expected.ereduced = found.ereduced in
let outcome = eterm_ok && emetasenv_ok && etype_ok && ereduced_ok in
- if outcome then
- (if Sys.file_exists report_fname then Sys.remove report_fname)
- else
begin
- let och = open_out report_fname in
- let print_endline = print_endline_to_channel och in
+ let print_endline = print_endline_to_channel (Lazy.force och) in
if not eterm_ok then begin
print_endline "### Term mismatch ###";
print_endline "# expected:";
print_endline "# found:";
print_endline (" " ^ found.ereduced);
end;
- close_out och ;
end;
outcome
-let test_this raw_term =
- let empty_context = [] in
- let (metasenv, cic_term) = BatchParser.parse raw_term in
- let etype =
- try
- CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv empty_context cic_term)
- with
- _ -> "MALFORMED"
+let as_expected report_fname expected found =
+ (if Sys.file_exists report_fname then Sys.remove report_fname) ;
+ let och = lazy (open_out report_fname) in
+ let print_endline = print_endline_to_channel (Lazy.force och) in
+ let rec aux =
+ function
+ [],[] -> true
+ | ex::extl, fo::fotl ->
+ as_expected_one och ex fo &&
+ aux (extl,fotl)
+ | [],found ->
+ print_endline "### Too many interpretations found" ;
+ false
+ | expected,[] ->
+ print_endline "### Too few interpretations found" ;
+ false
in
- let ereduced =
- try
- CicPp.ppterm (CicReduction.whd empty_context cic_term)
- with
- _ -> "MALFORMED"
- in
- {
- term = raw_term; (* useless *)
- emetasenv = CicMetaSubst.ppmetasenv metasenv [] ^ "\n";
- eterm = CicPp.ppterm cic_term ^ "\n";
- etype = etype ^ "\n";
- ereduced = ereduced ^ "\n";
- }
+ let outcome = aux (expected,found) in
+ (if Lazy.lazy_is_val och then close_out (Lazy.force och)) ;
+ outcome
+
+let test_this mqi_handle uri_pred raw_term =
+ let empty_context = [] in
+ List.map
+ (function (metasenv, cic_term) ->
+ let etype =
+ try
+ CicPp.ppterm
+ (CicTypeChecker.type_of_aux' metasenv empty_context cic_term)
+ with _ -> "MALFORMED"
+ in
+ let ereduced =
+ try
+ CicPp.ppterm (CicReduction.whd empty_context cic_term)
+ with _ -> "MALFORMED"
+ in
+ {
+ term = raw_term; (* useless *)
+ emetasenv = CicMetaSubst.ppmetasenv metasenv [] ^ "\n";
+ eterm = CicPp.ppterm cic_term ^ "\n";
+ etype = etype ^ "\n";
+ ereduced = ereduced ^ "\n";
+ }
+ ) (BatchParser.parse mqi_handle ~uri_pred raw_term)
let dump_environment filename =
try
("DUMP_ENVIRONMENT FAILURE, uncaught excecption " ^
Printexc.to_string exc) ;
raise exc
-;;
let restore_environment filename =
if Sys.file_exists filename then
end
else
CicEnvironment.empty ()
-;;
-let main generate dump fnames =
+let main mqi_handle generate dump fnames tryvars varsprefix =
+ let uri_pred = BatchParser.uri_pred_of_conf tryvars varsprefix in
if generate then
begin
(* gen mode *)
let env_fname = fname ^ ".env" in
print_endline (sprintf "Generating regtest %s -> %s\n ..."
fname test_fname);
- let raw_term = (parse_regtest fname).term in
- let result = test_this raw_term in
- print_test result test_fname ;
+ let raw_term = (List.hd (parse_regtest fname)).term in
+ let results = test_this mqi_handle uri_pred raw_term in
+ print_test results test_fname ;
if dump then dump_environment env_fname ;
) fnames
end else
let is_ok =
try
let expected = parse_regtest test_fname in
- let actual = test_this expected.term in
+ let actual = test_this mqi_handle uri_pred (List.hd expected).term in
if dump then dump_environment env_fname ;
if as_expected report_fname expected actual then
(incr ok ; true)
in
let timediff = Unix.gettimeofday () -. time in
print (sprintf "done in %f seconds\t" timediff) ;
- print_endline (if is_ok then "\e[01;32m[ OK ]\e[00m" else "\e[01;31m[ FAILED ]\e[00m")
+ print_endline
+ (if is_ok then
+ "\e[01;32m[ OK ]\e[00m"
+ else
+ "\e[01;31m[ FAILED ]\e[00m")
) fnames ;
print_endline "*** Summary ***";
print_endline (sprintf "Succeeded: %d" !ok);
List.iter (fun fname -> print_endline (sprintf " %s failed :-(" fname))
(List.rev !nok)
end
-;;
let _ =
+
+ Helm_registry.load_from "gTopLevel.conf.xml";
+ HelmLogger.register_log_callback
+ (fun ?(append_NL = true) msg ->
+ (if append_NL then prerr_endline else prerr_string)
+ (HelmLogger.string_of_html_msg msg));
+
+ let mqi_debug_fun = ignore in
+ let mqi_handle = MQIConn.init ~log:mqi_debug_fun () in
+
let fnames = ref [] in
let gen = ref false in
+ let tryvars = ref false in
let dump = ref false in
let nodump = ref false in
+ let varsprefix = ref "" in
let usage = "regtest [OPTION] ... test1 ..." in
let spec =
- ["-gen", Arg.Set gen, "generate the tests; implies -dump (unless -nodump is specified)" ;
- "--gen", Arg.Set gen, "generate the tests; implies -dump (unless -nodump is specified)" ;
- "-dump", Arg.Set dump, "dumps the final environment" ;
- "--dump", Arg.Set dump, "dumps the final environment" ;
- "-nodump", Arg.Set dump, "do not dump the final environment" ;
- "--nodump", Arg.Set dump, "do not dump the final environment" ]
+ ["-gen", Arg.Set gen,
+ "generate the tests; implies -dump (unless -nodump is specified)" ;
+ "--gen", Arg.Set gen,
+ "generate the tests; implies -dump (unless -nodump is specified)" ;
+ "-dump", Arg.Set dump, "dump the final environment" ;
+ "--dump", Arg.Set dump, "dump the final environment" ;
+ "-nodump", Arg.Set nodump, "do not dump the final environment" ;
+ "--nodump", Arg.Set nodump, "do not dump the final environment" ;
+ "-vars", Arg.Set tryvars, "try also variables" ;
+ "-novars", Arg.Clear tryvars, "do not try variables (default)" ;
+ "-varsprefix", Arg.Set_string varsprefix,
+ "limit variable choices to URIs beginning with prefix" ;
+ "--varsprefix", Arg.Set_string varsprefix,
+ "limit variable choices to URIs beginning with prefix" ;
+ ]
in
- Arg.parse spec (function filename -> fnames := filename::!fnames ) usage ;
+ Arg.parse spec (fun filename -> fnames := filename::!fnames ) usage ;
if !fnames = [] then
Arg.usage spec (Sys.argv.(0) ^ ": missing argument test. You must provide at least one test file.\n" ^ usage) ;
- main !gen ((!gen || !dump) && (not !nodump)) !fnames
-;;
+ main mqi_handle !gen ((!gen || !dump) && (not !nodump)) !fnames !tryvars !varsprefix;
+ MQIConn.close mqi_handle