Skip to content

Commit

Permalink
pkg: add repro for gh10991 (ocaml#10993)
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Sherratt <stephen@sherra.tt>
  • Loading branch information
gridbugs authored and anmonteiro committed Nov 17, 2024
1 parent 9c42f51 commit 4e1ddc6
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/blackbox-tests/test-cases/pkg/ocamlformat/gh10991.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Test that ocamlformat is re-run when a source file changes.

$ . ./helpers.sh
$ mkrepo
$ make_project_with_dev_tool_lockdir

Make a fake ocamlformat package that appends a comment to the end of its input.
$ mkpkg ocamlformat <<EOF
> install: [
> [ "sh" "-c" "echo '#!/bin/sh' > %{bin}%/ocamlformat" ]
> [ "sh" "-c" "echo 'cat \$2' >> %{bin}%/ocamlformat" ]
> [ "sh" "-c" "echo 'echo \$2 | grep .*.ml >/dev/null && echo \"(* formatted with fake ocamlformat *)\"' >> %{bin}%/ocamlformat" ]
> [ "sh" "-c" "chmod a+x %{bin}%/ocamlformat" ]
> ]
> EOF

Initial file:
$ cat foo.ml
let () = print_endline "Hello, world"

$ DUNE_CONFIG__LOCK_DEV_TOOL=enabled dune fmt
Solution for dev-tools.locks/ocamlformat:
- ocamlformat.0.0.1
File "foo.ml", line 1, characters 0-0:
Error: Files _build/default/foo.ml and _build/default/.formatted/foo.ml
differ.
Promoting _build/default/.formatted/foo.ml to foo.ml.
[1]

After formatting the fake ocamlformat has added a suffix:
$ cat foo.ml
let () = print_endline "Hello, world"
(* formatted with fake ocamlformat *)

Update the file:
$ cat > foo.ml <<EOF
> let () = print_endline "Hello, ocaml!"
> EOF

$ DUNE_CONFIG__LOCK_DEV_TOOL=enabled dune fmt
File "foo.ml", line 1, characters 0-0:
Error: Files _build/default/foo.ml and _build/default/.formatted/foo.ml
differ.
Promoting _build/default/.formatted/foo.ml to foo.ml.
[1]

After formatting a second time, the recent change to the file was ignored:
$ cat foo.ml
let () = print_endline "Hello, world"
(* formatted with fake ocamlformat *)

0 comments on commit 4e1ddc6

Please sign in to comment.