This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
t/porting/readme.t: Check Porting/README.pod consistency
[perl5.git] / t / porting / readme.t
CommitLineData
d4345e37
BG
1#!./perl -w
2#
3# Check whether all files mentioned in Porting/README.pod exist in Porting and
4# vice versa.
5
6BEGIN {
7 @INC = '..' if -f '../TestInit.pm';
8}
9
10use TestInit qw(T); # T is chdir to the top level
11use strict;
12use warnings;
13require 't/test.pl';
14
15open(my $fh, '<', 'Porting/README.pod') or die("Can't open Porting/README.pod: $!");
16
17my @porting_files = glob("Porting/*");
18# It seems that dying here is nicer than having several dozen failing tests
19# later. But that assumes one will see the message from die.
20die "Can't get contents of Porting/ directory.\n" unless @porting_files > 1;
21
22my (@current_order, @sorted_order, %files_in_pod);
23while(<$fh>) {
24 next unless $_ =~ /^=head/;
25 my @matches = $_ =~ m/F<([^>]+)>/g;
26 for my $file (@matches) {
27 $files_in_pod{$file} = 1;
28 push @current_order, $file;
29 }
30}
31
32for my $file (@porting_files) {
33 $file =~ s!^Porting/!!;
34 next if $file =~ /^perl[0-9]+delta\.pod$/;
35 ok(exists($files_in_pod{$file}), "$file is mentioned in Porting/README.pod");
36 delete $files_in_pod{$file};
37}
38for my $file (keys %files_in_pod) {
39 fail("$file exists in Porting/");
40}
41
42# Check if the entries in the README are in some sort of order.
43eval {
44 require Unicode::Collate;
45 my $Collator = Unicode::Collate->new();
46 @sorted_order = $Collator->sort(@current_order);
47};
48
49if(@sorted_order) {
50 ok(eq_array(\@current_order, \@sorted_order), "Files are referenced in order") or
51 print_right_order();
52}
53else {
54 note('Unicode collation did not work. Not checking order of entries.');
55}
56
57# Frankly this is a bit much for a porting test, but it exists now.
58sub print_right_order {
59 my $max = 0;
60 for(@current_order) {
61 my $l = length $_;
62 $max = $l if $l > $max;
63 }
64 $max = 36 if $max > 36;
65 note(sprintf " N %-${max}s %-${max}s\n", "Correct", "Current");
66 for(0..$#current_order) {
67 my $wrong = $sorted_order[$_] eq $current_order[$_] ? '' : 'X';
68 my $line = sprintf "%2d %1s %-${max}s %-${max}s\n",
69 $_, $wrong, $sorted_order[$_], $current_order[$_];
70 $line =~ s{ ((?: ){2,})}{" " . ". " x (length($1)/2)}e if $_&1;
71 note($line);
72 }
73}
74
75done_testing();