This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test that README and perl -v copyright years match
[perl5.git] / t / porting / copyright.t
diff --git a/t/porting/copyright.t b/t/porting/copyright.t
new file mode 100644 (file)
index 0000000..e1b7faa
--- /dev/null
@@ -0,0 +1,56 @@
+#!perl
+
+=head1 NAME
+
+copyright.t
+
+=head1 DESCRIPTION
+
+Tests that the latest copyright years in the top-level README file and the
+C<perl -v> output match each other.
+
+If the test fails, update at least one of README and perl.c so that they match
+reality.
+
+=cut
+
+
+use TestInit;
+use strict;
+BEGIN { require 'test.pl' }
+
+
+my $readme_year = readme_year();
+my $v_year = v_year();
+is $readme_year, $v_year, 'README and perl -v copyright dates match';
+
+done_testing;
+
+
+sub readme_year
+# returns the latest copyright year from the top-level README file
+{
+
+  open my $readme, '<', '../README' or die "Opening README failed: $!";
+
+  # The copyright message is the first paragraph:
+  local $/ = '';
+  my $copyright_msg = <$readme>;
+
+  my ($year) = $copyright_msg =~ /.*\b(\d{4,})/s
+      or die "Year not found in README copyright message '$copyright_msg'";
+
+  $year;
+}
+
+
+sub v_year
+# returns the latest copyright year shown in perl -v
+{
+
+  my $output = runperl switches => ['-v'];
+  my ($year) = $output =~ /copyright 1987.*\b(\d{4,})/i
+      or die "Copyright statement not found in perl -v output '$output'";
+
+  $year;
+}