From 0cad8334b4878ccb683a4913b1f1f0dcff7c754e Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Sun, 23 Aug 2020 15:33:58 -0700 Subject: [PATCH] Add test for RT #133166, RT #133171, git #35; encoded -st output --- t/testwide.t | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/t/testwide.t b/t/testwide.t index 7f7e3e72..f194d0ed 100755 --- a/t/testwide.t +++ b/t/testwide.t @@ -4,7 +4,7 @@ use Test; use Carp; use FindBin; BEGIN {unshift @INC, "./"} -BEGIN {plan tests => 2} +BEGIN {plan tests => 3} use Perl::Tidy; @@ -48,3 +48,34 @@ Perl::Tidy::perltidy( ok($output, $expected_output); +# Test writing encoded output to stdout with the -st flag +# References: RT #133166, RT #133171, git #35 +$output = ""; +do { + + # Send STDOUT to a temporary file + use File::Temp (); + my $fh = new File::Temp(); + my $tmpfile = $fh->filename; + + # Note that we are not specifying an encoding here. Perltidy should do that. + local *STDOUT; + open STDOUT, '>', $tmpfile or die "Can't open tmpfile: $!"; + + Perl::Tidy::perltidy( + source => \$source, + ##destination => ... we are using -st, so no destination is specified + perltidyrc => \$perltidyrc, + argv => '-nsyn -st', # added -st + ); + close STDOUT; + + # Read the temporary file back in. Note that here we need to specify + # the encoding. + open TMP, '<', $tmpfile; + binmode TMP, ":raw:encoding(UTF-8)"; + while ( my $line = ) { $output .= $line } +}; + +ok($output, $expected_output); + -- 2.39.5