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