1#!perl 2 3=head1 NAME 4 5copyright.t 6 7=head1 DESCRIPTION 8 9Tests that the latest copyright years in the top-level README file and the 10C<perl -v> output match each other. 11 12If the test fails, update at least one of README and perl.c so that they match 13reality. 14 15Optionally you can pass the C<--now> option to check they are at the current 16year. This isn't checked by default, so that it doesn't fail for people 17working on older releases. It should be run before making a new release. 18 19=cut 20 21use strict; 22use Config; 23BEGIN { require './test.pl' } 24 25if ( $Config{usecrosscompile} ) { 26 skip_all( "Not all files are available during cross-compilation" ); 27} 28 29my ($opt) = @ARGV; 30 31my $readme_year = readme_year(); 32my $v_year = v_year(); 33my $gh_readme_year; 34# git on windows renders symbolic links as a file containing 35# the file linked to 36if (-e "../.github/README.md" && -s "../.github/README.md" > 80) 37{ 38 $gh_readme_year = readme_year(".github/README.md"); 39} 40 41 42# Check that both copyright dates are up-to-date, but only if requested, so 43# that tests still pass for people intentionally working on older versions: 44if ($opt eq '--now') 45{ 46 my $current_year = (gmtime)[5] + 1900; 47 is $v_year, $current_year, 'perl -v copyright includes current year'; 48 is $readme_year, $current_year, 'README copyright includes current year'; 49 if ($gh_readme_year) 50 { 51 is ($gh_readme_year, $current_year, 52 '.github/README.md copyright includes current year'); 53 } 54} 55 56# Otherwise simply check that the two copyright dates match each other: 57else 58{ 59 is $readme_year, $v_year, 'README and perl -v copyright dates match'; 60 if ($gh_readme_year) 61 { 62 is ($gh_readme_year, $v_year, 63 '.github/README.md and perl -v copyright dates match'); 64 } 65} 66 67done_testing; 68 69 70sub readme_year 71# returns the latest copyright year from the top-level README file 72{ 73 my $file = shift || "README"; 74 75 open my $readme, '<', "../$file" or die "Opening $file failed: $!"; 76 77 # The copyright message is the first paragraph: 78 local $/ = ''; 79 my $copyright_msg = <$readme>; 80 81 my ($year) = $copyright_msg =~ /.*\b(\d{4,})/s 82 or die "Year not found in $file copyright message '$copyright_msg'"; 83 84 $year; 85} 86 87 88sub v_year 89# returns the latest copyright year shown in perl -v 90{ 91 92 my $output = runperl switches => ['-v']; 93 my ($year) = $output =~ /copyright 1987.*\b(\d{4,})/i 94 or die "Copyright statement not found in perl -v output '$output'"; 95 96 $year; 97} 98