Skip to content

Commit 5d05171

Browse files
RFC: Make it possible to disable line wrapping in tests (#10841)
* feat(test): Make it possible to disable line wrapping Sometimes cram tests are not reproducible if different platforms output different length errors, in which case even editing out the errors with common tools like `sed` does not help as the wrapping happens before the `sed` invocation runs, thus the message is split over multiple lines. This introduces an option to disable the automatic wrapping of lines. --------- Signed-off-by: Marek Kubica <[email protected]>
1 parent 1062748 commit 5d05171

File tree

7 files changed

+65
-0
lines changed

7 files changed

+65
-0
lines changed

otherlibs/stdune/src/ansi_color.ml

+8
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,13 @@ let rec tag_handler buf current_styles ppf (styles : Style.t list) pp =
494494
(Style.escape_sequence_buf buf (current_styles :> Style.t list))
495495
;;
496496

497+
let skip_line_break =
498+
lazy
499+
(match Sys.getenv_opt "DUNE_CONFIG__SKIP_LINE_BREAK" with
500+
| Some "enabled" -> true
501+
| _ -> false)
502+
;;
503+
497504
let make_printer supports_color ppf =
498505
let f =
499506
lazy
@@ -504,6 +511,7 @@ let make_printer supports_color ppf =
504511
else Pp.to_fmt ppf)
505512
in
506513
Staged.stage (fun pp ->
514+
if Lazy.force skip_line_break then Format.pp_set_margin ppf Format.pp_infinity;
507515
Lazy.force f pp;
508516
Format.pp_print_flush ppf ())
509517
;;

otherlibs/stdune/src/format.ml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(* added in OCaml 5.2 *)
2+
let[@warning "-32"] pp_infinity = Int.max_int
3+
4+
include Stdlib.Format

otherlibs/stdune/src/format.mli

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
val pp_infinity : int
2+
3+
include module type of Stdlib.Format

otherlibs/stdune/src/int.ml

+1
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ module Infix = Comparator.Operators (T)
4747
let of_string s = int_of_string_opt s
4848
let shift_left = Stdlib.Int.shift_left
4949
let shift_right = Stdlib.Int.shift_right
50+
let max_int = Stdlib.Int.max_int

otherlibs/stdune/src/int.mli

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ module Infix : Comparator.OPS with type t = t
1515

1616
val shift_left : t -> t -> t
1717
val shift_right : t -> t -> t
18+
val max_int : t

otherlibs/stdune/src/stdune.ml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Exn = Exn
1313
module Exn_with_backtrace = Exn_with_backtrace
1414
module Filename = Filename
1515
module Filename_set = Filename_set
16+
module Format = Format
1617
module Hashtbl = Hashtbl
1718
module Table = Table
1819
module Int = Int
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
Test the behavior of long lines
2+
3+
In the default output, user input affects on which lines which of the output
4+
lines appear. For example, with a short project name, the line wraps later:
5+
6+
$ cat > dune-project <<EOF
7+
> (lang dune 3.17)
8+
> (package
9+
> (name short))
10+
> EOF
11+
$ dune build
12+
Error: The package short does not have any user defined stanzas attached to
13+
it. If this is intentional, add (allow_empty) to the package definition in
14+
the dune-project file
15+
-> required by _build/default/short.install
16+
-> required by alias all
17+
-> required by alias default
18+
[1]
19+
20+
With a long project name, there are less words on the line and thus it wraps in
21+
a different position:
22+
23+
$ cat > dune-project <<EOF
24+
> (lang dune 3.17)
25+
> (package
26+
> (name verylongnamethatcauseslinewrappingincases))
27+
> EOF
28+
$ dune build
29+
Error: The package verylongnamethatcauseslinewrappingincases does not have
30+
any user defined stanzas attached to it. If this is intentional, add
31+
(allow_empty) to the package definition in the dune-project file
32+
-> required by
33+
_build/default/verylongnamethatcauseslinewrappingincases.install
34+
-> required by alias all
35+
-> required by alias default
36+
[1]
37+
38+
Disabling line breaks should thus only break lines where there are explicit
39+
line breaks in the input and not when the line gets too long.
40+
41+
$ export DUNE_CONFIG__SKIP_LINE_BREAK=enabled
42+
$ dune build
43+
Error: The package verylongnamethatcauseslinewrappingincases does not have any user defined stanzas attached to it. If this is intentional, add (allow_empty) to the package definition in the dune-project file
44+
-> required by _build/default/verylongnamethatcauseslinewrappingincases.install
45+
-> required by alias all
46+
-> required by alias default
47+
[1]

0 commit comments

Comments
 (0)