]> iEval git - gruntmaster-daemon.git/commitdiff
Add perlcritic test and make code comply
authorMarius Gavrilescu <marius@ieval.ro>
Thu, 22 Jan 2015 22:18:09 +0000 (00:18 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Thu, 22 Jan 2015 22:18:15 +0000 (00:18 +0200)
12 files changed:
MANIFEST
lib/Gruntmaster/Daemon.pm
lib/Gruntmaster/Daemon/Constants.pm
lib/Gruntmaster/Daemon/Format.pm
lib/Gruntmaster/Daemon/Generator/File.pm
lib/Gruntmaster/Daemon/Generator/Undef.pm
lib/Gruntmaster/Daemon/Judge/Points.pm
lib/Gruntmaster/Daemon/Runner/File.pm
lib/Gruntmaster/Daemon/Runner/Interactive.pm
lib/Gruntmaster/Daemon/Runner/Verifier.pm
t/perlcritic.t [new file with mode: 0644]
t/perlcriticrc [new file with mode: 0644]

index d3f7e1b6762bd576d9f13ba9121d8d547a1dc705..469cb5d0e7e45ee15af2be8b604c5d9c33ece80d 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -25,6 +25,8 @@ selinux/gruntmasterd.fc
 selinux/gruntmasterd.te
 t/00-compile.t
 t/01-jobs.t
+t/perlcriticrc
+t/perlcritic.t
 t/problems/aminusb/1.in
 t/problems/aminusb/2.in
 t/problems/aminusb/3.in
index 1d1ca01f9544c895168dd27e7ed356c3af2cebaf..64f82312df71b5edde5d6e4dde3c0003e76be960 100644 (file)
@@ -40,8 +40,7 @@ my $db;
 sub safe_can_nodie {
        my ($type, $sub, $name) = @_;
 
-       return unless $name =~ /^\w+$/;
-       no strict 'refs';
+       return unless $name =~ /^\w+$/s;
        my $pkg = __PACKAGE__ . "::${type}::${name}";
        eval "require $pkg" or get_logger->warn("Error while requiring $pkg: $@");
        $pkg->can($sub);
@@ -87,7 +86,7 @@ sub process{
                prepare_files $meta;
                chomp $errors;
 
-               my ($files, $generator, $runner, $judge, $testcnt) = map { $meta->{$_} or die "Required parameter missing: $_"} qw/files generator runner judge testcnt/;
+               my ($files, $generator, $runner, $judge, $testcnt) = map { $meta->{$_} or die "Required parameter missing: $_\n"} qw/files generator runner judge testcnt/;
 
                $generator = safe_can Generator => generate => $generator;
                $runner = safe_can Runner => run => $runner;
@@ -122,14 +121,14 @@ sub process{
                $meta->{$_} = $results{$_} for keys %results;
                $meta->{results} = \@full_results
        } catch {
-               s,(.*) at .*,$1,;
+               s/(.*) at .*/$1/s;
                chomp;
                $meta->{result} = -1;
                $meta->{result_text} = $_;
        };
        stopvms;
 
-       get_logger->info("Job result: " . $meta->{result_text});
+       get_logger->info('Job result: ' . $meta->{result_text});
        return unless $jobr;
        $jobr->update({
                result => $meta->{result},
index c64f57ae0f4bc40fb8b5c36b2847cc453a79a27d..0ffe114eac2daaf2457b618d2a6b4a180dc54552 100644 (file)
@@ -5,9 +5,9 @@ use strict;
 use warnings;
 use parent qw/Exporter/;
 
-our $VERSION = "5999.000_004";
+our $VERSION = '5999.000_004';
 
-use constant +{
+use constant +{ ## no critic (Capitalization)
        # Accepted
        AC => 0,
 
index 5f503a117a534a4749294611034e2315dc8ebe93..a51b6cb66ea6fc6ce3bff0b6a123ca9404e480d9 100644 (file)
@@ -15,7 +15,7 @@ use POSIX qw/mkfifo/;
 use String::ShellQuote qw/shell_quote/;
 use Try::Tiny;
 
-our $VERSION = "5999.000_004";
+our $VERSION = '5999.000_004';
 our @EXPORT_OK = qw/prepare_files stopvms/;
 
 ##################################################
@@ -47,11 +47,11 @@ sub execlist {
                get_logger->trace("Running in VM $vm: $cmd");
                $vm{$vm}->send($cmd);
        } else {
-               my $ret = fork // die 'Cannot fork';
+               my $ret = fork // die "Cannot fork\n";
                if ($ret) {
                        waitpid $ret, 0;
                } else {
-                       open STDOUT, ">$er";
+                       open STDOUT, '>', $er or die "Cannot open $er\n";
                        exec 'gruntmaster-exec', @args;
                }
        }
@@ -59,9 +59,9 @@ sub execlist {
        die "gruntmaster-exec died\n" if -z $er;
        my ($excode, $exmsg) = read_file $er;
        unlink $er;
-       chomp ($excode, $exmsg);
+       chomp ($excode, $exmsg); ## no critic (ProhibitParensWithBuiltins)
        get_logger->trace("Exec result: $excode $exmsg");
-       die [$excode, $exmsg] if $excode > 0;
+       die [$excode, $exmsg] if $excode > 0; ## no critic (RequireCarping)
 }
 
 sub command_and_args{
@@ -83,7 +83,7 @@ sub mkrun{
                local *__ANON__ = 'mkrun_runner';
                my ($name, %args) = @_;
                get_logger->trace("Running $name...");
-               my $basename = fileparse $name, qr/\.[^.]*/;
+               my $basename = fileparse $name, qr/[.][^.]*/s;
                my @args;
                push @args, '--timeout', $args{timeout} if $args{timeout};
                push @args, '--mlimit',  $args{mlimit}  if $args{mlimit};
index be10f26f2730423db0c44902d46495c145b2149f..c5023a75790e21e772cb65f5334c876687a0cc40 100644 (file)
@@ -8,7 +8,7 @@ use File::Copy qw/copy/;
 use File::Slurp qw/write_file/;
 use Log::Log4perl qw/get_logger/;
 
-our $VERSION = "5999.000_004";
+our $VERSION = '5999.000_004';
 
 ##################################################
 
index 649a5d83b9da1b268d54808186aa107951d56162..3a30f7af6eb4496454e4946601a2951001b0311f 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 
 use Log::Log4perl qw/get_logger/;
 
-our $VERSION = "5999.000_004";
+our $VERSION = '5999.000_004';
 
 ##################################################
 
index 26c19f9ab42ba2aee551b535f60d8264290285b6..66286b22806d4c3cdb35c3bf161355f79f30848e 100644 (file)
@@ -13,7 +13,7 @@ our $VERSION = '5999.000_004';
 ##################################################
 
 sub judge{
-       no warnings qw/numeric/;
+       no warnings qw/numeric/; ## no critic (ProhibitNoWarnings)
        get_logger->trace("Judging results: @_");
        my $points = sum 0, grep { !ref } @_;
        $points == 100 ? (result => AC, result_text => 'Accepted') : (result => REJ, result_text => "$points points", points => $points)
index a79500cd364cb01c68957790174fff0afc11aa53..386b02c00b178886be8b04d365516205ad2fe10d 100644 (file)
@@ -3,12 +3,13 @@ package Gruntmaster::Daemon::Runner::File;
 use 5.014000;
 use strict;
 use warnings;
+use re '/s';
 
 use Gruntmaster::Daemon::Constants qw/WA/;
 use File::Slurp qw/slurp/;
 use Log::Log4perl qw/get_logger/;
 
-our $VERSION = "5999.000_004";
+our $VERSION = '5999.000_004';
 
 ##################################################
 
@@ -31,7 +32,7 @@ sub run{
        $out =~ s/\s+$//;
        $ok  =~ s/\s+$//;
 
-       die [WA, "Wrong answer"] if $out ne $ok;
+       die [WA, 'Wrong answer'] if $out ne $ok; ## no critic (RequireCarping)
        $meta->{tests}[$test - 1] // 0
 }
 
index 1825fcdfa384bb3132afa7189b03e0c7983d7076..dfdf95b5982e93c4a540c555e1690f80db91c97e 100644 (file)
@@ -18,8 +18,8 @@ sub run{
        my ($test, $meta) = @_;
        get_logger->trace("Running on test $test...");
 
-       mkfifo 'fifo1', 0600 or die $! unless -e 'fifo1';
-       mkfifo 'fifo2', 0600 or die $! unless -e 'fifo2';
+       mkfifo 'fifo1', 0600 or die "$!\n" unless -e 'fifo1';
+       mkfifo 'fifo2', 0600 or die "$!\n" unless -e 'fifo2';
 
        if ($test == 1 && $ENV{GRUNTMASTER_VM}) {
                exec 'cat <prog.out >ver.in' if fork;
@@ -32,11 +32,11 @@ sub run{
                        my @fds = $ENV{GRUNTMASTER_VM} ? qw,0 /dev/ttyS1 1 >/dev/ttyS1, : qw/0 fifo1 1 >fifo2/;
                        $meta->{files}{prog}{run}->($meta->{files}{prog}{name}, fds => \@fds, map {defined $meta->{$_} ? ($_ => $meta->{$_}) : () } qw/timeout mlimit/);
                } catch {
-                       die $_
+                       die $_ ## no critic (RequireCarping)
                } finally {
                        waitpid $ret, 0;
                };
-               die [WA, "Wrong Answer"] if $?;
+               die [WA, 'Wrong Answer'] if $?; ## no critic (RequireCarping)
        } else {
                try {
                        my @fds = $ENV{GRUNTMASTER_VM} ? qw,1 >/dev/ttyS1 0 /dev/ttyS1, : qw/1 >fifo1 0 fifo2/;
index fd267cd88691664685f18f17f480ac099f862570..7111f6baadc6058ac46b01ab86f12cca48181c75 100644 (file)
@@ -21,7 +21,7 @@ sub run{
        try {
                $meta->{files}{ver}{run}->($meta->{files}{ver}{name}, fds => [qw/0 input 3 output 1 >result/], args => [$test]);
        } catch {
-               die [WA, "Wrong answer"]
+               die [WA, 'Wrong answer'] ## no critic (RequireCarping)
        };
        scalar slurp 'result';
 }
diff --git a/t/perlcritic.t b/t/perlcritic.t
new file mode 100644 (file)
index 0000000..51bad9d
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+use v5.14;
+use warnings;
+
+use Test::More;
+
+BEGIN { plan skip_all => '$ENV{RELEASE_TESTING} is false' unless $ENV{RELEASE_TESTING} }
+use Test::Perl::Critic -profile => 't/perlcriticrc';
+
+all_critic_ok
diff --git a/t/perlcriticrc b/t/perlcriticrc
new file mode 100644 (file)
index 0000000..96564fe
--- /dev/null
@@ -0,0 +1,35 @@
+severity = 1
+
+[-BuiltinFunctions::ProhibitComplexMappings]
+[-CodeLayout::RequireTidyCode]
+[-ControlStructures::ProhibitPostfixControls]
+[-ControlStructures::ProhibitUnlessBlocks]
+[-Documentation::PodSpelling]
+[-Documentation::RequirePodLinksIncludeText]
+[-InputOutput::RequireBracedFileHandleWithPrint]
+[-References::ProhibitDoubleSigils]
+[-RegularExpressions::ProhibitEnumeratedClasses]
+[-RegularExpressions::RequireLineBoundaryMatching]
+[-Subroutines::RequireFinalReturn]
+[-ValuesAndExpressions::ProhibitConstantPragma]
+[-ValuesAndExpressions::ProhibitEmptyQuotes]
+[-ValuesAndExpressions::ProhibitLeadingZeros]
+[-ValuesAndExpressions::ProhibitMagicNumbers]
+[-ValuesAndExpressions::ProhibitNoisyQuotes]
+[-Variables::ProhibitLocalVars]
+[-Variables::ProhibitPackageVars]
+[-Variables::ProhibitPunctuationVars]
+
+[BuiltinFunctions::ProhibitStringyEval]
+allow_includes = 1
+
+[RegularExpressions::RequireExtendedFormatting]
+minimum_regex_length_to_complain_about = 20
+
+[Documentation::RequirePodSections]
+lib_sections = NAME | SYNOPSIS | DESCRIPTION | AUTHOR | COPYRIGHT AND LICENSE
+script_sections = NAME | SYNOPSIS | DESCRIPTION | AUTHOR | COPYRIGHT AND LICENSE
+
+[Subroutines::RequireArgUnpacking]
+short_subroutine_statements = 5
+allow_subscripts = 1
This page took 0.046379 seconds and 4 git commands to generate.