Subject: | check-syntax, warning-output with non files (SCALAR ref, Handle, etc) |
Date: | Wed, 22 Oct 2008 20:22:15 -0400 |
To: | bug-Perl-Tidy [...] rt.cpan.org, perltidy [...] users.sourceforge.net |
From: | Charles Alderman <charlie-perl [...] aldermania.com> |
Hello,
I think I encountered a bug in the Perl::Tidy module. I get errors
with the check-syntax and warning-output flags enabled when I use a
scalar ref as the source or dest of perltidy.
I included a test case to illustrate.
Thanks,
Charles Alderman
----
use strict;
use warnings;
use Test::More tests => 5;
use IO::File;
use IO::String;
use Perl::Tidy;
my $perltidy_rc = q{
--check-syntax
--warning-output
};
my ( %scalar, %handle );
sub reset_test {
%scalar = (
source => q{ sub test{ return 42; } },
dest => '',
errors => '',
stderr => '',
);
%handle = map { $_ => IO::String->new( $scalar{$_} ) } keys %scalar;
}
reset_test();
my $temp_source_file = 'temp_source.pl';
my $temp_dest_file = 'temp_dest.pl';
my $fh = IO::File->new( $temp_source_file, '>' );
$fh->print( $scalar{source} );
$fh->close;
# baseline should pass ok - for my sanity
Perl::Tidy::perltidy(
perltidyrc => \$perltidy_rc,
source => $temp_source_file,
destination => $temp_dest_file,
stderr => $handle{stderr},
errorfile => $handle{errors},
);
diag $scalar{errors} if $scalar{errors};
ok( !$scalar{errors},
'check-syntax, warning-output: no errors with source/dest as files' );
reset_test();
# ERROR 1 - source is a handle (a SCALAR ref would give the same error)
Perl::Tidy::perltidy(
perltidyrc => \$perltidy_rc,
source => $handle{source},
destination => $temp_dest_file,
stderr => $handle{stderr},
errorfile => $handle{errors},
);
ok( !$scalar{errors},
'check-syntax, warning-output: no errors with IO::Handle for source' );
unlike(
$scalar{errors},
qr{Can't open perl script "IO::String"},
'check-syntax, warning-output: test for specific error. IO::String source'
);
reset_test();
# ERROR 2 - dest is a SCALAR ref
Perl::Tidy::perltidy(
perltidyrc => \$perltidy_rc,
source => $temp_source_file,
destination => \$scalar{dest},
stderr => $handle{stderr},
errorfile => $handle{errors},
);
ok( !$scalar{errors},
'check-syntax, warning-output: no errors with SCALAR ref for dest' );
unlike(
$scalar{errors},
qr{Oops, you seem to have encountered a bug in perltidy.},
'check-syntax, warning-output: test for specific error. SCALAR ref dest'
);
unlink $temp_source_file, $temp_dest_file;