From cfc6c78d0071efb47b7551183968bd55254af6e5 Mon Sep 17 00:00:00 2001 From: Chris 'BinGOs' Williams Date: Thu, 15 Dec 2011 23:11:51 +0000 Subject: [PATCH] Added porting tests for CUSTOMIZED files In Porting/Maintainers.pl CUSTOMIZED is a list of files that have been customized within the Perl core. These tests make SHA digests of the customized files and do a comparison previously stored digests to ensure that customization is not lost when updating from upstream. Update MANIFEST with the customized files Add --regen ability to porting/customized.t and some documentation --- MANIFEST | 2 + t/porting/customized.dat | 14 +++++ t/porting/customized.t | 144 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 t/porting/customized.dat create mode 100644 t/porting/customized.t diff --git a/MANIFEST b/MANIFEST index 8983793..9891653 100644 --- a/MANIFEST +++ b/MANIFEST @@ -5319,6 +5319,8 @@ t/porting/bincompat.t Check that {non_,}bincompat_options are ordered t/porting/checkcase.t Check whether we are case-insensitive-fs-friendly t/porting/checkcfgvar.t Check that all config.sh-like files are good t/porting/cmp_version.t Test whether all changed module files have their VERSION bumped +t/porting/customized.dat Data file for porting/customized.t +t/porting/customized.t Check all CUSTOMIZED files are as they should be t/porting/diag.t Test completeness of perldiag.pod t/porting/dual-life.t Check that dual-life bins are in utils/ t/porting/exec-bit.t Check that exec-bit bins are identified diff --git a/t/porting/customized.dat b/t/porting/customized.dat new file mode 100644 index 0000000..e2ef05d --- /dev/null +++ b/t/porting/customized.dat @@ -0,0 +1,14 @@ +Module::Build cpan/Module-Build/lib/Module/Build/ConfigData.pm 2f3f07fd889077ebd51791ad6e195d9164b4baf3 +Test::Harness cpan/Test-Harness/t/source.t 61738913dac9ba6c4504756d355c23c25c47d31e +Test::Harness cpan/Test-Harness/t/testargs.t 79c91b2ea73f7cbfb9bae45dec4a62db74cb8dbf +Module::Pluggable cpan/Module-Pluggable/Makefile.PL 72062c1a01ed7c62d16c55122c163b2d89f0d739 +autodie cpan/autodie/t/open.t cb493da4305f591ca0344d09e8a840a3147c5579 +libnet cpan/libnet/Makefile.PL 5554b71464b45f5cc002e55f2464f7ff4abd05b6 +podlators cpan/podlators/scripts/pod2man.PL 8fb484dc560adb00889f504760ca0a4defa9dc40 +podlators cpan/podlators/scripts/pod2text.PL 53ccba9264368c3f9acd2a36d1d354797d2a88f6 +podlators pod/perlpodstyle.pod 4f1ba65eddc5576267954b948556e16a9686c411 +CPANPLUS cpan/CPANPLUS/Makefile.PL 5d533f6722af6aae73204755beb8d6c008fc0d4a +Text-Tabs+Wrap cpan/Text-Tabs/t/fill.t a960d2c4f66b7e30557b5479e0da2da1bf7a7f45 +Text-Tabs+Wrap cpan/Text-Tabs/t/tabs.t 63a67b3a319c858d7e66306b8a653de1951153dc +Sys::Syslog cpan/Sys-Syslog/t/syslog.t 647571fc90918883b871ff7e005ed7ab8a223784 +CGI cpan/CGI/t/tmpdir.t 83c913c36712f00412ce42475ae8a2bd1eba52ea diff --git a/t/porting/customized.t b/t/porting/customized.t new file mode 100644 index 0000000..76053bc --- /dev/null +++ b/t/porting/customized.t @@ -0,0 +1,144 @@ +#!./perl -w + +# Test that CUSTOMIZED files in Maintainers.pl have not been overwritten. + +BEGIN { + # This test script uses a slightly atypical invocation of the 'standard' + # core testing setup stanza. + # The existing porting tools which manage the Maintainers file all + # expect to be run from the root + # XXX that should be fixed + + chdir '..' unless -d 't'; + @INC = qw(lib Porting); +} + +use strict; +use warnings; +use Digest; +use File::Spec; +use Maintainers qw[%Modules get_module_files get_module_pat]; + +sub filter_customized { + my ($m, @files) = @_; + + return @files + unless my $customized = $Modules{$m}{CUSTOMIZED}; + + my ($pat) = map { qr/$_/ } join '|' => map { + ref $_ ? $_ : qr/\b\Q$_\E$/ + } @{ $customized }; + + return grep { $_ =~ $pat } @files; +} + +sub my_get_module_files { + my $m = shift; + return filter_customized $m => map { Maintainers::expand_glob($_) } get_module_pat($m); +} + +my $TestCounter = 0; + +my $digest_type = 'SHA-1'; + +my $original_dir = File::Spec->rel2abs(File::Spec->curdir); +my $data_dir = File::Spec->catdir('t', 'porting'); +my $customised = File::Spec->catfile($data_dir, 'customized.dat'); + +my %customised; + +my $regen = 0; + +while (@ARGV && substr($ARGV[0], 0, 1) eq '-') { + my $arg = shift @ARGV; + + $arg =~ s/^--/-/; # Treat '--' the same as a single '-' + if ($arg eq '-regen') { + $regen = 1; + } + else { + die < Regenerate the data file for $0 + +EOF + } +} + +my $data_fh; + +if ( $regen ) { + open $data_fh, '>:bytes', $customised or die "Can't open $customised"; +} +else { + open $data_fh, '<:bytes', $customised or die "Can't open $customised"; + while (<$data_fh>) { + chomp; + my ($module,$file,$sha) = split ' '; + $customised{ $module }->{ $file } = $sha; + } + close $data_fh; +} + +foreach my $module ( keys %Modules ) { + next unless my $files = $Modules{ $module }{CUSTOMIZED}; + my @perl_files = my_get_module_files( $module ); + foreach my $file ( @perl_files ) { + my $digest = Digest->new( $digest_type ); + { + open my $fh, '<', $file or die "Can't open $file"; + binmode $fh; + $digest->addfile( $fh ); + close $fh; + } + my $id = $digest->hexdigest; + if ( $regen ) { + print $data_fh join(' ', $module, $file, $id), "\n"; + next; + } + my $should_be = $customised{ $module }->{ $file }; + if ( $id ne $should_be ) { + print "not ok ".++$TestCounter." - SHA for $file does not match stashed SHA\n"; + } + else { + print "ok ".++$TestCounter." - SHA for $file matched\n"; + } + } +} + +if ( $regen ) { + print "ok ".++$TestCounter." - regenerated data file\n"; + close $data_fh; +} + +print "1..".$TestCounter."\n"; + +=pod + +=head1 NAME + +customized.t - Test that CUSTOMIZED files in Maintainers.pl have not been overwritten + +=head1 SYNOPSIS + + cd t + ./perl -I../lib porting/customized.t --regen + +=head1 DESCRIPTION + +customized.t checks that files listed in C that have been C +are not accidently overwritten by CPAN module updates. + +=head1 OPTIONS + +=over + +=item C<--regen> + +Use this command line option to regenerate the C file. + +=back + +=cut -- 2.7.4