Skip to content

Commit

Permalink
[topfmt] Set formatter + flush fix
Browse files Browse the repository at this point in the history
Closes #12351.

We set the parameters of the redirect formatter to be same than the
ones in stdout.

I guess the original semantics was to ignore the parameters, so I'm
unsure we want to do this.

While we are a it, we include a fix on the formatter, which _must_ be
flushed before closing its associated channel.

(cherry picked from commit fb0caf1)
  • Loading branch information
ejgallego authored and Zimmi48 committed May 23, 2020
1 parent 50ee793 commit cdd7c6e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- **Changed:**
:cmd:Redirect now obeys the :opt:`Printing Width` and
:opt:`Printing Depth` flags.
(`#12358 <https://github.com/coq/coq/pull/12358>`_,
by Emilio Jesus Gallego Arias).
2 changes: 2 additions & 0 deletions test-suite/misc/redirect_printing.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nat_ind
: forall P : nat -> Prop, P 0 -> (forall n : nat, P n -> P (S n)) -> forall n : nat, P n
4 changes: 4 additions & 0 deletions test-suite/misc/redirect_printing.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

$coqc misc/redirect_printing.v
diff -u redirect_test.out misc/redirect_printing.out
2 changes: 2 additions & 0 deletions test-suite/misc/redirect_printing.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Set Printing Width 999999.
Redirect "redirect_test" Check nat_ind.
3 changes: 3 additions & 0 deletions vernac/topfmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ let with_output_to_file fname func input =
let channel = open_out (String.concat "." [fname; "out"]) in
let old_fmt = !std_ft, !err_ft, !deep_ft in
let new_ft = Format.formatter_of_out_channel channel in
set_gp new_ft (get_gp !std_ft);
std_ft := new_ft;
err_ft := new_ft;
deep_ft := new_ft;
Expand All @@ -412,13 +413,15 @@ let with_output_to_file fname func input =
std_ft := Util.pi1 old_fmt;
err_ft := Util.pi2 old_fmt;
deep_ft := Util.pi3 old_fmt;
Format.pp_print_flush new_ft ();
close_out channel;
output
with reraise ->
let reraise = Exninfo.capture reraise in
std_ft := Util.pi1 old_fmt;
err_ft := Util.pi2 old_fmt;
deep_ft := Util.pi3 old_fmt;
Format.pp_print_flush new_ft ();
close_out channel;
Exninfo.iraise reraise

Expand Down

0 comments on commit cdd7c6e

Please sign in to comment.