@@ -10,37 +10,37 @@ let ( / ) = Path.( / )
1010let try_read_file path =
1111 match Path. load path with
1212 | s -> traceln " read %a -> %S" Path. pp path s
13- | exception ex -> traceln " @[<h>%a@] " Eio.Exn. pp ex
13+ | exception ex -> raise ex
1414
1515let try_write_file ~create ?append path content =
1616 match Path. save ~create ?append path content with
1717 | () -> traceln " write %a -> ok" Path. pp path
18- | exception ex -> traceln " @[<h>%a@] " Eio.Exn. pp ex
18+ | exception ex -> raise ex
1919
2020let try_mkdir path =
2121 match Path. mkdir path ~perm: 0o700 with
2222 | () -> traceln " mkdir %a -> ok" Path. pp path
23- | exception ex -> traceln " @[<h>%a@] " Eio.Exn. pp ex
23+ | exception ex -> raise ex
2424
2525let try_rename p1 p2 =
2626 match Path. rename p1 p2 with
2727 | () -> traceln " rename %a to %a -> ok" Path. pp p1 Path. pp p2
28- | exception ex -> traceln " @[<h>%a@] " Eio.Exn. pp ex
28+ | exception ex -> raise ex
2929
3030let try_read_dir path =
3131 match Path. read_dir path with
3232 | names -> traceln " read_dir %a -> %a" Path. pp path Fmt.Dump. (list string ) names
33- | exception ex -> traceln " @[<h>%a@] " Eio.Exn. pp ex
33+ | exception ex -> raise ex
3434
3535let try_unlink path =
3636 match Path. unlink path with
3737 | () -> traceln " unlink %a -> ok" Path. pp path
38- | exception ex -> traceln " @[<h>%a@] " Eio.Exn. pp ex
38+ | exception ex -> raise ex
3939
4040let try_rmdir path =
4141 match Path. rmdir path with
4242 | () -> traceln " rmdir %a -> ok" Path. pp path
43- | exception ex -> traceln " @[<h>%a@] " Eio.Exn. pp ex
43+ | exception ex -> raise ex
4444
4545let with_temp_file path fn =
4646 Fun. protect (fun () -> fn path) ~finally: (fun () -> Eio.Path. unlink path)
@@ -110,6 +110,91 @@ let test_append env () =
110110 Path. save ~create: `Never ~append: true test_file " 2nd-write" ;
111111 Alcotest. (check string ) " append" " 1st-write-original2nd-write" (Path. load test_file)
112112
113+ let test_mkdir env () =
114+ let cwd = Eio.Stdenv. cwd env in
115+ try_mkdir (cwd / " subdir" );
116+ try_mkdir (cwd / " subdir\\ nested" );
117+ let test_file = cwd / " subdir\\ nested\\ test-file" in
118+ Path. save ~create: (`Exclusive 0o600 ) test_file " data" ;
119+ Alcotest. (check string ) " mkdir" " data" (Path. load test_file);
120+ Unix. unlink " subdir\\ nested\\ test-file" ;
121+ Unix. rmdir " subdir\\ nested" ;
122+ Unix. rmdir " subdir"
123+
124+ let test_symlink _env () =
125+ (* TODO *)
126+ ()
127+
128+ let test_unlink env () =
129+ let cwd = Eio.Stdenv. cwd env in
130+ Path. save ~create: (`Exclusive 0o600 ) (cwd / " file" ) " data" ;
131+ try_mkdir (cwd / " subdir" );
132+ Path. save ~create: (`Exclusive 0o600 ) (cwd / " subdir\\ file2" ) " data2" ;
133+ try_read_file (cwd / " file" );
134+ try_read_file (cwd / " subdir\\ file2" );
135+ try_unlink (cwd / " file" );
136+ try_unlink (cwd / " subdir\\ file2" );
137+ let () =
138+ try
139+ try_read_file (cwd / " file" );
140+ failwith " file should not exist"
141+ with Eio. Io (Eio.Fs. E (Not_found _ ), _ ) -> ()
142+ in
143+ let () =
144+ try
145+ try_read_file (cwd / " subdir\\ file2" );
146+ failwith " file should not exist"
147+ with Eio. Io (Eio.Fs. E (Not_found _ ), _ ) -> ()
148+ in
149+ try_write_file ~create: (`Exclusive 0o600 ) (cwd / " subdir\\ file2" ) " data2" ;
150+ (* Supposed to use symlinks here. *)
151+ try_unlink (cwd / " subdir\\ file2" );
152+ let () =
153+ try
154+ try_read_file (cwd / " subdir\\ file2" );
155+ failwith " file should not exist"
156+ with Eio. Io (Eio.Fs. E (Not_found _ ), _ ) -> ()
157+ in
158+ ()
159+
160+ let try_failing_unlink env () =
161+ let cwd = Eio.Stdenv. cwd env in
162+ let () =
163+ try
164+ try_unlink (cwd / " missing" );
165+ failwith " Expected not found!"
166+ with Eio. Io (Eio.Fs. E (Not_found _ ), _ ) -> ()
167+ in
168+ let () =
169+ try
170+ try_unlink (cwd / " ..\\ foo" );
171+ failwith " Expected permission denied!"
172+ with Eio. Io (Eio.Fs. E (Permission_denied _ ), _ ) -> ()
173+ in
174+ ()
175+
176+ let test_remove_dir env () =
177+ let cwd = Eio.Stdenv. cwd env in
178+ try_mkdir (cwd / " d1" );
179+ try_mkdir (cwd / " subdir\\ d2" );
180+ try_read_dir (cwd / " d1" );
181+ try_read_dir (cwd / " subdir\\ d2" );
182+ try_rmdir (cwd / " d1" );
183+ try_rmdir (cwd / " subdir\\ d2" );
184+ let () =
185+ try
186+ try_read_dir (cwd / " d1" );
187+ failwith " Expected not found"
188+ with Eio. Io (Eio.Fs. E (Not_found _ ), _ ) -> ()
189+ in
190+ let () =
191+ try
192+ try_read_dir (cwd / " subdir\\ d2" );
193+ failwith " Expected not found"
194+ with Eio. Io (Eio.Fs. E (Not_found _ ), _ ) -> ()
195+ in
196+ ()
197+
113198let tests env = [
114199 " create-write-read" , `Quick , test_create_and_read env;
115200 " cwd-abs-path" , `Quick , test_cwd_no_access_abs env;
@@ -118,4 +203,9 @@ let tests env = [
118203 " create-trunc" , `Quick , test_trunc env;
119204 " create-empty" , `Quick , test_empty env;
120205 " append" , `Quick , test_append env;
206+ " mkdir" , `Quick , test_mkdir env;
207+ " symlinks" , `Quick , test_symlink env;
208+ " unlink" , `Quick , test_unlink env;
209+ " failing-unlink" , `Quick , try_failing_unlink env;
210+ " rmdir" , `Quick , test_remove_dir env;
121211]
0 commit comments