Koha-QA
view release on metacpan or search on metacpan
t/perl_syntax.t view on Meta::CPAN
use Modern::Perl;
use Test::More tests => 7;
use Test::NoWarnings;
use File::Temp qw(tempfile);
use Koha::QA::PerlSyntax;
my $expected_messages = {};
sub check_syntax {
my ( $content, $params ) = @_;
$params ||= {};
my $checker = Koha::QA::PerlSyntax->new( { content => $content, %$params } );
$checker->check();
return $checker->errors();
}
subtest 'Valid Perl code in content' => sub {
plan tests => 1;
my $input = <<'INPUT';
use strict;
use warnings;
my $x = 1;
print "hello\n";
INPUT
my @errors = check_syntax($input);
is( scalar @errors, 0, 'Valid Perl code should have no errors' );
};
subtest 'Valid Perl code in file' => sub {
plan tests => 1;
my ( $fh, $filename ) = tempfile( UNLINK => 0, TEMPDIR => 1, SUFFIX => '.pl' );
print $fh <<'INPUT';
use strict;
use warnings;
my $x = 1;
print "hello\n";
INPUT
close $fh;
my $checker = Koha::QA::PerlSyntax->new( { file => $filename } );
my $is_valid = $checker->check();
my @errors = $checker->errors();
is( $is_valid, 1, 'Valid file should pass syntax check' );
unlink $filename;
};
subtest 'Syntax error - missing semicolon' => sub {
plan tests => 5;
my $input = <<'INPUT';
use strict;
use warnings;
my $x = 1
print "hello";
my @array = (1, 2, 3;
INPUT
( run in 1.110 second using v1.01-cache-2.11-cpan-eb134014566 )