From 4e1ddc6883eeeadf8155abecc82c7035de7efd33 Mon Sep 17 00:00:00 2001 From: Stephen Sherratt Date: Tue, 8 Oct 2024 05:10:10 +1100 Subject: [PATCH] pkg: add repro for gh10991 (#10993) Signed-off-by: Stephen Sherratt --- .../test-cases/pkg/ocamlformat/gh10991.t | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/blackbox-tests/test-cases/pkg/ocamlformat/gh10991.t diff --git a/test/blackbox-tests/test-cases/pkg/ocamlformat/gh10991.t b/test/blackbox-tests/test-cases/pkg/ocamlformat/gh10991.t new file mode 100644 index 00000000000..44a69d9b498 --- /dev/null +++ b/test/blackbox-tests/test-cases/pkg/ocamlformat/gh10991.t @@ -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 < 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 < 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 *)