# HG changeset patch # User Joel E. Denny # Date 1249344350 14400 # Node ID 107b7c10b72bb8d48151214f4830940787707a7a # Parent 803d728925f9ad22e72b94fe75afc3e5f72f4903 update-copyright: fix bug for 2-digit last year and add tests * build-aux/update-copyright: Fix bug. Use UPDATE_COPYRIGHT_YEAR from environment as current year if specified. * modules/update-copyright-tests: New * tests/test-update-copyright.sh: New. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2009-08-03 Joel E. Denny + + update-copyright: fix bug for 2-digit last year and add tests + * build-aux/update-copyright: Fix bug. + Use UPDATE_COPYRIGHT_YEAR from environment as current year if + specified. + * modules/update-copyright-tests: New + * tests/test-update-copyright.sh: New. + 2009-07-31 Joel E. Denny update-copyright: handle leading tabs in line prefix diff --git a/build-aux/update-copyright b/build-aux/update-copyright --- a/build-aux/update-copyright +++ b/build-aux/update-copyright @@ -1,7 +1,7 @@ #!/usr/bin/perl -0777 -pi # Update an FSF copyright year list to include the current year. -my $VERSION = '2009-07-31.12:44'; # UTC +my $VERSION = '2009-08-03.23:03'; # UTC # Copyright (C) 2009 Free Software Foundation # @@ -49,7 +49,7 @@ # Copyright (C) 1990-2005, 2007-2009 Free Software Foundation, # Inc. # -# # Copyright (C) 1990-2005, 2007-2009 Free Software +# # Copyright (c) 1990-2005, 2007-2009 Free Software # # Foundation, Inc. # # /* @@ -100,8 +100,11 @@ use strict; use warnings; -my ($sec, $min, $hour, $mday, $month, $year) = localtime (time()); -my $this_year = $year + 1900; +my $this_year = $ENV{UPDATE_COPYRIGHT_YEAR}; +if (!$this_year || $this_year !~ m/^\d\d(\d\d)?$/) { + my ($sec, $min, $hour, $mday, $month, $year) = localtime (time()); + $this_year = $year + 1900; +} my $copyright = 'Copyright \([cC]\)'; my $holder = 'Free Software Foundation, Inc.'; my $prefix_max = 5; @@ -131,9 +134,10 @@ { my $new = $1; my $sep = $2 ? $2 : ""; - my $last_c_year = $3; + my $last_year = $3; # Handle two-digit year numbers like "98" and "99". + my $last_c_year = $last_year; $last_c_year <= 99 and $last_c_year += 1900; @@ -142,15 +146,15 @@ # Update the year. if ($sep eq '-' && $last_c_year + 1 == $this_year) { - $new =~ s/$last_c_year/$this_year/; + $new =~ s/$last_year/$this_year/; } elsif ($sep ne '-' && $last_c_year + 1 == $this_year) { - $new =~ s/$last_c_year/$last_c_year-$this_year/; + $new =~ s/$last_year/$last_c_year-$this_year/; } else { - $new =~ s/$last_c_year/$last_c_year, $this_year/; + $new =~ s/$last_year/$last_c_year, $this_year/; } # Normalize all whitespace including newline-prefix sequences. diff --git a/modules/update-copyright-tests b/modules/update-copyright-tests new file mode 100644 --- /dev/null +++ b/modules/update-copyright-tests @@ -0,0 +1,12 @@ +Files: +tests/test-update-copyright.sh + +Depends-on: + +configure.ac: +abs_aux_dir=`cd "$ac_aux_dir"; pwd` +AC_SUBST([abs_aux_dir]) + +Makefile.am: +TESTS += test-update-copyright.sh +TESTS_ENVIRONMENT += PATH='$(abs_aux_dir)'$(PATH_SEPARATOR)"$$PATH" diff --git a/tests/test-update-copyright.sh b/tests/test-update-copyright.sh new file mode 100755 --- /dev/null +++ b/tests/test-update-copyright.sh @@ -0,0 +1,309 @@ +#!/bin/sh +# Test suite for update-copyright. +# Copyright (C) 2009 Free Software Foundation, Inc. +# This file is part of the GNUlib Library. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +TMP_BASE=update-copyright.test + +## ----------------------------- ## +## Examples from documentation. ## +## ----------------------------- ## + +TMP=$TMP_BASE-ex +cat > $TMP.1 < $TMP.2 < $TMP.3 < $TMP.4 < $TMP.5 < $TMP-stdout 2> $TMP-stderr +diff -u /dev/null $TMP-stdout || exit 1 +diff -u - $TMP-stderr < $TMP-stdout 2> $TMP-stderr +diff -u /dev/null $TMP-stdout || exit 1 +diff -u - $TMP-stderr <[5] + 1900'`; +cat > $TMP < $TMP-stdout 2> $TMP-stderr +diff -u /dev/null $TMP-stdout || exit 1 +diff -u /dev/null $TMP-stderr || exit 1 +diff -u - $TMP < $TMP < $TMP-stdout 2> $TMP-stderr +diff -u /dev/null $TMP-stdout || exit 1 +diff -u /dev/null $TMP-stderr || exit 1 +diff -u - $TMP < $TMP < $TMP-stdout 2> $TMP-stderr +diff -u /dev/null $TMP-stdout || exit 1 +diff -u /dev/null $TMP-stderr || exit 1 +diff -u - $TMP < $TMP < $TMP-stdout 2> $TMP-stderr +diff -u /dev/null $TMP-stdout || exit 1 +diff -u - $TMP-stderr < $TMP < $TMP-stdout 2> $TMP-stderr +diff -u /dev/null $TMP-stdout || exit 1 +diff -u - $TMP-stderr < $TMP < $TMP-stdout 2> $TMP-stderr +diff -u /dev/null $TMP-stdout || exit 1 +diff -u /dev/null $TMP-stderr || exit 1 +diff -u - $TMP < $TMP < $TMP-stdout 2> $TMP-stderr +diff -u /dev/null $TMP-stdout || exit 1 +diff -u /dev/null $TMP-stderr || exit 1 +diff -u - $TMP < $TMP < $TMP-stdout 2> $TMP-stderr +diff -u /dev/null $TMP-stdout || exit 1 +diff -u /dev/null $TMP-stderr || exit 1 +diff -u - $TMP <