1#!perl 2 3use strict; 4use warnings; 5use Config; 6 7require './test.pl'; 8 9if ( $Config{usecrosscompile} ) { 10 skip_all( "Not all files are available during cross-compilation" ); 11} 12 13plan('no_plan'); 14 15# Fail for every PERL_ARGS_ASSERT* macro that was declared but not used. 16 17my %declared; 18my %used; 19 20my $prefix = ''; 21 22unless (-d 't' && -f 'MANIFEST') { 23 # we'll assume that we are in t then. 24 # All files are internal to perl, so Unix-style is sufficiently portable. 25 $prefix = '../'; 26} 27 28{ 29 my $proto = $prefix . 'proto.h'; 30 31 open my $fh, '<', $proto or die "Can't open $proto: $!"; 32 33 while (<$fh>) { 34 # The trailing '.' distinguishes real from dummy macros that have no 35 # real asserts 36 $declared{$1}++ if /^#define\s+(PERL_ARGS_ASSERT[A-Za-z0-9_]+)\s+./; 37 } 38} 39 40cmp_ok(scalar keys %declared, '>', 0, 'Some macros were declared'); 41 42if (!@ARGV) { 43 my $manifest = $prefix . 'MANIFEST'; 44 open my $fh, '<', $manifest or die "Can't open $manifest: $!"; 45 while (<$fh>) { 46 # *.c or */*.c 47 push @ARGV, $prefix . $1 if m!^((?:[^/]+/)?[^/]+\.c)\t!; 48 # Special case the *inline.h since they behave like *.c 49 push @ARGV, $prefix . $1 if m!^(([^/]+)?inline\.h)\t!; 50 } 51} 52 53while (<>) { 54 $used{$1}++ if /^\s+(PERL_ARGS_ASSERT_[A-Za-z0-9_]+);$/; 55} 56 57my %unused; 58 59foreach (keys %declared) { 60 $unused{$_}++ unless $used{$_}; 61} 62 63if (keys %unused) { 64 fail("$_ is declared but not used") foreach sort keys %unused; 65} else { 66 pass('Every PERL_ARGS_ASSERT* macro declared is used'); 67} 68