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