@@ -41,17 +41,40 @@ struct
4141 )
4242 )
4343
44+ (* var gen_existing_pair : filesys -> (path * string) option Gen.t *)
45+ let rec gen_existing_pair fs = match fs with
46+ | File -> Gen. return None (* failwith "no sandbox directory"*)
47+ | Directory d ->
48+ (match Map_names. bindings d.fs_map with
49+ | [] -> Gen. return None
50+ | bindings -> Gen. (oneofl bindings >> = fun (n , sub_fs ) ->
51+ Gen. oneof [
52+ Gen. return (Some ([] ,n));
53+ Gen. map (function None -> Some ([] ,n)
54+ | Some (path ,name ) -> Some (n::path,name)) (gen_existing_pair sub_fs)]
55+ )
56+ )
57+
4458 let arb_cmd s =
4559 let name_gen = Gen. (oneofl [" aaa" ; " bbb" ; " ccc" ; " ddd" ; " eee" ]) in
4660 let path_gen = Gen. oneof [gen_existing_path s; Gen. list_size (Gen. int_bound 5 ) name_gen] in (* can be empty *)
61+ let fresh_pair_gen = Gen. (pair (list_size (int_bound 5 ) name_gen)) name_gen in
62+ let pair_gen =
63+ Gen. (oneof [
64+ fresh_pair_gen;
65+ (gen_existing_pair s >> = function None -> fresh_pair_gen
66+ | Some (p ,_ ) -> map (fun n -> (p,n)) name_gen);
67+ (gen_existing_pair s >> = function None -> fresh_pair_gen
68+ | Some (p ,n ) -> return (p,n));
69+ ]) in
4770 QCheck. make ~print: show_cmd
4871 Gen. (oneof
4972 [
5073 map (fun path -> File_exists path) path_gen ;
51- map2 (fun path new_dir_name -> Mkdir (path, new_dir_name)) path_gen name_gen ;
52- map2 (fun path delete_dir_name -> Rmdir (path, delete_dir_name)) path_gen name_gen ;
74+ map (fun ( path , new_dir_name ) -> Mkdir (path, new_dir_name)) pair_gen ;
75+ map (fun ( path , delete_dir_name ) -> Rmdir (path, delete_dir_name)) pair_gen ;
5376 map (fun path -> Readdir path) path_gen;
54- map2 (fun path new_file_name -> Mkfile (path, new_file_name)) path_gen name_gen ;
77+ map (fun ( path , new_file_name ) -> Mkfile (path, new_file_name)) pair_gen ;
5578 ])
5679
5780 let sandbox_root = " _sandbox"
0 commit comments