Skip to content

Commit

Permalink
Do not re-format Qtest comments (#2034)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetiot authored Mar 4, 2022
1 parent ddca4a3 commit 9193d71
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

#### Changes

+ Qtest comments are not re-formatted (#2034, @gpetiot)

#### New features

+ New syntax `(*= ... *)` for verbatim comments (#2028, @gpetiot)
+ New syntax `(*= ... *)` for verbatim comments (#2028, @gpetiot)

### 0.21.0 (2022-02-25)

Expand Down
3 changes: 3 additions & 0 deletions lib/Cmts.ml
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,9 @@ let fmt_cmt (cmt : Cmt.t) ~wrap:wrap_comments ~ocp_indent_compat ~fmt_code
| "*" when Location.width cmt.loc = 4 -> `Verbatim ""
| "*" -> `Verbatim "*"
| "$" -> `Verbatim "$"
(* Qtest pragmas *)
| str when Char.(str.[0] = '$' && not (is_whitespace str.[1])) ->
`Verbatim str
| str when Char.equal str.[0] '$' -> (
let dollar_suf = Char.equal str.[String.length str - 1] '$' in
let cls : Fmt.s = if dollar_suf then "$*)" else "*)" in
Expand Down
18 changes: 18 additions & 0 deletions test/passing/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4213,6 +4213,24 @@
(package ocamlformat)
(action (diff tests/protected_object_types.ml.err protected_object_types.ml.stderr)))

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

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/qtest.ml qtest.ml.stdout)))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/qtest.ml.err qtest.ml.stderr)))

(rule
(deps tests/.ocamlformat )
(package ocamlformat)
Expand Down
59 changes: 59 additions & 0 deletions test/passing/tests/qtest.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
(*$T
false
*)

(*$T foo
foo 0 ( + ) [1;2;3] = 6 (* hehe *)
foo 0 ( * ) [1;2;3] = 0 (* haha (*hoho *) *)
foo 1 ( * ) [4;5] = 20
foo 12 ( + ) [] = 12
*)

(*$T foo
foo 1 ( * ) [4;5] = foo 2 ( * ) [1;5;2]
*)

(*$= foo & ~printer:string_of_int
(foo 1 ( * ) [4;5]) (foo 2 ( * ) [1;5;2])
*)

(*$Q foo
Q.small_int (fun i-> foo i (+) [1;2;3] = List.fold_left (+) i [1;2;3])
(Q.pair Q.small_int (Q.list Q.small_int)) (fun (i,l)-> foo i (+) l = List.fold_left (+) i l)
*)

(*$R foo
let thing = foo 1 ( * )
and li = [4;5] in
assert_bool "something_witty" (thing li = 20);
(* pertinent comment *)
assert_bool "something_wittier" (1=1)
*)

(*$inject let brom = baz *)
(*$T brom
brom.[2] = 'z'
*)

(*$T &
1 = 2-1
2+3 \
= \
\
5
1+1=2
*)

(*$T & 6 \
& =
2*3
*)

(*$Q & ~count:10
(Q.small_int_corners ()) (fun n-> n+3 -2 -1 = abs n)
*)

(*$Q & ~max_gen:1000000 ~count:1000000
(Q.make (fun _ -> ())) (fun () -> true)
*)
1 change: 1 addition & 0 deletions test/passing/tests/qtest.ml.err
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warning: tests/qtest.ml:21 exceeds the margin

0 comments on commit 9193d71

Please sign in to comment.