let argc = Array.length Sys.argv
-let usage () =
- prerr_endline "Usage: regtest <file.test> ...";
- prerr_endline " regtest (-gen|--gen) <file.cic> ...";
- exit 2
-
let rawsep = "###"
let sep = Pcre.regexp (sprintf "^%s" rawsep)
let msg_prefix = "*** REGTEST *** "
ereduced = ereduced ^ "\n";
}
-let main () =
- if Sys.argv.(1) = "-gen" || Sys.argv.(1) = "--gen" then begin (* gen mode *)
- print_msg "[ Gen mode ]";
- for i = 2 to argc - 1 do
- let fname = Sys.argv.(i) in
+let dump_environment filename =
+ try
+ let oc = open_out filename in
+ CicEnvironment.dump_to_channel oc;
+ close_out oc
+ with exc ->
+ prerr_endline
+ ("DUMP_ENVIRONMENT FAILURE, uncaught excecption " ^
+ Printexc.to_string exc) ;
+ raise exc
+;;
+
+let restore_environment filename =
+ if Sys.file_exists filename then
+ begin
+ try
+ let ic = open_in filename in
+ CicEnvironment.restore_from_channel ic;
+ close_in ic
+ with exc ->
+ prerr_endline
+ ("RESTORE_ENVIRONMENT FAILURE, uncaught excecption " ^
+ Printexc.to_string exc) ;
+ raise exc
+ end
+ else
+ CicEnvironment.empty ()
+;;
+
+let main generate dump fnames =
+ if generate then
+ begin
+ (* gen mode *)
+ print_msg "[ Gen mode ]";
+ List.iter
+ (function fname ->
let test_fname = fname ^ ".test" in
+ let env_fname = fname ^ ".env" in
print_msg (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
- done
- end else begin (* regtest mode *)
- prerr_endline "[ Regtest mode ]";
+ print_test result test_fname ;
+ if dump then dump_environment env_fname ;
+ ) fnames
+ end else
+ begin
+ (* regtest mode *)
+ print_msg "[ Regtest mode ]";
let (ok, nok) = (ref 0, ref []) in
- for i = 1 to argc - 1 do
- let fname = Sys.argv.(i) in
- prerr_endline ("# " ^ fname);
- try
- let expected = parse_regtest fname in
- let actual = test_this expected.term in
- if as_expected expected actual then
- incr ok
- else
- nok := fname :: !nok;
- with e -> nok := fname :: !nok
- done;
+ List.iter
+ (function fname ->
+ let env_fname = fname ^ ".env" in
+ let test_fname = fname ^ ".test" in
+ restore_environment env_fname ;
+ prerr_endline ("# " ^ fname);
+ try
+ 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
+ incr ok
+ else
+ nok := fname :: !nok;
+ with e -> nok := fname :: !nok
+ ) fnames ;
print_msg "Regtest completed:";
print_msg (sprintf "Succeeded: %d" !ok);
print_msg (sprintf "Failed: %d" (List.length !nok));
List.iter (fun fname -> print_msg (sprintf " %s failed :-(" fname))
(List.rev !nok)
end
+;;
-let _ = try main () with Invalid_argument _ -> usage ()
-
+let _ =
+ let fnames = ref [] in
+ let gen = ref false in
+ let dump = ref false in
+ let nodump = ref false 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" ]
+ in
+ Arg.parse spec (function 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
+;;