Skip to content

Commit

Permalink
chore: do not depend on ocamlformat in tests (#10745)
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne Millon <me@emillon.org>
  • Loading branch information
emillon authored Jul 19, 2024
1 parent fd43bc7 commit 8351ff9
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/blackbox-tests/test-cases/dialects/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(env
(_
(binaries ../../utils/ocamlformat.exe)))

(cram
(applies_to :whole_subtree)
(deps %{bin:ocamlformat}))
9 changes: 9 additions & 0 deletions test/blackbox-tests/test-cases/dialects/no_impl.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]
5 changes: 5 additions & 0 deletions test/blackbox-tests/test-cases/dialects/no_intf_good.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -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]
7 changes: 7 additions & 0 deletions test/blackbox-tests/test-cases/formatting/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(env
(_
(binaries ../../utils/ocamlformat.exe)))

(cram
(applies_to :whole_subtree)
(deps %{bin:ocamlformat}))
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/formatting/feature.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions test/blackbox-tests/test-cases/formatting/no-gen.t
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions test/blackbox-tests/utils/dune
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@
(modules ocaml_index)
(name ocaml_index)
(libraries cmdliner))

(executable
(modules ocamlformat)
(name ocamlformat))
16 changes: 16 additions & 0 deletions test/blackbox-tests/utils/ocamlformat.ml
Original file line number Diff line number Diff line change
@@ -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 *)"
;;

0 comments on commit 8351ff9

Please sign in to comment.