Skip to content

Commit

Permalink
RFC: Make it possible to disable line wrapping in tests (#10841)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Leonidas-from-XIV authored Aug 23, 2024
1 parent 1062748 commit 5d05171
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions otherlibs/stdune/src/ansi_color.ml
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,13 @@ let rec tag_handler buf current_styles ppf (styles : Style.t list) pp =
(Style.escape_sequence_buf buf (current_styles :> Style.t list))
;;

let skip_line_break =
lazy
(match Sys.getenv_opt "DUNE_CONFIG__SKIP_LINE_BREAK" with
| Some "enabled" -> true
| _ -> false)
;;

let make_printer supports_color ppf =
let f =
lazy
Expand All @@ -504,6 +511,7 @@ let make_printer supports_color ppf =
else Pp.to_fmt ppf)
in
Staged.stage (fun pp ->
if Lazy.force skip_line_break then Format.pp_set_margin ppf Format.pp_infinity;
Lazy.force f pp;
Format.pp_print_flush ppf ())
;;
Expand Down
4 changes: 4 additions & 0 deletions otherlibs/stdune/src/format.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(* added in OCaml 5.2 *)
let[@warning "-32"] pp_infinity = Int.max_int

include Stdlib.Format
3 changes: 3 additions & 0 deletions otherlibs/stdune/src/format.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
val pp_infinity : int

include module type of Stdlib.Format
1 change: 1 addition & 0 deletions otherlibs/stdune/src/int.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ module Infix = Comparator.Operators (T)
let of_string s = int_of_string_opt s
let shift_left = Stdlib.Int.shift_left
let shift_right = Stdlib.Int.shift_right
let max_int = Stdlib.Int.max_int
1 change: 1 addition & 0 deletions otherlibs/stdune/src/int.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ module Infix : Comparator.OPS with type t = t

val shift_left : t -> t -> t
val shift_right : t -> t -> t
val max_int : t
1 change: 1 addition & 0 deletions otherlibs/stdune/src/stdune.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Exn = Exn
module Exn_with_backtrace = Exn_with_backtrace
module Filename = Filename
module Filename_set = Filename_set
module Format = Format
module Hashtbl = Hashtbl
module Table = Table
module Int = Int
Expand Down
47 changes: 47 additions & 0 deletions test/blackbox-tests/test-cases/long-lines.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Test the behavior of long lines

In the default output, user input affects on which lines which of the output
lines appear. For example, with a short project name, the line wraps later:

$ cat > dune-project <<EOF
> (lang dune 3.17)
> (package
> (name short))
> EOF
$ dune build
Error: The package short 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
-> required by _build/default/short.install
-> required by alias all
-> required by alias default
[1]

With a long project name, there are less words on the line and thus it wraps in
a different position:

$ cat > dune-project <<EOF
> (lang dune 3.17)
> (package
> (name verylongnamethatcauseslinewrappingincases))
> EOF
$ dune build
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
-> required by
_build/default/verylongnamethatcauseslinewrappingincases.install
-> required by alias all
-> required by alias default
[1]

Disabling line breaks should thus only break lines where there are explicit
line breaks in the input and not when the line gets too long.

$ export DUNE_CONFIG__SKIP_LINE_BREAK=enabled
$ dune build
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
-> required by _build/default/verylongnamethatcauseslinewrappingincases.install
-> required by alias all
-> required by alias default
[1]

0 comments on commit 5d05171

Please sign in to comment.