let sep = Pcre.regexp (sprintf "^%s" rawsep)
let print s = print_string s
let print_endline s = print_endline s
+let print_endline_to_channel ch s = output_string ch (s ^ "\n")
type state = Term | EMetasenv | ETerm | EType | EReduced
etype = Buffer.contents etype;
ereduced = Buffer.contents ereduced }
-let as_expected expected found = (* ignores "term" field *)
- let outcome = ref true in
- if expected.eterm <> found.eterm then begin
- print_endline "Term mismatch";
- print_endline " expected:";
- print_endline (" " ^ expected.eterm);
- print_endline " found:";
- print_endline (" " ^ found.eterm);
- outcome := false;
- end;
- if expected.emetasenv <> found.emetasenv then begin
- print_endline "Metasenv mismatch";
- print_endline " expected:";
- print_endline (" " ^ expected.emetasenv);
- print_endline " found:";
- print_endline (" " ^ found.emetasenv);
- outcome := false;
- end;
- if expected.etype <> found.etype then begin
- print_endline "Type mismatch";
- print_endline " expected:";
- print_endline (" " ^ expected.etype);
- print_endline " found:";
- print_endline (" " ^ found.etype);
- outcome := false;
- end;
- if expected.ereduced <> found.ereduced then begin
- print_endline "Reduced term mismatch";
- print_endline " expected:";
- print_endline (" " ^ expected.ereduced);
- print_endline " found:";
- print_endline (" " ^ found.ereduced);
- outcome := false;
- end;
- !outcome
+let as_expected report_fname 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
+ if not eterm_ok then begin
+ print_endline "### Term mismatch ###";
+ print_endline "# expected:";
+ print_endline (" " ^ expected.eterm);
+ print_endline "# found:";
+ print_endline (" " ^ found.eterm);
+ end;
+ if not emetasenv_ok then begin
+ print_endline "### Metasenv mismatch ###";
+ print_endline "# expected:";
+ print_endline (" " ^ expected.emetasenv);
+ print_endline "# found:";
+ print_endline (" " ^ found.emetasenv);
+ end;
+ if not etype_ok then begin
+ print_endline "### Type mismatch ###";
+ print_endline "# expected:";
+ print_endline (" " ^ expected.etype);
+ print_endline "# found:";
+ print_endline (" " ^ found.etype);
+ end;
+ if expected.ereduced <> found.ereduced then begin
+ print_endline "### Reduced term mismatch ###";
+ print_endline "# expected:";
+ print_endline (" " ^ expected.ereduced);
+ print_endline "# found:";
+ print_endline (" " ^ found.ereduced);
+ end;
+ close_out och ;
+ end;
+ outcome
let test_this raw_term =
let empty_context = [] in
(function fname ->
let env_fname = fname ^ ".env" in
let test_fname = fname ^ ".test" in
+ let report_fname = fname ^ ".report" in
restore_environment env_fname ;
let time = Unix.gettimeofday () in
print ("Processing " ^ fname ^":\t") ;
let expected = parse_regtest test_fname in
let actual = test_this expected.term in
if dump then dump_environment env_fname ;
- if as_expected expected actual then
+ if as_expected report_fname expected actual then
(incr ok ; true)
else
(nok := fname :: !nok ; false)