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