X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FgTopLevel%2Ftestlibrary.ml;h=90563a6186ec078dc9d34252c8372ad6aa59b9be;hb=edb6ab182b915ebc8b2810574b0a87bdab39d051;hp=681b9b36275bccad0cdb67790f6abb2f75d17a98;hpb=c35a3f47e0468a6076a3afdd6f2ff5c5fe528784;p=helm.git diff --git a/helm/gTopLevel/testlibrary.ml b/helm/gTopLevel/testlibrary.ml index 681b9b362..90563a618 100644 --- a/helm/gTopLevel/testlibrary.ml +++ b/helm/gTopLevel/testlibrary.ml @@ -11,6 +11,8 @@ exception Failure of string exception Multiple_interpretations let fail msg = raise (Failure msg) +let uri_predicate = ref BatchParser.constants_only + module DisambiguateCallbacks = struct let output_html ?(append_NL = true) msg = @@ -19,9 +21,8 @@ module DisambiguateCallbacks = (Ui_logger.string_of_html_msg msg) let interactive_user_uri_choice - ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id = - List.filter - (fun uri -> not (String.sub uri (String.length uri - 4) 4 = ".var")) + ~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id choices = + List.filter !uri_predicate choices let interactive_interpretation_choice _ = raise Multiple_interpretations let input_or_locate_uri ~title = fail "Unknown identifier" @@ -87,41 +88,71 @@ let test_uri uri = (Printexc.to_string exn)); `Nok -let _ = - let idx = ref 0 in - let ok = ref [] in - let nok = ref [] in - let maybe = ref [] in +let report ok nok maybe = + print_newline (); + print_endline "TestLibrary report"; + print_endline "Succeeded URIs:"; + List.iter (fun s -> print_endline ("\t" ^ s)) ok; + print_endline "Failed URIs:"; + List.iter (fun s -> print_endline ("\t" ^ s)) nok; + print_endline "Multiple answers URIs:"; + List.iter (fun s -> print_endline ("\t" ^ s)) maybe; + print_newline () + +let do_uri (ok, nok, maybe) uri = + let uri_str = UriManager.string_of_uri uri in + printf "Testing URI: %-55s %!" (uri_str ^ " ..."); + match test_uri uri with + | `Ok -> + print_endline "[ OK ]"; + ok := uri_str :: !ok + | `Nok -> + print_endline "[ FAILED ]"; + nok := uri_str :: !nok + | `Maybe -> + print_endline "[ MANY ]"; + maybe := uri_str :: !maybe + +let do_file status fname = try - let mode = if Sys.argv.(1) = "-" then `Stdin else `Cmdline in + let ic = open_in fname in while true do - incr idx; - let uri_str = - match mode with - | `Stdin -> input_line stdin - | `Cmdline -> Sys.argv.(!idx) - in - printf "Testing URI: %-55s " (uri_str ^ " ..."); flush stdout; - let uri = UriManager.uri_of_string uri_str in - match test_uri uri with - | `Ok -> - print_endline "[ OK ]"; - ok := uri_str :: !ok - | `Nok -> - print_endline "[ FAILED ]"; - nok := uri_str :: !nok - | `Maybe -> - print_endline "[ MANY ]"; - maybe := uri_str :: !maybe + let line = input_line ic in + try + let uri = UriManager.uri_of_string line in + do_uri status uri + with UriManager.IllFormedUri _ -> + printf "Error parsing URI '%s', ignoring it" line done - with Invalid_argument _ | End_of_file -> - 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 () + with exn -> + printf "Error trying to access '%s' (%s), skipping the file\n%!" + fname (Printexc.to_string exn) + +let _ = + let names = ref [] in + let tryvars = ref false 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)" ; + "-varsprefix", Arg.Set_string varsprefix, + "limit variable choices to URIs beginning with prefix" ; + ] + in + Arg.parse spec (fun name -> names := name :: !names) usage; + let names = List.rev !names in + uri_predicate := BatchParser.uri_pred_of_conf !tryvars !varsprefix; + let status = (ref [], ref [], ref []) in (* URIs *) + List.iter + (fun name -> + try + let uri = UriManager.uri_of_string name in + do_uri status uri + with UriManager.IllFormedUri _ -> + if Sys.file_exists name then + do_file status name + else + printf "Don't know what to do with '%s', ignoring it\n%!" name) + names