maint: update copyright
[gnulib.git] / tests / test-update-copyright.sh
index 69dadbf..759a937 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Test suite for update-copyright.
-# Copyright (C) 2009 Free Software Foundation, Inc.
+# Copyright (C) 2009-2014 Free Software Foundation, Inc.
 # This file is part of the GNUlib Library.
 #
 # This program is free software: you can redistribute it and/or modify
@@ -23,7 +23,44 @@ else
   compare() { cmp "$@"; }
 fi
 
+# Ensure the update-copyright program gets found.
+PATH=$abs_aux_dir:$PATH
+export PATH
+
 TMP_BASE=update-copyright.test
+trap 'rm -f $TMP_BASE*' 0 1 2 3 15
+
+## --------------------------------- ##
+## Skip if user does not have perl.  ##
+## --------------------------------- ##
+
+TMP=$TMP_BASE
+s=$TMP-script
+cat <<\EOF > $s
+eval '(exit $?0)' && eval 'exec perl -wS -0777 -pi "$0" ${1+"$@"}'
+  & eval 'exec perl -wS -0777 -pi "$0" $argv:q'
+    if 0;
+s/a/b/
+EOF
+chmod a+x $s
+echo a > $TMP-in
+./$s $TMP-in 2>/dev/null && test b = "`cat $TMP-in 2>/dev/null`" ||
+  {
+    printf '%s\n' "$0: skipping this test;" \
+      'your system has insufficient support for Perl' 1>&2
+    exit 77
+  }
+
+# Skip this test if Perl is too old.  FIXME: 5.8.0 is just a guess.
+# We have a report that 5.6.1 is inadequate and that 5.8.0 works.
+perl -e 'require 5.8.0' || {
+  echo '$0: skipping this test; Perl version is too old' 1>&2
+  exit 77
+}
+
+# Do not let a different envvar setting perturb results.
+UPDATE_COPYRIGHT_MAX_LINE_LENGTH=72
+export UPDATE_COPYRIGHT_MAX_LINE_LENGTH
 
 ## ----------------------------- ##
 ## Examples from documentation.  ##
@@ -45,15 +82,15 @@ cat > $TMP.3 <<EOF
  */
 EOF
 cat > $TMP.4 <<EOF
-/* Copyright (C) 1990-2005, 2007-2009 Free Software
- * Foundation, Inc.  */
+## Copyright (C) 1990-2005, 2007-2009 Free Software
+#  Foundation, Inc.
 EOF
 cat > $TMP.5 <<EOF
 Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
 EOF
 cat > $TMP.6 <<EOF
-/* Copyright (C) 1990-2005, 2007-2009 Free Software
- * Foundation, Inc.  */
+## Copyright (C) 1990-2005, 2007-2009 Free Software
+#  Foundation, Inc.
 
 Copyright (C) 1990-2005, 2007-2009 Free Software Foundation,
 Inc.
@@ -66,11 +103,11 @@ Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
 EOF
 
 UPDATE_COPYRIGHT_YEAR=2009 \
-  update-copyright $TMP.* 1> $TMP-stdout 2> $TMP-stderr
+  update-copyright $TMP.? 1> $TMP-stdout 2> $TMP-stderr
 compare /dev/null $TMP-stdout || exit 1
 compare - $TMP-stderr <<EOF || exit 1
-$TMP.4: warning: FSF copyright statement not found
-$TMP.5: warning: FSF copyright statement not found
+$TMP.4: warning: copyright statement not found
+$TMP.5: warning: copyright statement not found
 EOF
 compare - $TMP.1 <<EOF || exit 1
 Copyright @copyright{} 1990-2005, 2007-2009 Free Software
@@ -87,15 +124,15 @@ compare - $TMP.3 <<EOF || exit 1
  */
 EOF
 compare - $TMP.4 <<EOF || exit 1
-/* Copyright (C) 1990-2005, 2007-2009 Free Software
- * Foundation, Inc.  */
+## Copyright (C) 1990-2005, 2007-2009 Free Software
+#  Foundation, Inc.
 EOF
 compare - $TMP.5 <<EOF || exit 1
 Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
 EOF
 compare - $TMP.6 <<EOF || exit 1
-/* Copyright (C) 1990-2005, 2007-2009 Free Software
- * Foundation, Inc.  */
+## Copyright (C) 1990-2005, 2007-2009 Free Software
+#  Foundation, Inc.
 
 Copyright (C) 1990-2005, 2007-2009 Free Software Foundation,
 Inc.
@@ -107,12 +144,12 @@ Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
 # Foundation, Inc.
 EOF
 
-UPDATE_COPYRIGHT_YEAR=2010 \
-  update-copyright $TMP.* 1> $TMP-stdout 2> $TMP-stderr
+UPDATE_COPYRIGHT_YEAR=2010 UPDATE_COPYRIGHT_USE_INTERVALS=1 \
+  update-copyright $TMP.? 1> $TMP-stdout 2> $TMP-stderr
 compare /dev/null $TMP-stdout || exit 1
 compare - $TMP-stderr <<EOF || exit 1
-$TMP.4: warning: FSF copyright statement not found
-$TMP.5: warning: FSF copyright statement not found
+$TMP.4: warning: copyright statement not found
+$TMP.5: warning: copyright statement not found
 EOF
 compare - $TMP.1 <<EOF || exit 1
 Copyright @copyright{} 1990-2005, 2007-2010 Free Software Foundation,
@@ -123,19 +160,19 @@ compare - $TMP.2 <<EOF || exit 1
 EOF
 compare - $TMP.3 <<EOF || exit 1
 /*
- * Copyright &copy; 90, 2005, 2007-2010 Free Software Foundation, Inc.
+ * Copyright &copy; 1990, 2005, 2007-2010 Free Software Foundation, Inc.
  */
 EOF
 compare - $TMP.4 <<EOF || exit 1
-/* Copyright (C) 1990-2005, 2007-2009 Free Software
- * Foundation, Inc.  */
+## Copyright (C) 1990-2005, 2007-2009 Free Software
+#  Foundation, Inc.
 EOF
 compare - $TMP.5 <<EOF || exit 1
 Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
 EOF
 compare - $TMP.6 <<EOF || exit 1
-/* Copyright (C) 1990-2005, 2007-2009 Free Software
- * Foundation, Inc.  */
+## Copyright (C) 1990-2005, 2007-2009 Free Software
+#  Foundation, Inc.
 
 Copyright (C) 1990-2005, 2007-2010 Free Software Foundation, Inc.
 EOF
@@ -145,6 +182,52 @@ Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
 # Copyright (C) 1990-2005, 2007-2010 Free Software Foundation, Inc.
 EOF
 
+UPDATE_COPYRIGHT_YEAR=2010 UPDATE_COPYRIGHT_FORCE=1 \
+  update-copyright $TMP.? 1> $TMP-stdout 2> $TMP-stderr
+compare /dev/null $TMP-stdout || exit 1
+compare - $TMP-stderr <<EOF || exit 1
+$TMP.4: warning: copyright statement not found
+$TMP.5: warning: copyright statement not found
+EOF
+compare - $TMP.1 <<EOF || exit 1
+Copyright @copyright{} 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
+1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
+Free Software Foundation, Inc.
+EOF
+compare - $TMP.2 <<EOF || exit 1
+# Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+# 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 Free
+# Software Foundation, Inc.
+EOF
+compare - $TMP.3 <<EOF || exit 1
+/*
+ * Copyright &copy; 1990, 2005, 2007, 2008, 2009, 2010 Free Software
+ * Foundation, Inc.
+ */
+EOF
+compare - $TMP.4 <<EOF || exit 1
+## Copyright (C) 1990-2005, 2007-2009 Free Software
+#  Foundation, Inc.
+EOF
+compare - $TMP.5 <<EOF || exit 1
+Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
+EOF
+compare - $TMP.6 <<EOF || exit 1
+## Copyright (C) 1990-2005, 2007-2009 Free Software
+#  Foundation, Inc.
+
+Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 Free
+Software Foundation, Inc.
+EOF
+compare - $TMP.7 <<EOF || exit 1
+Copyright (C) 1990-2005, 2007-2009 Acme, Inc.
+
+# Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+# 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 Free
+# Software Foundation, Inc.
+EOF
+
 rm $TMP*
 
 ## -------------- ##
@@ -152,7 +235,7 @@ rm $TMP*
 ## -------------- ##
 
 TMP=$TMP_BASE-current-year
-YEAR=`/usr/bin/perl -e 'print [localtime]->[5] + 1900'`;
+YEAR=`date +%Y`
 cat > $TMP <<EOF
 '\" Copyright (C) 2006
 '\" Free Software Foundation,
@@ -164,6 +247,13 @@ compare /dev/null $TMP-stderr || exit 1
 compare - $TMP <<EOF || exit 1
 '\" Copyright (C) 2006, $YEAR Free Software Foundation, Inc.
 EOF
+UPDATE_COPYRIGHT_USE_INTERVALS=1 \
+  update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
+compare /dev/null $TMP-stdout || exit 1
+compare /dev/null $TMP-stderr || exit 1
+compare - $TMP <<EOF || exit 1
+'\" Copyright (C) 2006, $YEAR Free Software Foundation, Inc.
+EOF
 rm $TMP*
 
 ## ------------------ ##
@@ -209,6 +299,14 @@ compare - $TMP <<EOF || exit 1
 #### 1985, 1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
 #### 2006, 2007, 2008, 2010 Free Software Foundation, Inc.
 EOF
+UPDATE_COPYRIGHT_YEAR=2011 UPDATE_COPYRIGHT_USE_INTERVALS=1 \
+  update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
+compare /dev/null $TMP-stdout || exit 1
+compare /dev/null $TMP-stderr || exit 1
+compare - $TMP <<EOF || exit 1
+#### Copyright (C) 1976-1988, 1999-2008, 2010-2011 Free Software
+#### Foundation, Inc.
+EOF
 rm $TMP*
 
 ## ------------------- ##
@@ -225,7 +323,7 @@ UPDATE_COPYRIGHT_YEAR=2010 \
   update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
 compare /dev/null $TMP-stdout || exit 1
 compare - $TMP-stderr <<EOF || exit 1
-$TMP: warning: FSF copyright statement not found
+$TMP: warning: copyright statement not found
 EOF
 compare - $TMP <<EOF || exit 1
 ####  Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985,
@@ -254,7 +352,7 @@ UPDATE_COPYRIGHT_YEAR=2010 \
   update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
 compare /dev/null $TMP-stdout || exit 1
 compare - $TMP-stderr <<EOF || exit 1
-$TMP: warning: FSF copyright statement not found
+$TMP: warning: copyright statement not found
 EOF
 compare - $TMP <<EOF || exit 1
 #Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985,
@@ -284,9 +382,17 @@ UPDATE_COPYRIGHT_YEAR=2010 \
 compare /dev/null $TMP-stdout || exit 1
 compare /dev/null $TMP-stderr || exit 1
 compare - $TMP <<EOF || exit 1
-       Copyright (C) 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
-       98, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-       2009-2010 Free Software Foundation, Inc.
+       Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996,
+       1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+       2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+EOF
+UPDATE_COPYRIGHT_YEAR=2011 UPDATE_COPYRIGHT_USE_INTERVALS=1 \
+  update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
+compare /dev/null $TMP-stdout || exit 1
+compare /dev/null $TMP-stderr || exit 1
+compare - $TMP <<EOF || exit 1
+       Copyright (C) 1987-1988, 1991-2011 Free Software Foundation,
+       Inc.
 EOF
 rm $TMP*
 
@@ -296,7 +402,7 @@ rm $TMP*
 
 TMP=$TMP_BASE-unusual-ws
 cat > $TMP <<EOF
-               # Copyright (C) 8788, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
+               # Copyright (C) 87-88, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
                # 98, 1999, 2000, 2001, 2002, 2003,             \f         2004, 2005, 2006, 2007, 2008,
                # 2009 Free Software Foundation, Inc.
 EOF
@@ -305,11 +411,26 @@ UPDATE_COPYRIGHT_YEAR=2010 \
 compare /dev/null $TMP-stdout || exit 1
 compare /dev/null $TMP-stderr || exit 1
 compare - $TMP <<EOF || exit 1
-               # Copyright (C) 87, 88, 1991, 1992, 1993, 1994, 1995,
-               # 1996, 1997, 98, 1999, 2000, 2001, 2002, 2003, 2004,
-               # 2005, 2006, 2007, 2008, 2009-2010 Free Software
+               # Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994,
+               # 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
+               # 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
+               # Foundation, Inc.
+EOF
+UPDATE_COPYRIGHT_YEAR=2011 UPDATE_COPYRIGHT_USE_INTERVALS=1 \
+  update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
+compare /dev/null $TMP-stdout || exit 1
+compare /dev/null $TMP-stderr || exit 1
+compare - $TMP <<EOF || exit 1
+               # Copyright (C) 1987-1988, 1991-2011 Free Software
                # Foundation, Inc.
 EOF
+UPDATE_COPYRIGHT_YEAR=2011 UPDATE_COPYRIGHT_USE_INTERVALS=2 \
+  UPDATE_COPYRIGHT_FORCE=1 update-copyright $TMP 1> $TMP-stdout 2> $TMP-stderr
+compare /dev/null $TMP-stdout || exit 1
+compare /dev/null $TMP-stderr || exit 1
+compare - $TMP <<EOF || exit 1
+               # Copyright (C) 1987-2011 Free Software Foundation, Inc.
+EOF
 rm $TMP*
 
 ## --------- ##
@@ -327,9 +448,9 @@ UPDATE_COPYRIGHT_YEAR=2010 \
 compare /dev/null $TMP-stdout || exit 1
 compare /dev/null $TMP-stderr || exit 1
 tr @ '\015' > $TMP-exp <<\EOF
-Rem Copyright (C) 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 98,@
-Rem 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,@
-Rem 2009-2010 Free Software Foundation, Inc.@
+Rem Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997,@
+Rem 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,@
+Rem 20092010 Free Software Foundation, Inc.@
 EOF
 compare $TMP-exp $TMP || exit 1
 rm $TMP*
@@ -349,9 +470,77 @@ UPDATE_COPYRIGHT_YEAR=2010 \
 compare /dev/null $TMP-stdout || exit 1
 compare /dev/null $TMP-stderr || exit 1
 compare - $TMP <<EOF || exit 1
-  Copyright 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 98, 1999,
-  2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009-2010 Free
-  Software Foundation, Inc.
+  Copyright 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+  1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+  Free Software Foundation, Inc.
+EOF
+rm $TMP*
+
+## ------------------ ##
+## C-style comments.  ##
+## ------------------ ##
+
+TMP=$TMP_BASE-c-style-comments
+cat > $TMP.star <<EOF
+/*  Copyright 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
+ *  98, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+ *  2009 Free Software Foundation, Inc.  */
+EOF
+cat > $TMP.space <<EOF
+  /*Copyright 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
+    98, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+    2009 Free Software Foundation, Inc.  */
+EOF
+cat > $TMP.single-line <<EOF
+/*   Copyright 87, 1991, 1992 Free Software Foundation, Inc.  */
+EOF
+cat > $TMP.single-line-wrapped <<EOF
+ /* Copyright 1988, 1991, 1992, 1993 Free Software Foundation, Inc.  */
+EOF
+cat > $TMP.extra-text-star <<EOF
+ /* Copyright 1987, 1988, 1991, 1992 Free Software Foundation, Inc.  End
+  * More comments.  */
+EOF
+cat > $TMP.extra-text-space <<EOF
+ /* Copyright 1987, 1988, 1991, 1992 Free Software Foundation, Inc. ***
+    * End of comments. */
+EOF
+cat > $TMP.two-digit-final-is-substr-of-first <<EOF
+ /* Copyright 1991, 99 Free Software Foundation, Inc. */
+EOF
+UPDATE_COPYRIGHT_YEAR=2010 \
+  update-copyright $TMP.* 1> $TMP-stdout 2> $TMP-stderr
+compare /dev/null $TMP-stdout || exit 1
+compare /dev/null $TMP-stderr || exit 1
+compare - $TMP.star <<EOF || exit 1
+/*  Copyright 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
+ *  1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+ *  2009, 2010 Free Software Foundation, Inc.  */
+EOF
+compare - $TMP.space <<EOF || exit 1
+  /*Copyright 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
+    1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+    2009, 2010 Free Software Foundation, Inc.  */
+EOF
+compare - $TMP.single-line <<EOF || exit 1
+/*   Copyright 1987, 1991, 1992, 2010 Free Software Foundation, Inc.  */
+EOF
+compare - $TMP.single-line-wrapped <<EOF || exit 1
+ /* Copyright 1988, 1991, 1992, 1993, 2010 Free Software Foundation,
+  * Inc.  */
+EOF
+compare - $TMP.extra-text-star <<EOF || exit 1
+ /* Copyright 1987, 1988, 1991, 1992, 2010 Free Software Foundation,
+  * Inc.  End
+  * More comments.  */
+EOF
+compare - $TMP.extra-text-space <<EOF || exit 1
+ /* Copyright 1987, 1988, 1991, 1992, 2010 Free Software Foundation,
+    Inc. ***
+    * End of comments. */
+EOF
+compare - $TMP.two-digit-final-is-substr-of-first <<EOF || exit 1
+ /* Copyright 1991, 1999, 2010 Free Software Foundation, Inc. */
 EOF
 rm $TMP*