Skip to content

Commit f7cfcfb

Browse files
committed
More uniformity: short Ok first, match on Error (Sys_error s)
1 parent 665547c commit f7cfcfb

File tree

1 file changed

+49
-56
lines changed

1 file changed

+49
-56
lines changed

src/sys/stm_tests.ml

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ struct
285285

286286
let postcond c (fs: filesys) res =
287287
match c, res with
288-
| File_exists path, Res ((Bool,_),b) -> b = Model.mem fs path
288+
| File_exists path, Res ((Bool,_),b) ->
289+
b = Model.mem fs path
289290
| Is_directory path, Res ((Result (Bool,Exn),_),res) ->
290291
(match res with
291292
| Ok b ->
@@ -328,67 +329,59 @@ struct
328329
| Mkdir (path, new_dir_name), Res ((Result (Unit,Exn),_), res) ->
329330
let full_path = (path @ [new_dir_name]) in
330331
(match res with
331-
| Error err ->
332-
(match err with
333-
| Sys_error s ->
334-
(match_msg s full_path "Permission denied") ||
335-
(match_msg s full_path "File exists" && Model.mem fs full_path) ||
336-
(match_msgs s full_path ["No such file or directory";
337-
"Invalid argument"] && not (Model.mem fs path)) ||
338-
(match_msgs s full_path ["Not a directory";
339-
"No such file or directory"(*win32*)] && not (path_is_a_dir fs full_path))
340-
| _ -> false)
341-
| Ok () -> Model.mem fs path && path_is_a_dir fs path && not (Model.mem fs full_path))
332+
| Ok () -> Model.mem fs path && path_is_a_dir fs path && not (Model.mem fs full_path)
333+
| Error (Sys_error s) ->
334+
(match_msg s full_path "Permission denied") ||
335+
(match_msg s full_path "File exists" && Model.mem fs full_path) ||
336+
(match_msgs s full_path ["No such file or directory";
337+
"Invalid argument"] && not (Model.mem fs path)) ||
338+
(match_msgs s full_path ["Not a directory";
339+
"No such file or directory"(*win32*)] && not (path_is_a_dir fs full_path))
340+
| Error _ -> false)
342341
| Rmdir (path, delete_dir_name), Res ((Result (Unit,Exn),_), res) ->
343342
let full_path = (path @ [delete_dir_name]) in
344343
(match res with
345-
| Error err ->
346-
(match err with
347-
| Sys_error s ->
348-
(match_msg s full_path "Permission denied") ||
349-
(match_msg s full_path "Directory not empty" && not (path_is_an_empty_dir fs full_path)) ||
350-
(match_msg s full_path "No such file or directory" && not (Model.mem fs full_path)) ||
351-
(match_msgs s full_path ["Not a directory";
352-
"Invalid argument"(*win32*)] && not (path_is_a_dir fs full_path))
353-
| _ -> false)
354-
| Ok () ->
355-
Model.mem fs full_path && path_is_a_dir fs full_path && path_is_an_empty_dir fs full_path)
344+
| Ok () ->
345+
Model.mem fs full_path && path_is_a_dir fs full_path && path_is_an_empty_dir fs full_path
346+
| Error (Sys_error s) ->
347+
(match_msg s full_path "Permission denied") ||
348+
(match_msg s full_path "Directory not empty" && not (path_is_an_empty_dir fs full_path)) ||
349+
(match_msg s full_path "No such file or directory" && not (Model.mem fs full_path)) ||
350+
(match_msgs s full_path ["Not a directory";
351+
"Invalid argument"(*win32*)] && not (path_is_a_dir fs full_path))
352+
| Error _ -> false)
356353
| Readdir path, Res ((Result (Array String,Exn),_), res) ->
357354
(match res with
358-
| Error err ->
359-
(match err with
360-
| Sys_error s ->
361-
(match_msg s path "Permission denied") ||
362-
(match_msg s path "No such file or directory" && not (Model.mem fs path)) ||
363-
(match_msgs s path ["Not a directory";
364-
"Invalid argument"(*win32*)] && not (path_is_a_dir fs path))
365-
| _ -> false)
366-
| Ok array_of_subdir ->
367-
(* Temporary work around for mingW, see https://github.com/ocaml/ocaml/issues/11829 *)
368-
if Sys.win32 && not (Model.mem fs path)
369-
then array_of_subdir = [||]
370-
else
371-
(Model.mem fs path && path_is_a_dir fs path &&
372-
(match Model.readdir fs path with
373-
| None -> false
374-
| Some l ->
375-
List.sort String.compare l
376-
= List.sort String.compare (Array.to_list array_of_subdir))))
377-
| Mkfile (path, new_file_name), Res ((Result (Unit,Exn),_),res) -> (
355+
| Ok array_of_subdir ->
356+
(* Temporary work around for mingW, see https://github.com/ocaml/ocaml/issues/11829 *)
357+
if Sys.win32 && not (Model.mem fs path)
358+
then array_of_subdir = [||]
359+
else
360+
(Model.mem fs path && path_is_a_dir fs path &&
361+
(match Model.readdir fs path with
362+
| None -> false
363+
| Some l ->
364+
List.sort String.compare l
365+
= List.sort String.compare (Array.to_list array_of_subdir)))
366+
| Error (Sys_error s) ->
367+
(match_msg s path "Permission denied") ||
368+
(match_msg s path "No such file or directory" && not (Model.mem fs path)) ||
369+
(match_msgs s path ["Not a directory";
370+
"Invalid argument"(*win32*)] && not (path_is_a_dir fs path))
371+
| Error _ -> false)
372+
| Mkfile (path, new_file_name), Res ((Result (Unit,Exn),_),res) ->
378373
let full_path = path @ [ new_file_name ] in
379-
match res with
380-
| Error err -> (
381-
match err with
382-
| Sys_error s ->
383-
(match_msgs s full_path ["File exists";
384-
"Permission denied"] && Model.mem fs full_path) ||
385-
(match_msgs s full_path ["No such file or directory";
386-
"Invalid argument";
387-
"Permission denied"] && not (Model.mem fs path)) ||
388-
(match_msgs s full_path ["Not a directory";
389-
"No such file or directory"] && not (path_is_a_dir fs path))
390-
| _ -> false)
391-
| Ok () -> path_is_a_dir fs path && not (Model.mem fs full_path))
374+
(match res with
375+
| Ok () -> path_is_a_dir fs path && not (Model.mem fs full_path)
376+
| Error (Sys_error s) ->
377+
(match_msgs s full_path ["File exists";
378+
"Permission denied"] && Model.mem fs full_path) ||
379+
(match_msgs s full_path ["No such file or directory";
380+
"Invalid argument";
381+
"Permission denied"] && not (Model.mem fs path)) ||
382+
(match_msgs s full_path ["Not a directory";
383+
"No such file or directory"] && not (path_is_a_dir fs path))
384+
| Error _ -> false)
392385
| _,_ -> false
393386
end
394387

0 commit comments

Comments
 (0)