@@ -60,6 +60,14 @@ let array : type a c s. (a, c, s, combinable) ty -> (a array, c, s, combinable)
6060 | GenDeconstr (arb , print , eq ) -> GenDeconstr (QCheck. array arb, QCheck.Print. array print, Array. for_all2 eq)
6161 | Deconstr (print , eq ) -> Deconstr (QCheck.Print. array print, Array. for_all2 eq)
6262
63+ let bounded_array : type a c s. int -> (a, c, s, combinable) ty -> (a array, c, s, combinable) ty =
64+ fun maxsize ty ->
65+ let array = QCheck. array_of_size (QCheck.Gen. int_bound maxsize) in
66+ match ty with
67+ | Gen (arb , print ) -> Gen (array arb, QCheck.Print. array print)
68+ | GenDeconstr (arb , print , eq ) -> GenDeconstr (array arb, QCheck.Print. array print, Array. for_all2 eq)
69+ | Deconstr (print , eq ) -> Deconstr (QCheck.Print. array print, Array. for_all2 eq)
70+
6371let print_seq pp s =
6472 let b = Buffer. create 25 in
6573 Buffer. add_char b '<' ;
@@ -269,6 +277,19 @@ module MakeCmd (ApiSpec : ApiSpec) : Lin.CmdSpec = struct
269277
270278 let show_cmd (Cmd (_ ,args ,_ ,print ,_ ,_ )) = print args
271279
280+ let rec fix_args
281+ : type a r. Lin.Env.t -> (a, r) Args.args -> (a, r) Args.args QCheck.Iter.t =
282+ fun env args ->
283+ let open QCheck in
284+ let fn_state i args = Args. FnState (i,args) in
285+ match args with
286+ | FnState (i , args ) -> Iter. (map fn_state (Lin.Env. valid_t_vars env i) < *> fix_args env args)
287+ | Fn (x , args ) -> Iter. map (fun args -> Args. Fn (x, args)) (fix_args env args)
288+ | _ -> Iter. return args
289+
290+ let fix_cmd env (Cmd (name ,args ,rty ,print ,shrink ,f )) =
291+ QCheck.Iter. map (fun args -> Cmd (name,args,rty,print,shrink,f)) (fix_args env args)
292+
272293 let shrink_cmd (Cmd (name ,args ,rty ,print ,shrink ,f )) =
273294 QCheck.Iter. map (fun args -> Cmd (name,args,rty,print,shrink,f)) (shrink args)
274295
@@ -287,18 +308,9 @@ module MakeCmd (ApiSpec : ApiSpec) : Lin.CmdSpec = struct
287308 let rec apply_f
288309 : type a r. a -> (a, r) Args.args -> t array -> Lin.Var.t option -> r = fun f args state opt_target ->
289310 match args with
290- | Ret _ ->
291- (* This happens only if there was a non-function value in the API,
292- which I'm not sure makes sense *)
293- raise (Invalid_argument " apply_f" )
294- | Ret_or_exc _ ->
295- (* This happens only if there was a non-function value in the API,
296- which I'm not sure makes sense *)
297- raise (Invalid_argument " apply_f" )
298- | Ret_ignore _ ->
299- (* This happens only if there was a non-function value in the API,
300- which I'm not sure makes sense *)
301- raise (Invalid_argument " apply_f" )
311+ | Ret _
312+ | Ret_or_exc _
313+ | Ret_ignore _
302314 | Ret_ignore_or_exc _ ->
303315 (* This happens only if there was a non-function value in the API,
304316 which I'm not sure makes sense *)
@@ -326,9 +338,7 @@ module MakeCmd (ApiSpec : ApiSpec) : Lin.CmdSpec = struct
326338 try Ok (ignore @@ f state.(index))
327339 with e -> Error e
328340 end )
329- | FnState (index , (Fn _ as rem )) ->
330- apply_f (f state.(index)) rem state opt_target
331- | FnState (index , (FnState _ as rem )) ->
341+ | FnState (index , rem ) ->
332342 apply_f (f state.(index)) rem state opt_target
333343 | Fn (arg , Ret _ ) ->
334344 f arg
@@ -344,9 +354,7 @@ module MakeCmd (ApiSpec : ApiSpec) : Lin.CmdSpec = struct
344354 try Ok (ignore @@ f arg)
345355 with e -> Error e
346356 end
347- | Fn (arg , (Fn _ as rem )) ->
348- apply_f (f arg) rem state opt_target
349- | Fn (arg , (FnState _ as rem )) ->
357+ | Fn (arg , rem ) ->
350358 apply_f (f arg) rem state opt_target
351359
352360 let run (opt_target ,cmd ) state =
0 commit comments