Ticket #105: tweak-test.patch

File tweak-test.patch, 1.7 KB (added by Infinoid, 6 years ago)
  • t/codingstd/c_arg_assert.t

    [codingstd] Tweak c_arg_assert.t to make sure ASSERT_ARGS() is at the
    
    From: Mark Glines <mark@glines.org>
    
    *top* of the function.
    ---
    
     t/codingstd/c_arg_assert.t |   18 ++++++++++++++++--
     1 files changed, 16 insertions(+), 2 deletions(-)
    
    
    diff --git a/t/codingstd/c_arg_assert.t b/t/codingstd/c_arg_assert.t
    index 6a3cda6..49b839c 100644
    a b  
    66use warnings; 
    77 
    88use lib qw( . lib ../lib ../../lib ); 
    9 use Test::More tests => 1; 
     9use Test::More tests => 2; 
    1010use Parrot::Distribution; 
    1111 
    1212=head1 NAME 
     
    3737    my @files = @_; 
    3838    my @defines; 
    3939    my %usages; 
     40    my @offsets; 
    4041 
    4142    # first, find the definitions and the usages 
    4243    diag("finding definitions"); 
     
    4849                push(@defines, $1); 
    4950            } 
    5051            if($line =~ /^\s+ASSERT_ARGS\(([_a-zA-Z0-9]+)\);/) { 
    51                 $usages{$1} = 1; 
     52                my $func = $1; 
     53                $usages{$func} = 1; 
     54                my $fulltext = join('',@lines); 
     55                if($fulltext !~ /\{\s*ASSERT_ARGS\($func\);/s) { 
     56                    push(@offsets, $func); 
     57                } 
    5258            } 
    5359        } 
    5460    } 
     
    6369        } 
    6470        diag(scalar(@missing) . " unused assert macros found in total."); 
    6571    } 
     72    ok(!scalar @offsets); 
     73    if(scalar @offsets) { 
     74        diag("The following macros exist but aren't at the top of the function:"); 
     75        foreach my $offset (sort @offsets) { 
     76            diag($offset); 
     77        } 
     78        diag(scalar(@offsets) . " offset macros found in total."); 
     79    } 
    6680} 
    6781 
    6882# Local Variables: