#!/bin/sh # Test suite for update-copyright. # Copyright (C) 2009-2013 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 . setglobal diffout = $[diff -u /dev/null /dev/null !2 > !1] if test x"$diffout" = x"" && test $Status -eq 0 { proc compare { diff -u @Argv; } } else { proc compare { cmp @Argv; } } # Ensure the update-copyright program gets found. setglobal PATH = "$abs_aux_dir:$PATH" export PATH setglobal TMP_BASE = 'update-copyright.test' trap 'rm -f $TMP_BASE*' 0 1 2 3 15 ## --------------------------------- ## ## Skip if user does not have perl. ## ## --------------------------------- ## setglobal TMP = $TMP_BASE setglobal s = "$TMP-script" cat << ''' > $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/ ''' > $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] || do { 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' || do { echo '$0: skipping this test; Perl version is too old' !1 > !2 exit 77 } # Do not let a different envvar setting perturb results. setglobal UPDATE_COPYRIGHT_MAX_LINE_LENGTH = '72' export UPDATE_COPYRIGHT_MAX_LINE_LENGTH ## ----------------------------- ## ## Examples from documentation. ## ## ----------------------------- ## setglobal TMP = "$TMP_BASE-ex" cat > $TMP.1 << """ Copyright @copyright{} 1990-2005, 2007-2009 Free Software Foundation, Inc. """ cat > $TMP.2 << """ # Copyright (C) 1990-2005, 2007-2009 Free Software # Foundation, Inc. """ cat > $TMP.3 << """ /* * Copyright © 90,2005,2007-2009 * Free Software Foundation, Inc. */ """ cat > $TMP.4 << """ ## Copyright (C) 1990-2005, 2007-2009 Free Software # Foundation, Inc. """ cat > $TMP.5 << """ Copyright (C) 1990-2005, 2007-2009 Acme, Inc. """ cat > $TMP.6 << """ ## Copyright (C) 1990-2005, 2007-2009 Free Software # Foundation, Inc. Copyright (C) 1990-2005, 2007-2009 Free Software Foundation, Inc. """ cat > $TMP.7 << """ Copyright (C) 1990-2005, 2007-2009 Acme, Inc. # Copyright (C) 1990-2005, 2007-2009 Free Software # Foundation, Inc. """ env UPDATE_COPYRIGHT_YEAR=2009 \ update-copyright $TMP.? !1 > $TMP-stdout !2 > $TMP-stderr compare /dev/null $TMP-stdout || exit 1 compare - $TMP-stderr << """ || exit 1 $TMP.4: warning: copyright statement not found $TMP.5: warning: copyright statement not found """ compare - $TMP.1 << """ || exit 1 Copyright @copyright{} 1990-2005, 2007-2009 Free Software Foundation, Inc. """ compare - $TMP.2 << """ || exit 1 # Copyright (C) 1990-2005, 2007-2009 Free Software # Foundation, Inc. """ compare - $TMP.3 << """ || exit 1 /* * Copyright © 90,2005,2007-2009 * Free Software Foundation, Inc. */ """ compare - $TMP.4 << """ || exit 1 ## Copyright (C) 1990-2005, 2007-2009 Free Software # Foundation, Inc. """ compare - $TMP.5 << """ || exit 1 Copyright (C) 1990-2005, 2007-2009 Acme, Inc. """ compare - $TMP.6 << """ || exit 1 ## Copyright (C) 1990-2005, 2007-2009 Free Software # Foundation, Inc. Copyright (C) 1990-2005, 2007-2009 Free Software Foundation, Inc. """ compare - $TMP.7 << """ || exit 1 Copyright (C) 1990-2005, 2007-2009 Acme, Inc. # Copyright (C) 1990-2005, 2007-2009 Free Software # Foundation, Inc. """ env 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 << """ || exit 1 $TMP.4: warning: copyright statement not found $TMP.5: warning: copyright statement not found """ compare - $TMP.1 << """ || exit 1 Copyright @copyright{} 1990-2005, 2007-2010 Free Software Foundation, Inc. """ compare - $TMP.2 << """ || exit 1 # Copyright (C) 1990-2005, 2007-2010 Free Software Foundation, Inc. """ compare - $TMP.3 << """ || exit 1 /* * Copyright © 1990, 2005, 2007-2010 Free Software Foundation, Inc. */ """ compare - $TMP.4 << """ || exit 1 ## Copyright (C) 1990-2005, 2007-2009 Free Software # Foundation, Inc. """ compare - $TMP.5 << """ || exit 1 Copyright (C) 1990-2005, 2007-2009 Acme, Inc. """ compare - $TMP.6 << """ || exit 1 ## Copyright (C) 1990-2005, 2007-2009 Free Software # Foundation, Inc. Copyright (C) 1990-2005, 2007-2010 Free Software Foundation, Inc. """ compare - $TMP.7 << """ || exit 1 Copyright (C) 1990-2005, 2007-2009 Acme, Inc. # Copyright (C) 1990-2005, 2007-2010 Free Software Foundation, Inc. """ env 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 << """ || exit 1 $TMP.4: warning: copyright statement not found $TMP.5: warning: copyright statement not found """ compare - $TMP.1 << """ || 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. """ compare - $TMP.2 << """ || 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. """ compare - $TMP.3 << """ || exit 1 /* * Copyright © 1990, 2005, 2007, 2008, 2009, 2010 Free Software * Foundation, Inc. */ """ compare - $TMP.4 << """ || exit 1 ## Copyright (C) 1990-2005, 2007-2009 Free Software # Foundation, Inc. """ compare - $TMP.5 << """ || exit 1 Copyright (C) 1990-2005, 2007-2009 Acme, Inc. """ compare - $TMP.6 << """ || 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. """ compare - $TMP.7 << """ || 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. """ rm $TMP* ## -------------- ## ## Current year. ## ## -------------- ## setglobal TMP = "$TMP_BASE-current-year" setglobal YEAR = $[date +%Y] cat > $TMP << """ ''"' Copyright (C) 2006 ''"' Free Software Foundation, ''"' Inc. """ 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 << """ || exit 1 ''"' Copyright (C) 2006, $YEAR Free Software Foundation, Inc. """ env 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 << """ || exit 1 ''"' Copyright (C) 2006, $YEAR Free Software Foundation, Inc. """ rm $TMP* ## ------------------ ## ## Surrounding text. ## ## ------------------ ## setglobal TMP = "$TMP_BASE-surrounding-text" cat > $TMP << """ Undisturbed text. dnl Undisturbed text. dnl Copyright (C) 89 dnl Free Software Foundation, Inc. dnl Undisturbed text. """ env 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 << """ || exit 1 Undisturbed text. dnl Undisturbed text. dnl Copyright (C) 1989, 2010 Free Software Foundation, Inc. dnl Undisturbed text. """ rm $TMP* ## --------------- ## ## Widest prefix. ## ## --------------- ## setglobal TMP = "$TMP_BASE-widest-prefix" cat > $TMP << """ #### Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, #### 1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, #### 2008 Free Software Foundation, Inc. """ env 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 << """ || exit 1 #### Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, #### 1985, 1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, #### 2006, 2007, 2008, 2010 Free Software Foundation, Inc. """ env 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 << """ || exit 1 #### Copyright (C) 1976-1988, 1999-2008, 2010-2011 Free Software #### Foundation, Inc. """ rm $TMP* ## ------------------- ## ## Prefix too large. ## ## ------------------- ## setglobal TMP = "$TMP_BASE-prefix-too-large" cat > $TMP << """ #### Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, #### 1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, #### 2008 Free Software Foundation, Inc. """ env UPDATE_COPYRIGHT_YEAR=2010 \ update-copyright $TMP !1 > $TMP-stdout !2 > $TMP-stderr compare /dev/null $TMP-stdout || exit 1 compare - $TMP-stderr << """ || exit 1 $TMP: warning: copyright statement not found """ compare - $TMP << """ || exit 1 #### Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, #### 1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, #### 2008 Free Software Foundation, Inc. """ rm $TMP* ## ------------- ## ## Blank lines. ## ## ------------- ## setglobal TMP = "$TMP_BASE-blank-lines" cat > $TMP << """ #Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, # #1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, #2008 Free Software Foundation, Inc. Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. """ env UPDATE_COPYRIGHT_YEAR=2010 \ update-copyright $TMP !1 > $TMP-stdout !2 > $TMP-stderr compare /dev/null $TMP-stdout || exit 1 compare - $TMP-stderr << """ || exit 1 $TMP: warning: copyright statement not found """ compare - $TMP << """ || exit 1 #Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, # #1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, #2008 Free Software Foundation, Inc. Copyright (C) 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. """ rm $TMP* ## -------------- ## ## Leading tabs. ## ## -------------- ## setglobal TMP = "$TMP_BASE-leading-tabs" cat > $TMP << """ Copyright (C) 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. """ env 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 << """ || exit 1 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. """ env 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 << """ || exit 1 Copyright (C) 1987-1988, 1991-2011 Free Software Foundation, Inc. """ rm $TMP* ## -------------------- ## ## Unusual whitespace. ## ## -------------------- ## setglobal TMP = "$TMP_BASE-unusual-ws" cat > $TMP << """ # Copyright (C) 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. """ env 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 << """ || exit 1 # 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. """ env 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 << """ || exit 1 # Copyright (C) 1987-1988, 1991-2011 Free Software # Foundation, Inc. """ env 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 << """ || exit 1 # Copyright (C) 1987-2011 Free Software Foundation, Inc. """ rm $TMP* ## --------- ## ## DOS EOL. ## ## --------- ## setglobal TMP = "$TMP_BASE-dos-eol" tr @ '\015' > $TMP << ''' Rem Copyright (C) 87, 88, 1991, 1992, 1993, 1994, 1995, 1996, 1997,@ Rem 98, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,@ Rem 2009 Free Software Foundation, Inc.@ ''' env 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 tr @ '\015' > $TMP-exp << ''' 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 2009, 2010 Free Software Foundation, Inc.@ ''' compare $TMP-exp $TMP || exit 1 rm $TMP* ## --------------- ## ## Omitted "(C)". ## ## --------------- ## setglobal TMP = "$TMP_BASE-omitted-circle-c" cat > $TMP << """ 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. """ env 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 << """ || 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. """ rm $TMP* ## ------------------ ## ## C-style comments. ## ## ------------------ ## setglobal TMP = "$TMP_BASE-c-style-comments" cat > $TMP.star << """ /* 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. */ """ cat > $TMP.space << """ /*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. */ """ cat > $TMP.single-line << """ /* Copyright 87, 1991, 1992 Free Software Foundation, Inc. */ """ cat > $TMP.single-line-wrapped << """ /* Copyright 1988, 1991, 1992, 1993 Free Software Foundation, Inc. */ """ cat > $TMP.extra-text-star << """ /* Copyright 1987, 1988, 1991, 1992 Free Software Foundation, Inc. End * More comments. */ """ cat > $TMP.extra-text-space << """ /* Copyright 1987, 1988, 1991, 1992 Free Software Foundation, Inc. *** * End of comments. */ """ cat > $TMP.two-digit-final-is-substr-of-first << """ /* Copyright 1991, 99 Free Software Foundation, Inc. */ """ env 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 << """ || 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. */ """ compare - $TMP.space << """ || 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. */ """ compare - $TMP.single-line << """ || exit 1 /* Copyright 1987, 1991, 1992, 2010 Free Software Foundation, Inc. */ """ compare - $TMP.single-line-wrapped << """ || exit 1 /* Copyright 1988, 1991, 1992, 1993, 2010 Free Software Foundation, * Inc. */ """ compare - $TMP.extra-text-star << """ || exit 1 /* Copyright 1987, 1988, 1991, 1992, 2010 Free Software Foundation, * Inc. End * More comments. */ """ compare - $TMP.extra-text-space << """ || exit 1 /* Copyright 1987, 1988, 1991, 1992, 2010 Free Software Foundation, Inc. *** * End of comments. */ """ compare - $TMP.two-digit-final-is-substr-of-first << """ || exit 1 /* Copyright 1991, 1999, 2010 Free Software Foundation, Inc. */ """ rm $TMP* exit 0