This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix O_CREAT without O_TRUNC in cpan/autodie/t/utf8_open.t
[perl5.git] / t / porting / copyright.t
CommitLineData
acc70a07
S
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
52d097d9
S
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
acc70a07
S
19=cut
20
21
22use TestInit;
23use strict;
24BEGIN { require 'test.pl' }
25
26
52d097d9
S
27my ($opt) = @ARGV;
28
acc70a07
S
29my $readme_year = readme_year();
30my $v_year = v_year();
52d097d9
S
31
32# Check that both copyright dates are up-to-date, but only if requested, so
33# that tests still pass for people intentionally working on older versions:
34if ($opt eq '--now')
35{
36 my $current_year = (gmtime)[5] + 1900;
37 is $v_year, $current_year, 'perl -v copyright includes current year';
38 is $readme_year, $current_year, 'README copyright includes current year';
39}
40
41# Otherwise simply check that the two copyright dates match each other:
42else
43{
44 is $readme_year, $v_year, 'README and perl -v copyright dates match';
45}
acc70a07
S
46
47done_testing;
48
49
50sub readme_year
51# returns the latest copyright year from the top-level README file
52{
53
54 open my $readme, '<', '../README' or die "Opening README failed: $!";
55
56 # The copyright message is the first paragraph:
57 local $/ = '';
58 my $copyright_msg = <$readme>;
59
60 my ($year) = $copyright_msg =~ /.*\b(\d{4,})/s
61 or die "Year not found in README copyright message '$copyright_msg'";
62
63 $year;
64}
65
66
67sub v_year
68# returns the latest copyright year shown in perl -v
69{
70
71 my $output = runperl switches => ['-v'];
72 my ($year) = $output =~ /copyright 1987.*\b(\d{4,})/i
73 or die "Copyright statement not found in perl -v output '$output'";
74
75 $year;
76}