From: Nicholas Clark Date: Mon, 14 Sep 2009 12:34:10 +0000 (+0100) Subject: Convert Porting/checkARGS_ASSERT.pl to a regresion test, t/lib/args_assert.t X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8c8273e3a8fb69fa8e9d9bca975ed4c97278ca5d;p=p5sagit%2Fp5-mst-13.2.git Convert Porting/checkARGS_ASSERT.pl to a regresion test, t/lib/args_assert.t --- diff --git a/MANIFEST b/MANIFEST index 96b3af6..ce6279c 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3933,7 +3933,6 @@ Porting/add-package.pl Add/Update CPAN modules that are part of Core Porting/bump-perl-version bump the perl version in relevant files Porting/check83.pl Check whether we are 8.3-friendly Porting/checkansi.pl Check source code for ANSI-C violations -Porting/checkARGS_ASSERT.pl Check we use every PERL_ARGS_ASSERT* macro Porting/checkAUTHORS.pl Check that the AUTHORS file is complete Porting/checkcfgvar.pl Check that config scripts define all symbols Porting/checkURL.pl Check whether we have working URLs @@ -4172,6 +4171,7 @@ t/io/through.t See if pipe passes data intact t/io/utf8.t See if file seeking works t/japh/abigail.t Obscure tests t/lib/1_compile.t See if the various libraries and extensions compile +t/lib/args_assert.t Check that all PERL_ARGS_ASSERT* macros are used t/lib/Cname.pm Test charnames in regexes (op/pat.t) t/lib/common.pl Helper for lib/{warnings,feature}.t t/lib/commonsense.t See if configuration meets basic needs diff --git a/Porting/checkARGS_ASSERT.pl b/Porting/checkARGS_ASSERT.pl deleted file mode 100755 index 3d8e2fc..0000000 --- a/Porting/checkARGS_ASSERT.pl +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/perl -w -use strict; - -# Print out any PERL_ARGS_ASSERT* macro that was declared but not used. - -my %declared; -my %used; - -open my $fh, '<', 'proto.h' or die "Can't open proto.h: $!"; -while (<$fh>) { - $declared{$1}++ if /^#define\s+(PERL_ARGS_ASSERT[A-Za-z_]+)\s+/; -} - -if (!@ARGV) { - open my $fh, '<', 'MANIFEST' or die "Can't open MANIFEST: $!"; - while (<$fh>) { - # *.c or */*.c - push @ARGV, $1 if m!^((?:[^/]+/)?[^/]+\.c)\t!; - } -} - -while (<>) { - $used{$1}++ if /^\s+(PERL_ARGS_ASSERT_[A-Za-z_]+);$/; -} - -my %unused; - -foreach (keys %declared) { - $unused{$_}++ unless $used{$_}; -} - -print $_, "\n" foreach sort keys %unused; diff --git a/t/lib/args_assert.t b/t/lib/args_assert.t new file mode 100644 index 0000000..bf42d0f --- /dev/null +++ b/t/lib/args_assert.t @@ -0,0 +1,56 @@ +#!perl + +use strict; +use warnings; + +use Test::More 'no_plan'; + +# Fail for every PERL_ARGS_ASSERT* macro that was declared but not used. + +my %declared; +my %used; + +my $prefix = ''; + +unless (-d 't' && -f 'MANIFEST') { + # we'll assume that we are in t then. + # All files are interal to perl, so Unix-style is sufficiently portable. + $prefix = '../'; +} + +{ + my $proto = $prefix . 'proto.h'; + + open my $fh, '<', $proto or die "Can't open $proto: $!"; + + while (<$fh>) { + $declared{$1}++ if /^#define\s+(PERL_ARGS_ASSERT[A-Za-z_]+)\s+/; + } +} + +cmp_ok(scalar keys %declared, '>', 0, 'Some macros were declared'); + +if (!@ARGV) { + my $manifest = $prefix . 'MANIFEST'; + open my $fh, '<', $manifest or die "Can't open $manifest: $!"; + while (<$fh>) { + # *.c or */*.c + push @ARGV, $prefix . $1 if m!^((?:[^/]+/)?[^/]+\.c)\t!; + } +} + +while (<>) { + $used{$1}++ if /^\s+(PERL_ARGS_ASSERT_[A-Za-z_]+);$/; +} + +my %unused; + +foreach (keys %declared) { + $unused{$_}++ unless $used{$_}; +} + +if (keys %unused) { + fail("$_ is declared but not used") foreach sort keys %unused; +} else { + pass('Every PERL_ARGS_ASSERT* macro declared is used'); +}