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)
29 my $test_file = "$Bin/testwide-passthrough.pl.src";
30 test_file2file($test_file);
31 test_scalar2scalar($test_file);
32 test_scalararray2scalararray($test_file);
36 my $test_file = shift;
38 my $tmp_file = File::Temp->new( TMPDIR => 1 );
40 my $source = $test_file;
41 my $destination = $tmp_file->filename();
43 note("Testing file2file: '$source' => '$destination'\n");
45 my $tidyresult = Perl::Tidy::perltidy(
46 argv => '-utf8 -npro',
48 destination => $destination
50 ok( !$tidyresult, 'perltidy' );
52 my $source_str = slurp_raw($source);
53 my $destination_str = slurp_raw($destination);
55 my $source_hex = unpack( 'H*', $source_str );
56 my $destination_hex = unpack( 'H*', $destination_str );
57 note("Comparing contents:\n $source_hex\n $destination_hex\n");
59 ok( $source_hex eq $destination_hex, 'file content compare' );
62 sub test_scalar2scalar {
65 my $source = slurp_raw($testfile);
68 note("Testing scalar2scalar\n");
70 my $tidyresult = Perl::Tidy::perltidy(
71 argv => '-utf8 -eos -npro',
73 destination => \$destination
75 ok( !$tidyresult, 'perltidy' );
77 my $source_hex = unpack( 'H*', $source );
78 my $destination_hex = unpack( 'H*', $destination );
80 note("Comparing contents:\n $source_hex\n $destination_hex\n");
81 ok( $source_hex eq $destination_hex, 'scalar content compare' );
84 sub test_scalararray2scalararray {
87 my $source = [ lines_raw($testfile) ];
90 note("Testing scalararray2scalararray\n");
92 my $tidyresult = Perl::Tidy::perltidy(
93 argv => '-utf8 -eos -npro',
95 destination => $destination
97 ok( !$tidyresult, 'perltidy' );
99 my $source_str = join( "", @$source );
100 my $destination_str = join( "", @$destination );
102 my $source_hex = unpack( 'H*', $source_str );
103 my $destination_hex = unpack( 'H*', $destination_str );
105 note("Comparing contents:\n $source_hex\n $destination_hex\n");
106 ok( $source_hex eq $destination_hex, 'scalararray content compare' );
110 my $filename = shift;
112 open( TMP, '<', $filename );
113 binmode( TMP, ':raw' );
115 my $contents = <TMP>;
122 my $filename = shift;
124 open( TMP, '<', $filename );
125 binmode( TMP, ':raw' );
126 my @contents = <TMP>;