Skip to content

Commit

Permalink
Add regression tests, fix issues with comments causing non-stability,…
Browse files Browse the repository at this point in the history
… fix issue with default modalities in empty signatures.

Signed-off-by: Thomas Del Vecchio <[email protected]>
  • Loading branch information
tdelvecchio-jsc committed Feb 3, 2025
1 parent 4b1dfb3 commit 501abe2
Show file tree
Hide file tree
Showing 19 changed files with 164 additions and 28 deletions.
4 changes: 2 additions & 2 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ and fmt_modals ?(pro = fmt "@ ") c ~ats modals =
let fmt_ats =
match ats with `Zero -> str "" | `One -> str "@ " | `Two -> str "@@ "
in
let fmt_modal {txt; loc} = Cmts.fmt c loc (str txt) in
let fmt_modal {txt; loc} = Cmts.fmt c loc (str txt) ~eol:(fmt "@ ") in
let fmt_mode {txt= Mode mode; loc} = fmt_modal {txt= mode; loc} in
let fmt_modality {txt= Modality modality; loc} =
fmt_modal {txt= modality; loc}
Expand Down Expand Up @@ -5302,7 +5302,7 @@ let fmt_file (type a) ~ctx ~fmt_code ~debug (fragment : a Extended_ast.t)
let c = {source; cmts; conf; debug; fmt_code} in
match (fragment, itms) with
| Signature, {psg_items= []; psg_modalities; _} ->
fmt_modals c ~ats:`Two (Modalities psg_modalities)
fmt_modals ~pro:noop c ~ats:`Two (Modalities psg_modalities)
$ Cmts.fmt_after ~pro:noop c Location.none
| Structure, [] | Use_file, [] -> Cmts.fmt_after ~pro:noop c Location.none
| Structure, l -> Chunk.split_and_fmt Structure c ctx l
Expand Down
74 changes: 74 additions & 0 deletions test/passing/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8563,6 +8563,80 @@
(package ocamlformat)
(action (diff tests/mod_type_subst.ml.js-err mod_type_subst.ml.js-stderr)))

(rule
(deps tests/.ocamlformat )
(package ocamlformat)
(action
(with-stdout-to modality_comments_failure.mli.stdout
(with-stderr-to modality_comments_failure.mli.stderr
(with-accepted-exit-codes 1
(run %{bin:ocamlformat} --margin-check %{dep:tests/modality_comments_failure.mli}))))))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/modality_comments_failure.mli.ref modality_comments_failure.mli.stdout)))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/modality_comments_failure.mli.err modality_comments_failure.mli.stderr)))

(rule
(deps tests/.ocamlformat )
(package ocamlformat)
(action
(with-stdout-to modality_comments_failure.mli.js-stdout
(with-stderr-to modality_comments_failure.mli.js-stderr
(with-accepted-exit-codes 1
(run %{bin:ocamlformat} --profile=janestreet --enable-outside-detected-project --disable-conf-files %{dep:tests/modality_comments_failure.mli}))))))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/modality_comments_failure.mli.js-ref modality_comments_failure.mli.js-stdout)))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/modality_comments_failure.mli.js-err modality_comments_failure.mli.js-stderr)))

(rule
(deps tests/.ocamlformat )
(package ocamlformat)
(action
(with-stdout-to modality_comments_regression.mli.stdout
(with-stderr-to modality_comments_regression.mli.stderr
(run %{bin:ocamlformat} --margin-check %{dep:tests/modality_comments_regression.mli})))))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/modality_comments_regression.mli.ref modality_comments_regression.mli.stdout)))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/modality_comments_regression.mli.err modality_comments_regression.mli.stderr)))

(rule
(deps tests/.ocamlformat )
(package ocamlformat)
(action
(with-stdout-to modality_comments_regression.mli.js-stdout
(with-stderr-to modality_comments_regression.mli.js-stderr
(run %{bin:ocamlformat} --profile=janestreet --enable-outside-detected-project --disable-conf-files %{dep:tests/modality_comments_regression.mli})))))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/modality_comments_regression.mli.js-ref modality_comments_regression.mli.js-stdout)))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/modality_comments_regression.mli.js-err modality_comments_regression.mli.js-stderr)))

(rule
(deps tests/.ocamlformat )
(package ocamlformat)
Expand Down
3 changes: 1 addition & 2 deletions test/passing/tests/default_modalities2.mli.js-ref
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@@ (* a *)

(* b *)
moda1 (* c *) moda2
(* b *) moda1 (* c *) moda2

(* d *)
val x : int
3 changes: 1 addition & 2 deletions test/passing/tests/default_modalities2.mli.ref
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
@@ (* a *)

(* b *)
moda1 (* c *) moda2
(* b *) moda1 (* c *) moda2

(* d *)
val x : int
10 changes: 7 additions & 3 deletions test/passing/tests/layout_abbreviation-erased.ml.js-ref
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,11 @@ kind_abbrev_ k =
(* 375 *)
mod
(* 382 *)
m (* 381 *) mmmmmmmmmmmmmmmmmmmmm (* 383 *) mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
m
(* 381 *)
mmmmmmmmmmmmmmmmmmmmm
(* 383 *)
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
(* 374 *)

kind_abbrev_ k =
Expand Down Expand Up @@ -1912,8 +1916,8 @@ module type S = sig
_
(* 1192 *)
(* 1191 *)
mod (* 1194 *)
mmmmmmmmmmmmm (* 1195 *) mmmmmmmmmmmmm
mod
(* 1194 *) mmmmmmmmmmmmm (* 1195 *) mmmmmmmmmmmmm
(* 1190 *)
(* 1189 *)
with (* 1196 *) tt (* 1188 *))
Expand Down
20 changes: 10 additions & 10 deletions test/passing/tests/layout_abbreviation.ml.err
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Warning: tests/layout_abbreviation.ml:2044 exceeds the margin
Warning: tests/layout_abbreviation.ml:2058 exceeds the margin
Warning: tests/layout_abbreviation.ml:2090 exceeds the margin
Warning: tests/layout_abbreviation.ml:2105 exceeds the margin
Warning: tests/layout_abbreviation.ml:2122 exceeds the margin
Warning: tests/layout_abbreviation.ml:2139 exceeds the margin
Warning: tests/layout_abbreviation.ml:2141 exceeds the margin
Warning: tests/layout_abbreviation.ml:2187 exceeds the margin
Warning: tests/layout_abbreviation.ml:2194 exceeds the margin
Warning: tests/layout_abbreviation.ml:2266 exceeds the margin
Warning: tests/layout_abbreviation.ml:2268 exceeds the margin
Warning: tests/layout_abbreviation.ml:2277 exceeds the margin
Warning: tests/layout_abbreviation.ml:2089 exceeds the margin
Warning: tests/layout_abbreviation.ml:2104 exceeds the margin
Warning: tests/layout_abbreviation.ml:2121 exceeds the margin
Warning: tests/layout_abbreviation.ml:2138 exceeds the margin
Warning: tests/layout_abbreviation.ml:2140 exceeds the margin
Warning: tests/layout_abbreviation.ml:2186 exceeds the margin
Warning: tests/layout_abbreviation.ml:2193 exceeds the margin
Warning: tests/layout_abbreviation.ml:2265 exceeds the margin
Warning: tests/layout_abbreviation.ml:2267 exceeds the margin
Warning: tests/layout_abbreviation.ml:2276 exceeds the margin
10 changes: 7 additions & 3 deletions test/passing/tests/layout_abbreviation.ml.js-ref
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,11 @@ kind_abbrev_ k =
(* 375 *)
mod
(* 382 *)
m (* 381 *) mmmmmmmmmmmmmmmmmmmmm (* 383 *) mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
m
(* 381 *)
mmmmmmmmmmmmmmmmmmmmm
(* 383 *)
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
(* 374 *)

kind_abbrev_ k =
Expand Down Expand Up @@ -1912,8 +1916,8 @@ module type S = sig
_
(* 1192 *)
(* 1191 *)
mod (* 1194 *)
mmmmmmmmmmmmm (* 1195 *) mmmmmmmmmmmmm
mod
(* 1194 *) mmmmmmmmmmmmm (* 1195 *) mmmmmmmmmmmmm
(* 1190 *)
(* 1189 *)
with (* 1196 *) tt (* 1188 *))
Expand Down
3 changes: 1 addition & 2 deletions test/passing/tests/layout_abbreviation.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -2066,8 +2066,7 @@ module type S = sig
tttttttttttttttttttt
(* 1091 *)
(* 1079 *)))
mod (* 1096 *)
mmmmmmmmmmmmmm
mod (* 1096 *) mmmmmmmmmmmmmm
(* 1078 *)
(* 1077 *)
with (* 1097 *)
Expand Down
3 changes: 1 addition & 2 deletions test/passing/tests/layout_annotation_mod.ml.js-ref
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ type a =
((* comment 1 *)
'k (* comment 2 *) :
(* comment 3 *)
immediate64 (* comment 4 *) mod (* comment 5 *)
mode (* comment 6 *))
immediate64 (* comment 4 *) mod (* comment 5 *) mode (* comment 6 *))
(* comment 7 *)

let f (type a : immediate mod mode) x = x
Expand Down
3 changes: 1 addition & 2 deletions test/passing/tests/layout_annotation_mod.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ type a =
(* comment 3 *)
immediate64
(* comment 4 *)
mod (* comment 5 *)
mode
mod (* comment 5 *) mode
(* comment 6 *))
(* comment 7 *)

Expand Down
5 changes: 5 additions & 0 deletions test/passing/tests/modality_comments_failure.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(** a *)

(** b *)

@@ a b c
6 changes: 6 additions & 0 deletions test/passing/tests/modality_comments_failure.mli.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ocamlformat: ignoring "tests/modality_comments_failure.mli" (misplaced documentation comments - warning 50)
File "tests/modality_comments_failure.mli", line 3, characters 0-8:
3 | (** b *)
^^^^^^^^
Warning 50 [unexpected-docstring]: unattached documentation comment (ignored)
Hint: (Warning 50) This file contains a documentation comment (** ... *) that the OCaml compiler does not know how to attach to the AST. OCamlformat does not support these cases. You can find more information at: https://github.com/ocaml-ppx/ocamlformat#overview. If you'd like to disable this check and let ocamlformat make a choice (though it might not be consistent with the ocaml compilers and odoc), you can set the --no-comment-check option.
6 changes: 6 additions & 0 deletions test/passing/tests/modality_comments_failure.mli.js-err
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ocamlformat: ignoring "tests/modality_comments_failure.mli" (misplaced documentation comments - warning 50)
File "tests/modality_comments_failure.mli", line 3, characters 0-8:
3 | (** b *)
^^^^^^^^
Warning 50 [unexpected-docstring]: unattached documentation comment (ignored)
Hint: (Warning 50) This file contains a documentation comment (** ... *) that the OCaml compiler does not know how to attach to the AST. OCamlformat does not support these cases. You can find more information at: https://github.com/ocaml-ppx/ocamlformat#overview. If you'd like to disable this check and let ocamlformat make a choice (though it might not be consistent with the ocaml compilers and odoc), you can set the --no-comment-check option.
Empty file.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions test/passing/tests/modality_comments_regression.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@@ mmmmmmmmm m (* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*) mmmmmmmmmm mmmmmmmmmm mmmmm mm m

val command : Command.t @@ mmmmmmmm m mmmmm mmm mmmmmmmm (* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*) mmmmmmm mmmmm mmmmmm
20 changes: 20 additions & 0 deletions test/passing/tests/modality_comments_regression.mli.js-ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@@ m
m
mm
mmmmm
mmmmmmmmm
(* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*)
mmmmmmmmmm
mmmmmmmmmm

val command
: Command.t
@@ m
mmm
mmmmm
mmmmm
mmmmmm
(* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*)
mmmmmmm
mmmmmmmm
mmmmmmmm
19 changes: 19 additions & 0 deletions test/passing/tests/modality_comments_regression.mli.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@@ m
m
mm
mmmmm
mmmmmmmmm
(* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*)
mmmmmmmmmm
mmmmmmmmmm

val command : Command.t
@@ m
mmm
mmmmm
mmmmm
mmmmmm
(* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*)
mmmmmmm
mmmmmmmm
mmmmmmmm

0 comments on commit 501abe2

Please sign in to comment.