summaryrefslogtreecommitdiff
path: root/t/porting/test_testlist.t
blob: 6cebf4c6f24be51cbc1cff46a762ca44eddd228a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
BEGIN {
    chdir '..' if -d '../dist';
    push @INC, "lib";
    require './t/test.pl';
}

use strict;
use warnings;

# Test that t/TEST and t/harness test the same files, and that all the
# test files (.t files) listed in MANIFEST are tested by both.
#
# We enabled the various special tests as this simplifies our MANIFEST
# parsing.  In theory if someone adds a new test directory this should
# tell us if one of the files does not know about it.

plan tests => 3;

my (%th, %tt, %all);
$ENV{PERL_TORTURE_TEST} = 1;
$ENV{PERL_TEST_MEMORY} = 1;
$ENV{PERL_BENCHMARK} = 1;

for my $file (`$^X t/harness -dumptests`) {
    chomp $file;
    $all{$file}++;
    $th{$file}++;
}

for my $file (`$^X t/TEST -dumptests`) {
    chomp $file;
    $all{$file}++;
    delete $th{$file} or $tt{$file}++;
}

is(0+keys(%th), 0, "t/harness will not test anything that t/TEST does not")
    or print STDERR map { "# t/harness: $_\n" } sort keys %th;
is(0+keys(%tt), 0, "t/TEST will not test aything that t/harness does not")
    or print STDERR map { "# tTEST: $_\n" } sort keys %tt;

sub get_extensions {
    my %extensions;
    open my $ifh, "<", "config.sh"
        or die "Failed to open 'config.sh': $!";
    while (<$ifh>) {
        if (/^extensions='([^']+)'/) {
            my $list = $1;
            NAME:
            foreach my $name (split /\s+/, $list) {
                $name = "PathTools" if $name eq "Cwd";
                $name = "Scalar/List/Utils" if $name eq "List/Util";
                my $sub_dir = $name;
                $sub_dir =~ s!/!-!g;
                foreach my $dir (qw(cpan dist ext)) {
                    if (-e "$dir/$sub_dir") {
                        $extensions{"$dir/$sub_dir"} = $name;
                        next NAME;
                    }
                }
                die "Could not find '$name'\n";
            }
            last;
        }
    }
    close $ifh;
    return \%extensions;
}

sub find_in_manifest_but_missing {
    my $extension = get_extensions();
    my %missing;
    my $is_os2 = $^O eq "os2";
    my $is_win32 = $^O eq "MSWin32";
    open my $ifh, "<", "MANIFEST"
        or die "Failed to open 'MANIFEST' for read: $!";
    while (<$ifh>) {
        chomp;
        my ($file, $descr) = split /\t+/, $_;
        next if $file eq "t/test.pl"
             or $file!~m!(?:\.t|/test\.pl)\z!
             or (!$is_os2 and $file=~m!^(?:t/)?os2/!)
             or (!$is_win32 and $file=~m!^(?:t/)?win32/!);
        if ($file=~m!^(cpan|dist|ext/[^/]+)!) {
            my $path = $1;
            next unless $extension->{$path};
        }
        $missing{$file}++ unless $all{$file};
    }
    close $ifh;
    return \%missing;
}
my $missing = find_in_manifest_but_missing();
is(0+keys(%$missing), 0, "Nothing in manifest that we wouldn't test")
    or print STDERR map { "# $_\n" } sort keys %$missing;