From 8351ff94655c8aa120a6e8dfec922ed992898c54 Mon Sep 17 00:00:00 2001 From: Etienne Millon Date: Fri, 19 Jul 2024 09:49:45 +0200 Subject: [PATCH] chore: do not depend on ocamlformat in tests (#10745) Signed-off-by: Etienne Millon --- Makefile | 2 +- test/blackbox-tests/test-cases/dialects/dune | 7 +++++++ .../test-cases/dialects/no_impl.t/run.t | 9 +++++++++ .../test-cases/dialects/no_intf_good.t/run.t | 5 +++++ test/blackbox-tests/test-cases/formatting/dune | 7 +++++++ .../test-cases/formatting/feature.t/run.t | 1 + .../test-cases/formatting/load-automatic-dirs.t | 1 + .../test-cases/formatting/no-gen.t | 5 +++++ test/blackbox-tests/utils/dune | 4 ++++ test/blackbox-tests/utils/ocamlformat.ml | 16 ++++++++++++++++ 10 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 test/blackbox-tests/test-cases/dialects/dune create mode 100644 test/blackbox-tests/test-cases/formatting/dune create mode 100644 test/blackbox-tests/utils/ocamlformat.ml diff --git a/Makefile b/Makefile index 93e893a7065..dc6386b1bf7 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,7 @@ install-ocamlformat: opam install -y ocamlformat.$$(awk -F = '$$1 == "version" {print $$2}' .ocamlformat) .PHONY: dev-deps -dev-deps: install-ocamlformat +dev-deps: opam install -y . --deps-only --with-dev-setup .PHONY: coverage-deps diff --git a/test/blackbox-tests/test-cases/dialects/dune b/test/blackbox-tests/test-cases/dialects/dune new file mode 100644 index 00000000000..e83959f79ed --- /dev/null +++ b/test/blackbox-tests/test-cases/dialects/dune @@ -0,0 +1,7 @@ +(env + (_ + (binaries ../../utils/ocamlformat.exe))) + +(cram + (applies_to :whole_subtree) + (deps %{bin:ocamlformat})) diff --git a/test/blackbox-tests/test-cases/dialects/no_impl.t/run.t b/test/blackbox-tests/test-cases/dialects/no_impl.t/run.t index de6ed4d5ae4..e954302acf7 100644 --- a/test/blackbox-tests/test-cases/dialects/no_impl.t/run.t +++ b/test/blackbox-tests/test-cases/dialects/no_impl.t/run.t @@ -3,4 +3,13 @@ Test the (dialect ...) stanza inside the `dune-project` file. $ dune exec ./main.exe $ dune build @fmt + fake ocamlformat is running: "--impl" "fmt.ml" + fake ocamlformat is running: "--impl" "main.ml" Formatting main.mfi + File "fmt.ml", line 1, characters 0-0: + Error: Files _build/default/fmt.ml and _build/default/.formatted/fmt.ml + differ. + File "main.ml", line 1, characters 0-0: + Error: Files _build/default/main.ml and _build/default/.formatted/main.ml + differ. + [1] diff --git a/test/blackbox-tests/test-cases/dialects/no_intf_good.t/run.t b/test/blackbox-tests/test-cases/dialects/no_intf_good.t/run.t index 7ca3ddc88e8..b2cd7ce22ec 100644 --- a/test/blackbox-tests/test-cases/dialects/no_intf_good.t/run.t +++ b/test/blackbox-tests/test-cases/dialects/no_intf_good.t/run.t @@ -3,4 +3,9 @@ Test the (dialect ...) stanza inside the dune-project file. $ dune exec ./main.exe $ dune build @fmt + fake ocamlformat is running: "--impl" "fmt.ml" Formatting main.mf + File "fmt.ml", line 1, characters 0-0: + Error: Files _build/default/fmt.ml and _build/default/.formatted/fmt.ml + differ. + [1] diff --git a/test/blackbox-tests/test-cases/formatting/dune b/test/blackbox-tests/test-cases/formatting/dune new file mode 100644 index 00000000000..e83959f79ed --- /dev/null +++ b/test/blackbox-tests/test-cases/formatting/dune @@ -0,0 +1,7 @@ +(env + (_ + (binaries ../../utils/ocamlformat.exe))) + +(cram + (applies_to :whole_subtree) + (deps %{bin:ocamlformat})) diff --git a/test/blackbox-tests/test-cases/formatting/feature.t/run.t b/test/blackbox-tests/test-cases/formatting/feature.t/run.t index c698d0dc04c..b812cdc2f32 100644 --- a/test/blackbox-tests/test-cases/formatting/feature.t/run.t +++ b/test/blackbox-tests/test-cases/formatting/feature.t/run.t @@ -225,6 +225,7 @@ Formatting can also be set in the (env ...) stanza > EOF $ touch using-env/.ocamlformat $ (cd using-env && dune build @fmt) + fake ocamlformat is running: "--impl" "subdir/foo.ml" File "subdir/foo.ml", line 1, characters 0-0: Error: Files _build/default/subdir/foo.ml and _build/default/subdir/.formatted/foo.ml differ. diff --git a/test/blackbox-tests/test-cases/formatting/load-automatic-dirs.t b/test/blackbox-tests/test-cases/formatting/load-automatic-dirs.t index 718c1645e2e..a2605019c5a 100644 --- a/test/blackbox-tests/test-cases/formatting/load-automatic-dirs.t +++ b/test/blackbox-tests/test-cases/formatting/load-automatic-dirs.t @@ -12,6 +12,7 @@ > (library (name lib_reason)) > EOF $ dune build ./bin/.formatted/ocaml_file.ml + fake ocamlformat is running: "--impl" "bin/ocaml_file.ml" .formatted dir is loaded diff --git a/test/blackbox-tests/test-cases/formatting/no-gen.t b/test/blackbox-tests/test-cases/formatting/no-gen.t index 43a563f10ac..03df9d3c1f4 100644 --- a/test/blackbox-tests/test-cases/formatting/no-gen.t +++ b/test/blackbox-tests/test-cases/formatting/no-gen.t @@ -57,10 +57,15 @@ Now we add [mli] files for the two modules whose implementation is generated: We format again. $ dune build @fmt + fake ocamlformat is running: "--intf" "other_gen.mli" Warning: one state end-of-stream conflict was arbitrarily resolved. File "parser_raw.mly", line 5, characters 4-7: Warning: production prog -> EOL is never reduced. Warning: in total, 1 production is never reduced. + fake ocamlformat is running: "--intf" "parser_raw.mli" + File "other_gen.mli", line 1, characters 0-0: + Error: Files _build/default/other_gen.mli and + _build/default/.formatted/other_gen.mli differ. File "parser_raw.mli", line 1, characters 0-0: Error: Files _build/default/parser_raw.mli and _build/default/.formatted/parser_raw.mli differ. diff --git a/test/blackbox-tests/utils/dune b/test/blackbox-tests/utils/dune index 3d1072f7bf0..09f3e38f714 100644 --- a/test/blackbox-tests/utils/dune +++ b/test/blackbox-tests/utils/dune @@ -38,3 +38,7 @@ (modules ocaml_index) (name ocaml_index) (libraries cmdliner)) + +(executable + (modules ocamlformat) + (name ocamlformat)) diff --git a/test/blackbox-tests/utils/ocamlformat.ml b/test/blackbox-tests/utils/ocamlformat.ml new file mode 100644 index 00000000000..26e6a83a7cc --- /dev/null +++ b/test/blackbox-tests/utils/ocamlformat.ml @@ -0,0 +1,16 @@ +(* This can be used when testing formatting rules instead of calling the real + ocamlformat binary. But when doing so, be careful not to expose it to too + many tests because it will be also be used by `@fmt` in dune itself. +*) + +let () = + let args = + Sys.argv + |> Array.to_list + |> List.tl + |> List.map (fun s -> Printf.sprintf "%S" s) + |> String.concat " " + in + Printf.eprintf "fake ocamlformat is running: %s\n" args; + Printf.printf "(* fake ocamlformat output *)" +;;