From b6de65c49ce4e397cae1a8ea3e1a8e155134e14a Mon Sep 17 00:00:00 2001 From: Chad Granum Date: Mon, 2 Sep 2024 16:26:31 -0700 Subject: [PATCH] Add comment if table it too small, fixes #931 --- Changes | 2 ++ lib/Test2/Formatter/TAP.pm | 8 +++++++- t/Test2/modules/Formatter/TAP.t | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 9f3001e7f..3fa537b20 100644 --- a/Changes +++ b/Changes @@ -6,6 +6,8 @@ {{$NEXT}} + - Add comment on how to make tables bigger, #931 + 1.302201 2024-08-13 08:19:01-07:00 America/Los_Angeles - Fix bug found by new warnings in blead (Thanks Mauke) diff --git a/lib/Test2/Formatter/TAP.pm b/lib/Test2/Formatter/TAP.pm index e3706d921..bbfb9d542 100644 --- a/lib/Test2/Formatter/TAP.pm +++ b/lib/Test2/Formatter/TAP.pm @@ -384,6 +384,8 @@ sub info_tap { my $msg; if ($table && $self->supports_tables) { + my $size = $self->calc_table_size($f); + $msg = join "\n" => map { "# $_" } Term::Table->new( header => $table->{header}, rows => $table->{rows}, @@ -391,8 +393,12 @@ sub info_tap { no_collapse => $table->{no_collapse}, sanitize => 1, mark_tail => 1, - max_width => $self->calc_table_size($f), + max_width => $size, )->render(); + + $msg .= "\n(If this table is too small, you can use the TABLE_TERM_SIZE=### env var to set a larger size, detected size is '$size')\n" + if $size <= 80 + && !$ENV{TABLE_TERM_SIZE}; } elsif (ref($details)) { require Data::Dumper; diff --git a/t/Test2/modules/Formatter/TAP.t b/t/Test2/modules/Formatter/TAP.t index 43ec086d1..d279e881a 100644 --- a/t/Test2/modules/Formatter/TAP.t +++ b/t/Test2/modules/Formatter/TAP.t @@ -6,6 +6,8 @@ use warnings; my $CLASS; my %BEFORE_LOAD; +local $ENV{TABLE_TERM_SIZE} = 80; + BEGIN { my $old = select STDOUT; $BEFORE_LOAD{STDOUT} = $|;