]> iEval git - app-scheme79asm.git/commitdiff
Add perlcritic test and make code compliant
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 24 Mar 2018 16:25:30 +0000 (18:25 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sat, 24 Mar 2018 16:25:30 +0000 (18:25 +0200)
MANIFEST
lib/App/Scheme79asm.pm
lib/App/Scheme79asm/Compiler.pm
t/perlcritic.t [new file with mode: 0644]
t/perlcriticrc [new file with mode: 0644]

index bcf5fe1ec8ffcb0947dac6a53ecff37ff6d3c652..d94d257ad810786c9071240f80692a450979ba8b 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,9 +1,11 @@
 Changes
+lib/App/Scheme79asm.pm
+lib/App/Scheme79asm/Compiler.pm
 Makefile.PL
 MANIFEST
 README
 scheme79asm
 t/App-Scheme79asm.t
 t/Compiler.t
-lib/App/Scheme79asm.pm
-lib/App/Scheme79asm/Compiler.pm
+t/perlcritic.t
+t/perlcriticrc
index fdbbd21c3f3f3fe7c3c042ee104511ee70f6fc0f..fb99ee33ef5a51fc4bd05ddbaf25896fdde4a929 100644 (file)
@@ -3,6 +3,8 @@ package App::Scheme79asm;
 use 5.014000;
 use strict;
 use warnings;
+use re '/s';
+use Carp qw/croak/;
 
 use Data::Dumper qw/Dumper/;
 use Data::SExpression qw/consp scalarp/;
@@ -66,8 +68,8 @@ sub process {
        }
 
        $addr += (1 << $self->{addr_bits}) if $addr < 0;
-       die "Type too large: $type\n" unless $type < (1 << $self->{type_bits});
-       die "Addr too large: $addr\n" unless $addr < (1 << $self->{addr_bits});
+       die "Type too large: $type\n" if $type >= (1 << $self->{type_bits});
+       die "Addr too large: $addr\n" if $addr >= (1 << $self->{addr_bits});
        my $result = ($type << $self->{addr_bits}) + $addr;
        unless ($location) {
                $self->{freeptr}++;
@@ -118,9 +120,9 @@ sub print_binary16 {
        die "addr_bits + type_bits >= 16\n"if $self->{addr_bits} + $self->{type_bits} > 16;
 
        my $length = @{$self->{memory}};
-       print $fh pack('n', $length);
+       print $fh pack 'n', $length or croak "Failed to print memory size: $!";
        for (@{$self->{memory}}) {
-               print $fh pack('n', $_)
+               print $fh pack 'n', $_ or croak "Failed to print memory: $!"
        }
 }
 
@@ -142,9 +144,9 @@ sub print_verilog {
                my $spaces = ' ' x ($bits + 5 - (length $val));
                $index = sprintf $index_format, $index;
 
-               print $fh "mem[$index] <= $val;";
-               print $fh "$spaces // $comment" if defined $comment;
-               print $fh "\n";
+               my $string = "mem[$index] <= $val;";
+               $string .= "$spaces // $comment" if defined $comment;
+               say $fh $string or croak "Failed to print verilog: $!";
        }
 
 }
index f4762623584a2e34e8a6adb5d63eed69d1642429..bf03eea81f8259dd7e748047a7c9eaccc8416bc2 100644 (file)
@@ -106,7 +106,7 @@ sub new {
        my %self = (
                symbols => ['', '', 'T'],
                nsymbols => 3,
-               symbol_map => {}
+               symbol_map => {},
        );
        bless \%self, $class;
 }
@@ -187,12 +187,12 @@ sub process_toplevel {
                } elsif ($func eq 'LAMBDA') {
                        my $func_name = $expr->cdr->car;
                        my $func_args = $expr->cdr->cdr->car;
-                       my $func_body = $expr->cdr->cdr->cdr->car;
+                       my $func_body = $expr->cdr->cdr->cdr->car; ## no critic (ProhibitLongChainsOfMethodCalls)
                        [PROC => $self->process_proc($func_name, $func_args, $func_body, $env)]
                } elsif ($func eq 'IF') {
                        my ($if_cond, $if_then, $if_else) =
                          map { $self->process_toplevel($_, $env) }
-                         ($expr->cdr->car, $expr->cdr->cdr->car, $expr->cdr->cdr->cdr->car);
+                         ($expr->cdr->car, $expr->cdr->cdr->car, $expr->cdr->cdr->cdr->car); ## no critic (ProhibitLongChainsOfMethodCalls)
                        [IF => [LIST => $if_else, $if_then], $if_cond]
                } else {
                        $self->process_funcall($expr->car, $expr->cdr, $env)
diff --git a/t/perlcritic.t b/t/perlcritic.t
new file mode 100644 (file)
index 0000000..e005e07
--- /dev/null
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+use strict;
+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 'lib'
diff --git a/t/perlcriticrc b/t/perlcriticrc
new file mode 100644 (file)
index 0000000..f6a22c0
--- /dev/null
@@ -0,0 +1,42 @@
+severity = 1
+
+[-BuiltinFunctions::ProhibitComplexMappings]
+[-CodeLayout::RequireTidyCode]
+[-ControlStructures::ProhibitPostfixControls]
+[-ControlStructures::ProhibitUnlessBlocks]
+[-Documentation::PodSpelling]
+[-Documentation::RequirePodLinksIncludeText]
+[-InputOutput::RequireBracedFileHandleWithPrint]
+[-Modules::ProhibitAutomaticExportation]
+[-References::ProhibitDoubleSigils]
+[-RegularExpressions::ProhibitEnumeratedClasses]
+[-RegularExpressions::ProhibitUnusualDelimiters]
+[-RegularExpressions::RequireBracesForMultiline]
+[-RegularExpressions::RequireLineBoundaryMatching]
+[-Subroutines::ProhibitSubroutinePrototypes]
+[-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
+
+[TestingAndDebugging::ProhibitNoWarnings]
+allow_with_category_restriction = 1
This page took 0.039167 seconds and 4 git commands to generate.