3 # Test that CUSTOMIZED files in Maintainers.pl have not been overwritten.
6 # This test script uses a slightly atypical invocation of the 'standard'
7 # core testing setup stanza.
8 # The existing porting tools which manage the Maintainers file all
9 # expect to be run from the root
10 # XXX that should be fixed
12 chdir '..' unless -d 't';
13 @INC = qw(lib Porting);
20 use Maintainers qw[%Modules get_module_files get_module_pat];
22 sub filter_customized {
26 unless my $customized = $Modules{$m}{CUSTOMIZED};
28 my ($pat) = map { qr/$_/ } join '|' => map {
29 ref $_ ? $_ : qr/\b\Q$_\E$/
32 return grep { $_ =~ $pat } @files;
35 sub my_get_module_files {
37 return filter_customized $m => map { Maintainers::expand_glob($_) } get_module_pat($m);
42 my $digest_type = 'SHA-1';
44 my $original_dir = File::Spec->rel2abs(File::Spec->curdir);
45 my $data_dir = File::Spec->catdir('t', 'porting');
46 my $customised = File::Spec->catfile($data_dir, 'customized.dat');
52 while (@ARGV && substr($ARGV[0], 0, 1) eq '-') {
53 my $arg = shift @ARGV;
55 $arg =~ s/^--/-/; # Treat '--' the same as a single '-'
56 if ($arg eq '-regen') {
63 Usage: $0 [ --regen ]\n"
64 --regen -> Regenerate the data file for $0
73 open $data_fh, '>:bytes', $customised or die "Can't open $customised";
76 open $data_fh, '<:bytes', $customised or die "Can't open $customised";
79 my ($module,$file,$sha) = split ' ';
80 $customised{ $module }->{ $file } = $sha;
85 foreach my $module ( keys %Modules ) {
86 next unless my $files = $Modules{ $module }{CUSTOMIZED};
87 my @perl_files = my_get_module_files( $module );
88 foreach my $file ( @perl_files ) {
89 my $digest = Digest->new( $digest_type );
91 open my $fh, '<', $file or die "Can't open $file";
93 $digest->addfile( $fh );
96 my $id = $digest->hexdigest;
98 print $data_fh join(' ', $module, $file, $id), "\n";
101 my $should_be = $customised{ $module }->{ $file };
102 if ( $id ne $should_be ) {
103 print "not ok ".++$TestCounter." - SHA for $file does not match stashed SHA\n";
106 print "ok ".++$TestCounter." - SHA for $file matched\n";
112 print "ok ".++$TestCounter." - regenerated data file\n";
116 print "1..".$TestCounter."\n";
122 customized.t - Test that CUSTOMIZED files in Maintainers.pl have not been overwritten
127 ./perl -I../lib porting/customized.t --regen
131 customized.t checks that files listed in C<Maintainers.pl> that have been C<CUSTOMIZED>
132 are not accidently overwritten by CPAN module updates.
140 Use this command line option to regenerate the C<customized.dat> file.