2 # Copyright (C) 2008-2010, Parrot Foundation.
7 use lib qw( . lib ../lib ../../lib );
9 use Test::More tests => 2;
10 use Parrot::Distribution;
14 t/codingstd/c_arg_assert.t - checks that all the headerizer asserts are used
19 % prove t/codingstd/c_arg_assert.t
23 Finds all the argument guards generated by headerizer (asserts to enforce the
24 non-NULLness of specially marked pointers) are actually used.
25 Verifies that macros are invoked on a sane position.
29 L<docs/pdds/pdd07_codingstd.pod>
33 my @files = Parrot::Distribution->new()->get_c_language_files();
35 check_asserts(@files);
44 # first, find the definitions and the usages in all files
45 diag('finding macro definitions and invocations');
46 foreach my $file (@files) {
47 my $path = $file->path();
48 my @lines = $file->read();
49 my $fulltext = join('', @lines);
50 foreach my $line (@lines) {
51 if ( my ($func) = $line =~ m/^#define ASSERT_ARGS_([_a-zA-Z0-9]+)\s/s ) {
52 push @defines, [$func, $path];
55 if ( my ($func) = $line =~ m/^\s+ASSERT_ARGS\(([_a-zA-Z0-9]+)\)$/ ) {
58 # The ASSERT_ARGS macro needs to follow an opening curly bracket
59 if ($fulltext !~ m/\)(?:\n| )\{\s*ASSERT_ARGS\($func\)\n/s) {
60 push @misplaced, [$func, $path];
66 # next, cross reference them.
67 my @missing = grep { ! exists($usages{$_->[0]}) } @defines;
68 ok(! @missing, 'no unused assert macros');
70 diag('unused assert macros found:');
71 foreach (sort { $a->[1] . $a->[0] cmp $b->[1] . $b->[0]} @missing) {
72 diag($_->[1] . ': ' . $_->[0]);
74 diag(scalar(@missing) . ' unused assert macros found in total.');
77 ok(! @misplaced, 'macros used in correct position');
79 diag(q{The following macros exist but aren't at the top of their function:});
80 foreach (sort @misplaced) {
81 diag($_->[1] . ': ' . $_->[0]);
83 diag(scalar(@misplaced) . ' misplaced macros found in total.');
89 # cperl-indent-level: 4
92 # vim: expandtab shiftwidth=4: