This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Convert Porting/checkARGS_ASSERT.pl to a regresion test, t/lib/args_assert.t
[perl5.git] / t / lib / args_assert.t
CommitLineData
8c8273e3
NC
1#!perl
2
3use strict;
4use warnings;
5
6use Test::More 'no_plan';
7
8# Fail for every PERL_ARGS_ASSERT* macro that was declared but not used.
9
10my %declared;
11my %used;
12
13my $prefix = '';
14
15unless (-d 't' && -f 'MANIFEST') {
16 # we'll assume that we are in t then.
17 # All files are interal to perl, so Unix-style is sufficiently portable.
18 $prefix = '../';
19}
20
21{
22 my $proto = $prefix . 'proto.h';
23
24 open my $fh, '<', $proto or die "Can't open $proto: $!";
25
26 while (<$fh>) {
27 $declared{$1}++ if /^#define\s+(PERL_ARGS_ASSERT[A-Za-z_]+)\s+/;
28 }
29}
30
31cmp_ok(scalar keys %declared, '>', 0, 'Some macros were declared');
32
33if (!@ARGV) {
34 my $manifest = $prefix . 'MANIFEST';
35 open my $fh, '<', $manifest or die "Can't open $manifest: $!";
36 while (<$fh>) {
37 # *.c or */*.c
38 push @ARGV, $prefix . $1 if m!^((?:[^/]+/)?[^/]+\.c)\t!;
39 }
40}
41
42while (<>) {
43 $used{$1}++ if /^\s+(PERL_ARGS_ASSERT_[A-Za-z_]+);$/;
44}
45
46my %unused;
47
48foreach (keys %declared) {
49 $unused{$_}++ unless $used{$_};
50}
51
52if (keys %unused) {
53 fail("$_ is declared but not used") foreach sort keys %unused;
54} else {
55 pass('Every PERL_ARGS_ASSERT* macro declared is used');
56}