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 t);
21 use Maintainers qw[%Modules get_module_files get_module_pat];
23 sub filter_customized {
27 unless my $customized = $Modules{$m}{CUSTOMIZED};
29 my ($pat) = map { qr/$_/ } join '|' => map {
30 ref $_ ? $_ : qr/\b\Q$_\E$/
33 return grep { $_ =~ $pat } @files;
36 sub my_get_module_files {
38 return filter_customized $m => map { Maintainers::expand_glob($_) } get_module_pat($m);
43 my $digest_type = 'SHA-1';
45 my $original_dir = File::Spec->rel2abs(File::Spec->curdir);
46 my $data_dir = File::Spec->catdir('t', 'porting');
47 my $customised = File::Spec->catfile($data_dir, 'customized.dat');
53 while (@ARGV && substr($ARGV[0], 0, 1) eq '-') {
54 my $arg = shift @ARGV;
56 $arg =~ s/^--/-/; # Treat '--' the same as a single '-'
57 if ($arg eq '-regen') {
64 Usage: $0 [ --regen ]\n"
65 --regen -> Regenerate the data file for $0
74 open $data_fh, '>:bytes', $customised or die "Can't open $customised";
77 open $data_fh, '<:bytes', $customised or die "Can't open $customised";
80 my ($module,$file,$sha) = split ' ';
81 $customised{ $module }->{ $file } = $sha;
86 foreach my $module ( keys %Modules ) {
87 next unless my $files = $Modules{ $module }{CUSTOMIZED};
88 my @perl_files = my_get_module_files( $module );
89 foreach my $file ( @perl_files ) {
90 my $digest = Digest->new( $digest_type );
92 open my $fh, '<', $file or die "Can't open $file";
94 $digest->addfile( $fh );
97 my $id = $digest->hexdigest;
99 print $data_fh join(' ', $module, $file, $id), "\n";
102 my $should_be = $customised{ $module }->{ $file };
103 is( $id, $should_be, "SHA for $file matches stashed SHA" );
108 pass( "regenerated data file" );
118 customized.t - Test that CUSTOMIZED files in Maintainers.pl have not been overwritten
123 ./perl -I../lib porting/customized.t --regen
127 customized.t checks that files listed in C<Maintainers.pl> that have been C<CUSTOMIZED>
128 are not accidently overwritten by CPAN module updates.
136 Use this command line option to regenerate the C<customized.dat> file.