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 is UTF-8 encoded
27 my $test_file = "$Bin/testwide-tidy.pl.src";
28 my $tidy_file = "$Bin/testwide-tidy.pl.srctdy";
29 my $tidy_str = slurp_raw($tidy_file);
30 test_file2file( $test_file, $tidy_str );
31 test_scalar2scalar( $test_file, $tidy_str );
32 test_scalararray2scalararray( $test_file, $tidy_str );
36 my $test_file = shift;
38 my $tidy_hex = unpack( 'H*', $tidy_str );
40 my $tmp_file = File::Temp->new( TMPDIR => 1 );
42 my $source = $test_file;
43 my $destination = $tmp_file->filename();
45 note("Testing file2file: '$source' => '$destination'\n");
47 my $tidyresult = Perl::Tidy::perltidy(
50 destination => $destination
52 ok( !$tidyresult, 'perltidy' );
54 my $destination_str = slurp_raw($destination);
55 my $destination_hex = unpack( 'H*', $destination_str );
57 note("Comparing contents:\n $tidy_hex\n $destination_hex\n");
58 ok($tidy_hex eq $destination_hex, 'file content compare');
62 sub test_scalar2scalar {
63 my $test_file = shift;
65 my $tidy_hex = unpack( 'H*', $tidy_str );
67 my $source = slurp_raw($test_file);
70 note("Testing scalar2scalar\n");
72 my $tidyresult = Perl::Tidy::perltidy(
75 destination => \$destination
77 ok( !$tidyresult, 'perltidy' );
79 my $destination_hex = unpack( 'H*', $destination );
81 note("Comparing contents:\n $tidy_hex\n $destination_hex\n");
82 ok($tidy_hex eq $destination_hex, 'scalar content compare');
86 sub test_scalararray2scalararray {
87 my $test_file = shift;
89 my $tidy_hex = unpack( 'H*', $tidy_str );
91 my $source = [ lines_raw($test_file) ];
94 note("Testing scalararray2scalararray\n");
96 my $tidyresult = Perl::Tidy::perltidy(
99 destination => $destination
101 ok( !$tidyresult, 'perltidy' );
103 my $destination_str = join( '', @$destination );
104 my $destination_hex = unpack( 'H*', $destination_str );
106 note("Comparing contents:\n $tidy_hex\n $destination_hex\n");
107 ok($tidy_hex eq $destination_hex, 'scalararray content compare');
111 my $filename = shift;
113 open( TMP, '<', $filename );
114 binmode( TMP, ':raw' );
116 my $contents = <TMP>;
123 my $filename = shift;
125 open( TMP, '<', $filename );
126 binmode( TMP, ':raw' );
127 my @contents = <TMP>;