Skip to content

Commit

Permalink
Fix patch expect tests on macos (#11132)
Browse files Browse the repository at this point in the history
A recent update to macos's patch command broke some of our tests. The
relevant changes to the command's behaviour are that it's stricter about
line numbers in patch metadata, and it no longer deletes files,
truncating them instead. This updates dune's patch expect tests to
accomodate this behaviour.

Signed-off-by: Stephen Sherratt <[email protected]>
  • Loading branch information
gridbugs authored Nov 21, 2024
1 parent 7f23a4b commit a602bb0
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions test/expect-tests/dune_patch/dune_patch_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ diff --git a/foo.ml b/foo.ml
index b69a69a5a..ea988f6bd 100644
--- a/foo.ml
+++ b/foo.ml
@@ -1,2 +1,2 @@
@@ -1,1 +1,1 @@
-This is wrong
+This is right
|}
Expand All @@ -22,7 +22,7 @@ diff --git a/dir/foo.ml b/dir/foo.ml
index b69a69a5a..ea988f6bd 100644
--- a/dir/foo.ml
+++ b/dir/foo.ml
@@ -1,2 +1,2 @@
@@ -1,1 +1,1 @@
-This is wrong
+This is right
|}
Expand Down Expand Up @@ -199,10 +199,21 @@ let%expect_test "patching a new file" =
let () = Dune_util.Report_error.report_backtraces true

let%expect_test "patching a deleted file" =
test [ "foo.ml", "This is wrong\n" ] ("foo.patch", delete_file);
check "foo.ml";
[%expect {|
File foo.ml not found |}]
let filename = "foo.ml" in
test [ filename, "This is wrong\n" ] ("foo.patch", delete_file);
(* Different implementations of the patch command behave differently when the
patch specifies deleting a file: *)
match Unix.stat filename with
| { st_kind = S_REG; st_size; _ } ->
(* Some implementations of patch (e.g. the patch that ships with macOS
15.1) do not delete files, and instead truncate them to 0 length. If
the file still exists after applying the patch, assert that it is now
empty. *)
assert (st_size == 0)
| _ -> failwith "Not a regular file"
| exception Unix.Unix_error (Unix.ENOENT, _, _) ->
(* Most implementations of patch will delete the file. *)
()
;;

let undo_breaks =
Expand Down

0 comments on commit a602bb0

Please sign in to comment.