Move 3 porting sanity tests from t/lib/ to t/porting/, a more natural home.
[p5sagit/p5-mst-13.2.git] / t / porting / args_assert.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More 'no_plan';
7
8 # Fail for every PERL_ARGS_ASSERT* macro that was declared but not used.
9
10 my %declared;
11 my %used;
12
13 my $prefix = '';
14
15 unless (-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
31 cmp_ok(scalar keys %declared, '>', 0, 'Some macros were declared');
32
33 if (!@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
42 while (<>) {
43     $used{$1}++ if /^\s+(PERL_ARGS_ASSERT_[A-Za-z_]+);$/;
44 }
45
46 my %unused;
47
48 foreach (keys %declared) {
49     $unused{$_}++ unless $used{$_};
50 }
51
52 if (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 }