Skip to content

Commit 6323773

Browse files
committed
update postcond match -> more readable
1 parent 9add414 commit 6323773

File tree

1 file changed

+63
-55
lines changed

1 file changed

+63
-55
lines changed

src/sys/stm_tests.ml

Lines changed: 63 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -172,61 +172,69 @@ struct
172172
let p path = static_path / "sandbox_root" / (String.concat "/" path) in
173173
match c, res with
174174
| File_exists (path), Res ((Bool,_),b) -> b = mem fs path
175-
| Mkdir (path, new_dir_name, _perm), Res ((Result (Unit,Exn),_), Error (Sys_error (s) ))
176-
when s = (p (path @ [new_dir_name])) ^ ": Permission denied" -> true
177-
| Mkdir (path, new_dir_name, _perm), Res ((Result (Unit,Exn),_), Error (Sys_error (s) ))
178-
when s = (p (path @ [new_dir_name])) ^ ": File exists" -> mem fs (path @ [new_dir_name])
179-
| Mkdir (path, new_dir_name, _perm), Res ((Result (Unit,Exn),_), Error (Sys_error (s) ))
180-
when s = (p (path @ [new_dir_name])) ^ ": No such file or directory" -> not (mem fs path)
181-
| Mkdir (path, new_dir_name, _perm), Res ((Result (Unit,Exn),_), Error (Sys_error (s) ))
182-
when s = (p (path @ [new_dir_name])) ^ ": Not a directory" ->
183-
(match find_opt fs (path @ [new_dir_name]) with
184-
| None -> true
185-
| Some target_fs -> not (is_a_dir target_fs))
186-
| Mkdir (path, new_dir_name, _perm), Res ((Result (Unit,Exn),_), Ok ()) ->
187-
let is_existing_is_a_dir =
188-
(match find_opt fs path with
189-
| None -> false
190-
| Some target_fs -> is_a_dir target_fs) in
191-
true && not (mem fs (path @ [new_dir_name])) && mem fs path && is_existing_is_a_dir
192-
| Mkdir (_path, _new_dir_name, _perm), Res ((Result (Unit,Exn),_), _) -> false
193-
| Rmdir (path, delete_dir_name), Res ((Result (Unit,Exn),_), Error (Sys_error (s) ))
194-
when s = (p (path @ [delete_dir_name])) ^ ": No such file or directory" ->
195-
not (mem fs (path @ [delete_dir_name]))
196-
| Rmdir (path, delete_dir_name), Res ((Result (Unit,Exn),_), Error (Sys_error (s) ))
197-
when s = (p (path @ [delete_dir_name])) ^ ": Directory not empty" ->
198-
not (readdir fs (path @ [delete_dir_name]) = Some [])
199-
| Rmdir (path, delete_dir_name), Res ((Result (Unit,Exn),_), Error (Sys_error (s) ))
200-
when s = (p (path @ [delete_dir_name])) ^ ": Not a directory" ->
201-
(match find_opt fs (path @ [delete_dir_name]) with
202-
| None -> true
203-
| Some target_fs -> not (is_a_dir target_fs))
204-
| Rmdir (path, delete_dir_name), Res ((Result (Unit,Exn),_), Ok ()) ->
205-
let is_empty = readdir fs (path @ [delete_dir_name]) = Some [] in
206-
let is_a_dir =
207-
(match find_opt fs (path @ [delete_dir_name]) with
208-
| None -> false
209-
| Some target_fs -> is_a_dir target_fs) in
210-
mem fs (path @ [delete_dir_name]) && is_empty && is_a_dir
211-
| Rmdir (_path, _delete_dir_name), Res ((Result (Unit,Exn),_), _r) -> false
212-
| Readdir (path), Res ((Result (Array String,Exn),_), Error (Sys_error (s) ))
213-
when s = (p path) ^ ": Permission denied" -> true
214-
| Readdir (path), Res ((Result (Array String,Exn),_), Error (Sys_error (s) ))
215-
when s = (p path) ^ ": No such file or directory" ->
216-
not (mem fs path)
217-
| Readdir (path), Res ((Result (Array String,Exn),_), Error (Sys_error (s) ))
218-
when s = (p path) ^ ": Not a directory" ->
219-
(match find_opt fs path with
220-
| None -> true
221-
| Some target_fs -> not (is_a_dir target_fs))
222-
| Readdir (path), Res ((Result (Array String,Exn),_), r) ->
223-
(match r with
224-
| Error _ -> false
225-
| Ok a ->
226-
let sut = List.sort (fun a b -> -(String.compare a b)) (Array.to_list a) in
227-
(match readdir fs path with
228-
| None -> false
229-
| Some l -> List.sort (fun a b -> -(String.compare a b)) l = sut))
175+
| Mkdir (path, new_dir_name, _perm), Res ((Result (Unit,Exn),_), res) ->
176+
let complete_path = (path @ [new_dir_name]) in
177+
(match res with
178+
| Error err ->
179+
(match err with
180+
| Sys_error s ->
181+
(s = (p complete_path) ^ ": Permission denied") ||
182+
(s = (p complete_path) ^ ": File exists" && mem fs complete_path) ||
183+
(s = (p complete_path) ^ ": No such file or directory" && not (mem fs path)) ||
184+
(s = (p complete_path) ^ ": Not a directory" &&
185+
(match find_opt fs complete_path with
186+
| None -> true
187+
| Some target_fs -> not (is_a_dir target_fs)))
188+
| _ -> false)
189+
| Ok () ->
190+
let is_existing_is_a_dir =
191+
(match find_opt fs path with
192+
| None -> false
193+
| Some target_fs -> is_a_dir target_fs) in
194+
not (mem fs complete_path) && mem fs path && is_existing_is_a_dir)
195+
| Rmdir (path, delete_dir_name), Res ((Result (Unit,Exn),_), res) ->
196+
let complete_path = (path @ [delete_dir_name]) in
197+
(match res with
198+
| Error err ->
199+
(match err with
200+
| Sys_error s ->
201+
(s = (p complete_path) ^ ": Directory not empty" && not (readdir fs complete_path = Some [])) ||
202+
(s = (p complete_path) ^ ": No such file or directory" && not (mem fs complete_path)) ||
203+
(s = (p complete_path) ^ ": Not a directory" &&
204+
(match find_opt fs complete_path with
205+
| None -> true
206+
| Some target_fs -> not (is_a_dir target_fs)))
207+
| _ -> false)
208+
| Ok () ->
209+
let is_empty = readdir fs complete_path = Some [] in
210+
let is_a_dir =
211+
(match find_opt fs complete_path with
212+
| None -> false
213+
| Some target_fs -> is_a_dir target_fs) in
214+
mem fs complete_path && is_empty && is_a_dir)
215+
| Readdir (path), Res ((Result (Array String,Exn),_), res) ->
216+
(match res with
217+
| Error err ->
218+
(match err with
219+
| Sys_error s ->
220+
(s = (p path) ^ ": Permission denied") ||
221+
(s = (p path) ^ ": No such file or directory" && not (mem fs path)) ||
222+
(s = (p path) ^ ": Not a directory" &&
223+
(match find_opt fs path with
224+
| None -> true
225+
| Some target_fs -> not (is_a_dir target_fs)))
226+
| _ -> false)
227+
| Ok array_of_subdir ->
228+
let sut = List.sort (fun a b -> -(String.compare a b)) (Array.to_list array_of_subdir) in
229+
let same_result =
230+
(match readdir fs path with
231+
| None -> false
232+
| Some l -> List.sort (fun a b -> -(String.compare a b)) l = sut) in
233+
let is_a_dir =
234+
(match find_opt fs path with
235+
| None -> true
236+
| Some target_fs -> is_a_dir target_fs) in
237+
same_result && mem fs path && is_a_dir)
230238
| Touch (_path, _new_dir_name, _perm), Res ((Unit,_),_) -> true
231239
| _,_ -> false
232240
end

0 commit comments

Comments
 (0)