From 8d37369f272e318226ddbcf93ef638165cdbcaad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Henry?= Date: Tue, 22 Nov 2016 11:16:56 +0100 Subject: [PATCH] Client: random json template : fix random integers --- src/client/client_generic_rpcs.ml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/client/client_generic_rpcs.ml b/src/client/client_generic_rpcs.ml index f60f621c4..402b5ea94 100644 --- a/src/client/client_generic_rpcs.ml +++ b/src/client/client_generic_rpcs.ml @@ -104,7 +104,12 @@ let fill_in input schema = let random_fill_in schema = let display _ = return () in - let int min max _ _ = return (Random.int (max - min) + min) in + let int min max _ _ = + let max = Int64.of_int max + and min = Int64.of_int min in + let range = Int64.sub max min in + let random_int64 = Int64.add (Random.int64 range) min in + return (Int64.to_int random_int64) in let string _title _ = return "" in let float _ _ = return (Random.float infinity) in let bool _ _ = return (Random.int 2 = 0) in @@ -155,7 +160,9 @@ let editor_fill_in schema = and reread () = (* finally reread the file *) Lwt_io.(with_file Input tmp (fun fp -> read fp)) >>= fun text -> - return (Data_encoding.Json.from_string text) + match Data_encoding.Json.from_string text with + | Ok r -> return (Ok r) + | Error msg -> return (Error (Printf.sprintf "bad input: %s" msg)) and delete () = (* and delete the temp file *) Lwt_unix.unlink tmp @@ -300,8 +307,8 @@ let call url () = Client_node_rpcs.describe ~recurse:false args >>= function | Static { service = Some { input } } -> begin fill_in input >>= function - | Error _ -> - error "bad input" + | Error msg -> + error "%s" msg | Ok json -> Client_node_rpcs.get_json args json >>= fun json -> Printf.printf "Output:\n%s\n%!" (Data_encoding.Json.to_string json) ;