Skip to content

Commit 1a8fa84

Browse files
committed
Remove reverse-engineering of error-message conditions
1 parent b38762b commit 1a8fa84

File tree

1 file changed

+28
-53
lines changed

1 file changed

+28
-53
lines changed

src/sys/stm_tests.ml

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,6 @@ struct
290290
| Mkfile (path, new_file_name) ->
291291
Res (result unit exn, protect mkfile (p path / new_file_name))
292292

293-
let match_msg err path msg = err = (p path) ^ ": " ^ msg
294-
let match_msgs err path msgs = List.exists (match_msg err path) msgs
295-
296293
let postcond c (fs: filesys) res =
297294
match c, res with
298295
| File_exists path, Res ((Bool,_),b) ->
@@ -304,63 +301,49 @@ struct
304301
| Some (Directory _) -> b = true
305302
| Some File -> b = false
306303
| None -> false)
307-
| Error (Sys_error s) ->
308-
(match_msg s path "No such file or directory" && not (Model.mem fs path)) ||
309-
(match_msg s path "Not a directory" &&
310-
List.exists (fun pref -> not (path_is_a_dir fs pref)) (path_prefixes path))
304+
| Error (Sys_error _) -> not (Model.mem fs path)
311305
| _ -> false)
312306
| Remove (path, file_name), Res ((Result (Unit,Exn),_), res) ->
313-
let full_path = (path @ [file_name]) in
307+
let full_path = path @ [file_name] in
314308
(match res with
315309
| Ok () -> Model.mem fs full_path && path_is_a_dir fs path && not (path_is_a_dir fs full_path)
316-
| Error (Sys_error s) ->
317-
(match_msg s full_path "No such file or directory" && not (Model.mem fs full_path)) ||
318-
(match_msgs s full_path ["Is a directory"; (*Linux*)
319-
"Operation not permitted"; (*macOS*)
320-
"Permission denied"(*Win*)] && path_is_a_dir fs full_path) ||
321-
(match_msg s full_path "Not a directory" && not (path_is_a_dir fs path))
310+
| Error (Sys_error _) ->
311+
(not (Model.mem fs full_path)) || path_is_a_dir fs full_path || not (path_is_a_dir fs path)
322312
| Error _ -> false
323313
)
324314
| Rename (old_path, new_path), Res ((Result (Unit,Exn),_), res) ->
325315
(match res with
326316
| Ok () -> Model.mem fs old_path (* permits dir-to-file MingW success https://github.com/ocaml/ocaml/issues/12073 *)
327-
| Error (Sys_error s) ->
317+
| Error (Sys_error _) ->
328318
(* temporary workaround for dir-to-empty-target-dir https://github.com/ocaml/ocaml/issues/12073 *)
329-
(s = "Permission denied" && Sys.win32 && path_is_a_dir fs old_path && path_is_an_empty_dir fs new_path) ||
319+
(Sys.win32 && path_is_a_dir fs old_path && path_is_an_empty_dir fs new_path) ||
330320
(* temporary workaround for identity regression renaming under MingW *)
331-
(s = "No such file or directory" && Sys.win32 && old_path = new_path && path_is_an_empty_dir fs new_path) ||
332-
(s = "No such file or directory" &&
333-
not (Model.mem fs old_path) || List.exists (fun pref -> not (path_is_a_dir fs pref)) (path_prefixes new_path)) ||
334-
((s = "Invalid argument" || s = "Permission denied"(*Win32*)) && is_true_prefix old_path new_path) ||
335-
(s = "Not a directory" &&
336-
List.exists (path_is_a_file fs) (path_prefixes old_path) ||
337-
List.exists (path_is_a_file fs) (path_prefixes new_path) ||
338-
path_is_a_dir fs old_path && Model.mem fs new_path && not (path_is_a_dir fs new_path)) ||
339-
((s = "Is a directory" || s = "Permission denied"(*Win32*)) && path_is_a_dir fs new_path) ||
340-
(s = "Directory not empty" &&
341-
is_true_prefix new_path old_path || (path_is_a_dir fs new_path && not (path_is_an_empty_dir fs new_path)))
321+
(Sys.win32 && old_path = new_path && path_is_an_empty_dir fs new_path) ||
322+
(* general conditions *)
323+
(not (Model.mem fs old_path)) ||
324+
is_true_prefix old_path new_path || (* parent-to-child *)
325+
is_true_prefix new_path old_path || (* child-to-parent *)
326+
(path_is_a_file fs old_path && path_is_a_dir fs new_path) || (* file-to-dir *)
327+
(path_is_a_dir fs old_path && path_is_a_file fs new_path) || (* dir-to-file *)
328+
(path_is_a_dir fs new_path && not (path_is_an_empty_dir fs new_path)) || (* to-non-empty-dir *)
329+
List.exists (fun pref -> not (path_is_a_dir fs pref)) (path_prefixes new_path) (* malformed-target-path *)
342330
| Error _ -> false)
343331
| Mkdir (path, new_dir_name), Res ((Result (Unit,Exn),_), res) ->
344-
let full_path = (path @ [new_dir_name]) in
332+
let full_path = path @ [new_dir_name] in
345333
(match res with
346334
| Ok () -> Model.mem fs path && path_is_a_dir fs path && not (Model.mem fs full_path)
347-
| Error (Sys_error s) ->
348-
(match_msg s full_path "File exists" && Model.mem fs full_path) ||
349-
(match_msgs s full_path ["No such file or directory";
350-
"Invalid argument"] && not (Model.mem fs path)) ||
351-
(match_msgs s full_path ["Not a directory";
352-
"No such file or directory"(*win32*)] && not (path_is_a_dir fs full_path))
335+
| Error (Sys_error _) ->
336+
Model.mem fs full_path || (not (Model.mem fs path)) || not (path_is_a_dir fs full_path)
353337
| Error _ -> false)
354338
| Rmdir (path, delete_dir_name), Res ((Result (Unit,Exn),_), res) ->
355-
let full_path = (path @ [delete_dir_name]) in
339+
let full_path = path @ [delete_dir_name] in
356340
(match res with
357341
| Ok () ->
358342
Model.mem fs full_path && path_is_a_dir fs full_path && path_is_an_empty_dir fs full_path
359-
| Error (Sys_error s) ->
360-
(match_msg s full_path "Directory not empty" && not (path_is_an_empty_dir fs full_path)) ||
361-
(match_msg s full_path "No such file or directory" && not (Model.mem fs full_path)) ||
362-
(match_msgs s full_path ["Not a directory";
363-
"Invalid argument"(*win32*)] && not (path_is_a_dir fs full_path))
343+
| Error (Sys_error _) ->
344+
(not (Model.mem fs full_path)) ||
345+
(not (path_is_a_dir fs full_path)) ||
346+
(not (path_is_an_empty_dir fs full_path))
364347
| Error _ -> false)
365348
| Readdir path, Res ((Result (Array String,Exn),_), res) ->
366349
(match res with
@@ -375,23 +358,15 @@ struct
375358
| Some l ->
376359
List.sort String.compare l
377360
= List.sort String.compare (Array.to_list array_of_subdir)))
378-
| Error (Sys_error s) ->
379-
(match_msg s path "No such file or directory" && not (Model.mem fs path)) ||
380-
(match_msgs s path ["Not a directory";
381-
"Invalid argument"(*win32*)] && not (path_is_a_dir fs path))
361+
| Error (Sys_error _) ->
362+
(not (Model.mem fs path)) || (not (path_is_a_dir fs path))
382363
| Error _ -> false)
383364
| Mkfile (path, new_file_name), Res ((Result (Unit,Exn),_),res) ->
384-
let full_path = path @ [ new_file_name ] in
365+
let full_path = path @ [new_file_name] in
385366
(match res with
386367
| Ok () -> path_is_a_dir fs path && not (Model.mem fs full_path)
387-
| Error (Sys_error s) ->
388-
(match_msgs s full_path ["File exists";
389-
"Permission denied"] && Model.mem fs full_path) ||
390-
(match_msgs s full_path ["No such file or directory";
391-
"Invalid argument";
392-
"Permission denied"] && not (Model.mem fs path)) ||
393-
(match_msgs s full_path ["Not a directory";
394-
"No such file or directory"] && not (path_is_a_dir fs path))
368+
| Error (Sys_error _) ->
369+
Model.mem fs full_path || (not (Model.mem fs path)) || (not (path_is_a_dir fs path))
395370
| Error _ -> false)
396371
| _,_ -> false
397372
end

0 commit comments

Comments
 (0)