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
29 # work around problem where sub Test::More::note does not exist
30 # in older versions of perl
38 my $test_file = "$Bin/testwide-tidy.pl.src";
39 my $tidy_file = "$Bin/testwide-tidy.pl.srctdy";
40 my $tidy_str = slurp_raw($tidy_file);
41 test_file2file( $test_file, $tidy_str );
42 test_scalar2scalar( $test_file, $tidy_str );
43 test_scalararray2scalararray( $test_file, $tidy_str );
47 my $test_file = shift;
49 my $tidy_hex = unpack( 'H*', $tidy_str );
51 my $tmp_file = File::Temp->new( TMPDIR => 1 );
53 my $source = $test_file;
54 my $destination = $tmp_file->filename();
56 my_note("Testing file2file: '$source' => '$destination'\n");
58 my $tidyresult = Perl::Tidy::perltidy(
59 argv => '-utf8 -npro',
61 destination => $destination
63 ok( !$tidyresult, 'perltidy' );
65 my $destination_str = slurp_raw($destination);
66 my $destination_hex = unpack( 'H*', $destination_str );
68 my_note("Comparing contents:\n $tidy_hex\n $destination_hex\n");
69 ok($tidy_hex eq $destination_hex, 'file content compare');
73 sub test_scalar2scalar {
74 my $test_file = shift;
76 my $tidy_hex = unpack( 'H*', $tidy_str );
78 my $source = slurp_raw($test_file);
81 my_note("Testing scalar2scalar\n");
83 my $tidyresult = Perl::Tidy::perltidy(
84 argv => '-utf8 -eos -npro',
86 destination => \$destination
88 ok( !$tidyresult, 'perltidy' );
90 my $destination_hex = unpack( 'H*', $destination );
92 my_note("Comparing contents:\n $tidy_hex\n $destination_hex\n");
93 ok($tidy_hex eq $destination_hex, 'scalar content compare');
97 sub test_scalararray2scalararray {
98 my $test_file = shift;
100 my $tidy_hex = unpack( 'H*', $tidy_str );
102 my $source = [ lines_raw($test_file) ];
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 $destination_str = join( '', @$destination );
115 my $destination_hex = unpack( 'H*', $destination_str );
117 my_note("Comparing contents:\n $tidy_hex\n $destination_hex\n");
118 ok($tidy_hex eq $destination_hex, 'scalararray content compare');
122 my $filename = shift;
124 open( TMP, '<', $filename );
125 binmode( TMP, ':raw' );
127 my $contents = <TMP>;
134 my $filename = shift;
136 open( TMP, '<', $filename );
137 binmode( TMP, ':raw' );
138 my @contents = <TMP>;