maint: prefer HTTPS to HTTP, FTP in URLs
[debian/gzip] / tests / help-version
index ebdc69af32a39e73406998f27b58e9a0b6eb9440..8bcfe5d078cf9c71c0c3f0fa175037069c4bdc6a 100755 (executable)
@@ -2,7 +2,7 @@
 # Make sure all these programs work properly
 # when invoked with --help or --version.
 
-# Copyright (C) 2000-2010 Free Software Foundation, Inc.
+# Copyright (C) 2000-2017 Free Software Foundation, Inc.
 
 # 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
@@ -15,9 +15,7 @@
 # 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 <http://www.gnu.org/licenses/>.
-
-test "$VERBOSE" = yes && set -x
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 # Ensure that $SHELL is set to *some* value and exported.
 # This is required for dircolors, which would fail e.g., when
@@ -25,8 +23,7 @@ test "$VERBOSE" = yes && set -x
 test "x$SHELL" = x && SHELL=/bin/sh
 export SHELL
 
-: ${srcdir=.}
-. "$srcdir/tests/init.sh"
+. "${srcdir=.}/init.sh"; path_prepend_ ..
 
 expected_failure_status_chroot=125
 expected_failure_status_env=125
@@ -54,8 +51,25 @@ expected_failure_status_zgrep=2
 expected_failure_status_zegrep=2
 expected_failure_status_zfgrep=2
 
+expected_failure_status_grep=2
+expected_failure_status_egrep=2
+expected_failure_status_fgrep=2
+
 test "$built_programs" \
-  || { echo "$this_test: no programs built!?!" 1>&2; Exit 1; }
+  || fail_ "built_programs not specified!?!"
+
+test "$VERSION" \
+  || fail_ "set envvar VERSION; it is required for a PATH sanity-check"
+
+# Extract version from --version output of the first program
+for i in $built_programs; do
+  v=$(env $i --version | sed -n '1s/.* //p;q')
+  break
+done
+
+# Ensure that it matches $VERSION.
+test "x$v" = "x$VERSION" \
+  || fail_ "--version-\$VERSION mismatch"
 
 for lang in C fr da; do
   for i in $built_programs; do
@@ -70,12 +84,14 @@ for lang in C fr da; do
       continue
     fi
 
+    args=
+
     # The just-built install executable is always named `ginstall'.
     test $i = install && i=ginstall
 
     # Make sure they exit successfully, under normal conditions.
-    env $i --help    > h-$i     || fail=1
-    env $i --version >/dev/null || fail=1
+    eval "env \$i $args --help    > h-\$i   " || fail=1
+    eval "env \$i $args --version >/dev/null" || fail=1
 
     # Make sure they mention the bug-reporting address in --help output.
     grep "$PACKAGE_BUGREPORT" h-$i > /dev/null || fail=1
@@ -83,8 +99,8 @@ for lang in C fr da; do
 
     # Make sure they fail upon `disk full' error.
     if test -w /dev/full && test -c /dev/full; then
-      env $i --help    >/dev/full 2>/dev/null && fail=1
-      env $i --version >/dev/full 2>/dev/null && fail=1
+      eval "env \$i $args --help    >/dev/full 2>/dev/null" && fail=1
+      eval "env \$i $args --version >/dev/full 2>/dev/null" && fail=1
       status=$?
       test $i = [ && prog=lbracket || prog=$i
       eval "expected=\$expected_failure_status_$prog"
@@ -112,102 +128,111 @@ tmp_out=out-$$
 mkdir $tmp || fail=1
 cd $tmp || fail=1
 
-comm_args="$tmp_in $tmp_in"
-csplit_args="$tmp_in //"
-cut_args='-f 1'
-join_args="$tmp_in $tmp_in"
-tr_args='a a'
+comm_setup () { args="$tmp_in $tmp_in"; }
+csplit_setup () { args="$tmp_in //"; }
+cut_setup () { args='-f 1'; }
+join_setup () { args="$tmp_in $tmp_in"; }
+tr_setup () { args='a a'; }
 
-chmod_args="a+x $tmp_in"
+chmod_setup () { args="a+x $tmp_in"; }
 # Punt on these.
-chgrp_args=--version
-chown_args=--version
-mkfifo_args=--version
-mknod_args=--version
+chgrp_setup () { args=--version; }
+chown_setup () { args=--version; }
+mkfifo_setup () { args=--version; }
+mknod_setup () { args=--version; }
 # Punt on uptime, since it fails (e.g., failing to get boot time)
 # on some systems, and we shouldn't let that stop `make check'.
-uptime_args=--version
+uptime_setup () { args=--version; }
 
 # Create a file in the current directory, not in $TMPDIR.
-mktemp_args=mktemp.XXXX
+mktemp_setup () { args=mktemp.XXXX; }
 
-cmp_args="$tmp_in $tmp_in2"
+cmp_setup () { args="$tmp_in $tmp_in2"; }
 
 # Tell dd not to print the line with transfer rate and total.
 # The transfer rate would vary between runs.
-dd_args=status=noxfer
-
-zdiff_args="$zin $zin2"
-zcmp_args="$zin $zin2"
-zcat_args=$zin
-gunzip_args=$zin
-zmore_args=$zin
-zless_args=$zin
-znew_args=$bigZ_in
-zforce_args=$zin
-zgrep_args="z $zin"
-zegrep_args="z $zin"
-zfgrep_args="z $zin"
-gzexe_args=$tmp_in
-
-diff_args="$tmp_in $tmp_in2"
-sdiff_args="$tmp_in $tmp_in2"
-diff3_args="$tmp_in $tmp_in2 $tmp_in2"
-cp_args="$tmp_in $tmp_in2"
-ln_args="$tmp_in ln-target"
-ginstall_args="$tmp_in $tmp_in2"
-mv_args="$tmp_in $tmp_in2"
-mkdir_args=$tmp_dir/subdir
-rmdir_args=$tmp_dir
-rm_args=$tmp_in
-shred_args=$tmp_in
-touch_args=$tmp_in2
-truncate_args="--reference=$tmp_in $tmp_in2"
-
-basename_args=$tmp_in
-dirname_args=$tmp_in
-expr_args=foo
+dd_setup () { args=status=noxfer; }
+
+zdiff_setup () { args="$args $zin $zin2"; }
+zcmp_setup () { zdiff_setup; }
+zcat_setup () { TERM=dumb; export TERM; args="$args $zin"; }
+gunzip_setup () { zcat_setup; }
+zmore_setup () { zcat_setup; }
+zless_setup () { zcat_setup; }
+znew_setup () { args="$args $bigZ_in"; }
+zforce_setup () { zcat_setup; }
+zgrep_setup () { args="$args z $zin"; }
+zegrep_setup () { zgrep_setup; }
+zfgrep_setup () { zgrep_setup; }
+gzexe_setup () { args="$args $tmp_in"; }
+
+# We know that $tmp_in contains a "0"
+grep_setup () { args="0 $tmp_in"; }
+egrep_setup () { args="0 $tmp_in"; }
+fgrep_setup () { args="0 $tmp_in"; }
+
+diff_setup () { args="$tmp_in $tmp_in2"; }
+sdiff_setup () { args="$tmp_in $tmp_in2"; }
+diff3_setup () { args="$tmp_in $tmp_in2 $tmp_in2"; }
+cp_setup () { args="$tmp_in $tmp_in2"; }
+ln_setup () { args="$tmp_in ln-target"; }
+ginstall_setup () { args="$tmp_in $tmp_in2"; }
+mv_setup () { args="$tmp_in $tmp_in2"; }
+mkdir_setup () { args=$tmp_dir/subdir; }
+rmdir_setup () { args=$tmp_dir; }
+rm_setup () { args=$tmp_in; }
+shred_setup () { args=$tmp_in; }
+touch_setup () { args=$tmp_in2; }
+truncate_setup () { args="--reference=$tmp_in $tmp_in2"; }
+
+basename_setup () { args=$tmp_in; }
+dirname_setup () { args=$tmp_in; }
+expr_setup () { args=foo; }
 
 # Punt, in case GNU `id' hasn't been installed yet.
-groups_args=--version
-
-pathchk_args=$tmp_in
-yes_args=--version
-logname_args=--version
-nohup_args=--version
-printf_args=foo
-seq_args=10
-sleep_args=0
-su_args=--version
-stdbuf_args="-oL true"
-timeout_args=--version
+groups_setup () { args=--version; }
+
+pathchk_setup () { args=$tmp_in; }
+yes_setup () { args=--version; }
+logname_setup () { args=--version; }
+nohup_setup () { args=--version; }
+printf_setup () { args=foo; }
+seq_setup () { args=10; }
+sleep_setup () { args=0; }
+su_setup () { args=--version; }
+stdbuf_setup () { args="-oL true"; }
+timeout_setup () { args=--version; }
 
 # I'd rather not run sync, since it spins up disks that I've
 # deliberately caused to spin down (but not unmounted).
-sync_args=--version
+sync_setup () { args=--version; }
 
-test_args=foo
+test_setup () { args=foo; }
 
 # This is necessary in the unusual event that there is
 # no valid entry in /etc/mtab.
-df_args=/
+df_setup () { args=/; }
 
 # This is necessary in the unusual event that getpwuid (getuid ()) fails.
-id_args=-u
+id_setup () { args=-u; }
 
 # Use env to avoid invoking built-in sleep of Solaris 11's /bin/sh.
-env sleep 10m &
-kill_args=$!
+kill_setup () {
+  env sleep 10m &
+  args=$!
+}
 
-link_args="$tmp_in link-target"
-unlink_args=$tmp_in
+link_setup () { args="$tmp_in link-target"; }
+unlink_setup () { args=$tmp_in; }
 
-ln -s . slink
-readlink_args=slink
+readlink_setup () {
+  ln -s . slink
+  args=slink;
+}
 
-stat_args=$tmp_in
-unlink_args=$tmp_in
-lbracket_args=": ]"
+stat_setup () { args=$tmp_in; }
+unlink_setup () { args=$tmp_in; }
+lbracket_setup () { args=": ]"; }
 
 # Ensure that each program "works" (exits successfully) when doing
 # something more than --help or --version.
@@ -219,13 +244,21 @@ for i in $built_programs; do
   echo z |gzip > $zin
   cp $zin $zin2
   cp $zin $bigZ_in
-  echo > $tmp_in
-  echo > $tmp_in2
+
+  # This is sort of kludgey: use numbers so this is valid input for factor,
+  # and two tokens so it's valid input for tsort.
+  echo 2147483647 0 > $tmp_in
+  # Make $tmp_in2 identical. Then, using $tmp_in and $tmp_in2 as arguments
+  # to the likes of cmp and diff makes them exit successfully.
+  cp $tmp_in $tmp_in2
   mkdir $tmp_dir
   # echo ================== $i
   test $i = [ && prog=lbracket || prog=$i
-  eval "args=\$${prog}_args"
-  if env $i $args < $tmp_in > $tmp_out; then
+  args=
+  if type ${prog}_setup > /dev/null 2>&1; then
+    ${prog}_setup
+  fi
+  if eval "env \$i $args < \$tmp_in > \$tmp_out"; then
     : # ok
   else
     echo FAIL: $i