+let report (ok,nok,maybe,timeout) =
+ print_newline ();
+ print_endline "TestLibrary report";
+ print_endline "Succeeded URIs:";
+ List.iter (fun s -> print_endline ("\t" ^ s)) (List.rev !ok);
+ print_endline "Failed URIs:";
+ List.iter (fun s -> print_endline ("\t" ^ s)) (List.rev !nok);
+ print_endline "Multiple answers URIs:";
+ List.iter (fun s -> print_endline ("\t" ^ s)) (List.rev !maybe);
+ print_newline ();
+ print_endline ("URIs that timeout (" ^ string_of_int !time_out ^ "s):");
+ List.iter (fun s -> print_endline ("\t" ^ s)) (List.rev !timeout);
+ print_newline ()
+
+let do_uri typecheck (ok, nok, maybe, timeout) uri =
+ let uri_str = UriManager.string_of_uri uri in
+ printf "Testing URI: %-55s %!" (uri_str ^ " ...");
+ (match test_uri typecheck uri with
+ | `Ok ->
+ print_endline "\e[01;32m[ OK ]\e[00m";
+ ok := uri_str :: !ok
+ | `Nok ->
+ print_endline "\e[01;31m[ FAILED ]\e[00m";
+ nok := uri_str :: !nok
+ | `Maybe ->
+ print_endline "\e[01;33m[ MANY ]\e[00m";
+ maybe := uri_str :: !maybe
+ | `TimeOut ->
+ print_endline "\e[01;34m[TIMEOUT!]\e[00m";
+ timeout := uri_str :: !timeout)
+
+let do_file typecheck status fname =
+ try
+ let ic = open_in fname in
+ (try
+ while true do
+ let line = input_line ic in
+ try
+ let uri = UriManager.uri_of_string line in
+ do_uri typecheck status uri
+ with UriManager.IllFormedUri _ ->
+ printf "Error parsing URI '%s', ignoring it" line
+ done
+ with End_of_file ->
+ close_in ic)
+ with exn ->
+ printf "Error trying to access '%s' (%s), skipping the file\n%!"
+ fname (Printexc.to_string exn)
+
+let _ =
+ 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 names = ref [] in
+ let tryvars = ref false in
+ let typecheck = ref false in
+ let prefix = ref "" in
+ let varsprefix = ref "####" in
+ let usage = "testlibrary [OPTION] ... (uri1 | file1) (uri2 | file2) ..." in
+ let spec =
+ [ "-vars", Arg.Set tryvars, "try also variables" ;
+ "-novars", Arg.Clear tryvars, "do not try variables (default)" ;
+ "-prefix", Arg.Set_string prefix,
+ "limit object choices to URIs beginning with prefix" ;
+ "-varsprefix", Arg.Set_string varsprefix,
+ "limit variable choices to URIs beginning with prefix; overrides -prefix" ;
+ "-timeout", Arg.Set_int time_out,
+ "number of seconds before a timeout; 0 means no timeout";
+ "-typecheck", Arg.Set typecheck, "simply typechek the uri"
+ ]
+ in
+ Arg.parse spec (fun name -> names := name :: !names) usage;
+ let names = List.rev !names in
+ if !varsprefix = "####" then varsprefix := !prefix ;
+ uri_predicate :=
+ BatchParser.uri_pred_of_conf !tryvars ~prefix:!prefix ~varsprefix:!varsprefix;
+ let status = (ref [], ref [], ref [], ref []) in (* <ok, nok, maybe, timeout> URIs *)
+ List.iter
+ (fun name ->
+ try
+ let uri = UriManager.uri_of_string name in
+ do_uri !typecheck status uri
+ with UriManager.IllFormedUri _ ->
+ if Sys.file_exists name then
+ do_file !typecheck status name
+ else
+ printf "Don't know what to do with '%s', ignoring it\n%!" name)
+ names ;
+ report status