6 use File::Temp qw(tempfile);
9 BEGIN { unshift @INC, "./" }
12 # This tests the -eos (--encode-output-strings) which was added for issue
13 # git #83 to fix an issue with tidyall.
15 # NOTE: to prevent automatic conversion of line endings LF to CRLF under github
16 # Actions with Windows, which would cause test failure, it is essential that
17 # there be a file 't/.gitattributes' with the line:
20 # The test file has no tidying needs but is UTF-8 encoded, so all passes
21 # through perltidy should read/write identical contents (previously only
22 # file test behaved correctly)
24 # Test::More in perl versions before 5.10 does not have sub note
25 # so just skip this test
34 # try to work around problem where sub Test::More::note does not exist
35 # in older versions of perl
44 my $test_file = "$Bin/testwide-passthrough.pl.src";
45 test_file2file($test_file);
46 test_scalar2scalar($test_file);
47 test_scalararray2scalararray($test_file);
51 my $test_file = shift;
53 my $tmp_file = File::Temp->new( TMPDIR => 1 );
55 my $source = $test_file;
56 my $destination = $tmp_file->filename();
58 my_note("Testing file2file: '$source' => '$destination'\n");
60 my $tidyresult = Perl::Tidy::perltidy(
61 argv => '-utf8 -npro',
63 destination => $destination
65 ok( !$tidyresult, 'perltidy' );
67 my $source_str = slurp_raw($source);
68 my $destination_str = slurp_raw($destination);
70 my $source_hex = unpack( 'H*', $source_str );
71 my $destination_hex = unpack( 'H*', $destination_str );
72 my_note("Comparing contents:\n $source_hex\n $destination_hex\n");
74 ok( $source_hex eq $destination_hex, 'file content compare' );
77 sub test_scalar2scalar {
80 my $source = slurp_raw($testfile);
83 my_note("Testing scalar2scalar\n");
85 my $tidyresult = Perl::Tidy::perltidy(
86 argv => '-utf8 -eos -npro',
88 destination => \$destination
90 ok( !$tidyresult, 'perltidy' );
92 my $source_hex = unpack( 'H*', $source );
93 my $destination_hex = unpack( 'H*', $destination );
95 my_note("Comparing contents:\n $source_hex\n $destination_hex\n");
96 ok( $source_hex eq $destination_hex, 'scalar content compare' );
99 sub test_scalararray2scalararray {
100 my $testfile = shift;
102 my $source = [ lines_raw($testfile) ];
103 my $destination = [];
105 my_note("Testing scalararray2scalararray\n");
107 my $tidyresult = Perl::Tidy::perltidy(
108 argv => '-utf8 -eos -npro',
110 destination => $destination
112 ok( !$tidyresult, 'perltidy' );
114 my $source_str = join( "", @$source );
115 my $destination_str = join( "", @$destination );
117 my $source_hex = unpack( 'H*', $source_str );
118 my $destination_hex = unpack( 'H*', $destination_str );
120 my_note("Comparing contents:\n $source_hex\n $destination_hex\n");
121 ok( $source_hex eq $destination_hex, 'scalararray content compare' );
125 my $filename = shift;
127 open( TMP, '<', $filename );
128 binmode( TMP, ':raw' );
130 my $contents = <TMP>;
137 my $filename = shift;
139 open( TMP, '<', $filename );
140 binmode( TMP, ':raw' );
141 my @contents = <TMP>;