help-version.sh 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. #! /bin/sh
  2. # Make sure all these programs work properly
  3. # when invoked with --help or --version.
  4. # Copyright (C) 2000-2016 Free Software Foundation, Inc.
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. # Ensure that $SHELL is set to *some* value and exported.
  16. # This is required for dircolors, which would fail e.g., when
  17. # invoked via debuild (which removes SHELL from the environment).
  18. test "x$SHELL" = x && SHELL=/bin/sh
  19. export SHELL
  20. . "${srcdir=.}/init.sh"; path_prepend_ .
  21. expected_failure_status_chroot=125
  22. expected_failure_status_env=125
  23. expected_failure_status_nice=125
  24. expected_failure_status_nohup=125
  25. expected_failure_status_stdbuf=125
  26. expected_failure_status_su=125
  27. expected_failure_status_timeout=125
  28. expected_failure_status_printenv=2
  29. expected_failure_status_tty=3
  30. expected_failure_status_sort=2
  31. expected_failure_status_expr=3
  32. expected_failure_status_lbracket=2
  33. expected_failure_status_dir=2
  34. expected_failure_status_ls=2
  35. expected_failure_status_vdir=2
  36. expected_failure_status_cmp=2
  37. expected_failure_status_zcmp=2
  38. expected_failure_status_sdiff=2
  39. expected_failure_status_diff3=2
  40. expected_failure_status_diff=2
  41. expected_failure_status_zdiff=2
  42. expected_failure_status_zgrep=2
  43. expected_failure_status_zegrep=2
  44. expected_failure_status_zfgrep=2
  45. expected_failure_status_grep=2
  46. expected_failure_status_egrep=2
  47. expected_failure_status_fgrep=2
  48. test "$built_programs" \
  49. || fail_ "built_programs not specified!?!"
  50. test "$VERSION" \
  51. || fail_ "set envvar VERSION; it is required for a PATH sanity-check"
  52. # Extract version from --version output of the first program
  53. for i in $built_programs; do
  54. v=$(env $i --version | sed -n '1s/.* //p;q')
  55. break
  56. done
  57. # Ensure that it matches $VERSION.
  58. test "x$v" = "x$VERSION" \
  59. || fail_ "--version-\$VERSION mismatch"
  60. for lang in C fr da; do
  61. for i in $built_programs; do
  62. # Skip `test'; it doesn't accept --help or --version.
  63. test $i = test && continue;
  64. # false fails even when invoked with --help or --version.
  65. if test $i = false; then
  66. env LC_MESSAGES=$lang $i --help >/dev/null && fail=1
  67. env LC_MESSAGES=$lang $i --version >/dev/null && fail=1
  68. continue
  69. fi
  70. args=
  71. # The just-built install executable is always named `ginstall'.
  72. test $i = install && i=ginstall
  73. # Make sure they exit successfully, under normal conditions.
  74. eval "env \$i $args --help > h-\$i " || fail=1
  75. eval "env \$i $args --version >/dev/null" || fail=1
  76. # Make sure they mention the bug-reporting address in --help output.
  77. grep "$PACKAGE_BUGREPORT" h-$i > /dev/null || fail=1
  78. rm -f h-$i
  79. # Make sure they fail upon `disk full' error.
  80. if test -w /dev/full && test -c /dev/full; then
  81. eval "env \$i $args --help >/dev/full 2>/dev/null" && fail=1
  82. eval "env \$i $args --version >/dev/full 2>/dev/null" && fail=1
  83. status=$?
  84. test $i = [ && prog=lbracket || prog=$i
  85. eval "expected=\$expected_failure_status_$prog"
  86. test x$expected = x && expected=1
  87. if test $status = $expected; then
  88. : # ok
  89. else
  90. fail=1
  91. echo "*** $i: bad exit status \`$status' (expected $expected)," 1>&2
  92. echo " with --help or --version output redirected to /dev/full" 1>&2
  93. fi
  94. fi
  95. done
  96. done
  97. bigZ_in=bigZ-in.Z
  98. zin=zin.gz
  99. zin2=zin2.gz
  100. tmp=tmp-$$
  101. tmp_in=in-$$
  102. tmp_in2=in2-$$
  103. tmp_dir=dir-$$
  104. tmp_out=out-$$
  105. mkdir $tmp || fail=1
  106. cd $tmp || fail=1
  107. comm_setup () { args="$tmp_in $tmp_in"; }
  108. csplit_setup () { args="$tmp_in //"; }
  109. cut_setup () { args='-f 1'; }
  110. join_setup () { args="$tmp_in $tmp_in"; }
  111. tr_setup () { args='a a'; }
  112. chmod_setup () { args="a+x $tmp_in"; }
  113. # Punt on these.
  114. chgrp_setup () { args=--version; }
  115. chown_setup () { args=--version; }
  116. mkfifo_setup () { args=--version; }
  117. mknod_setup () { args=--version; }
  118. # Punt on uptime, since it fails (e.g., failing to get boot time)
  119. # on some systems, and we shouldn't let that stop `make check'.
  120. uptime_setup () { args=--version; }
  121. # Create a file in the current directory, not in $TMPDIR.
  122. mktemp_setup () { args=mktemp.XXXX; }
  123. cmp_setup () { args="$tmp_in $tmp_in2"; }
  124. # Tell dd not to print the line with transfer rate and total.
  125. # The transfer rate would vary between runs.
  126. dd_setup () { args=status=noxfer; }
  127. zdiff_setup () { args="$args $zin $zin2"; }
  128. zcmp_setup () { zdiff_setup; }
  129. zcat_setup () { args="$args $zin"; }
  130. gunzip_setup () { zcat_setup; }
  131. zmore_setup () { zcat_setup; }
  132. zless_setup () { zcat_setup; }
  133. znew_setup () { args="$args $bigZ_in"; }
  134. zforce_setup () { zcat_setup; }
  135. zgrep_setup () { args="$args z $zin"; }
  136. zegrep_setup () { zgrep_setup; }
  137. zfgrep_setup () { zgrep_setup; }
  138. gzexe_setup () { args="$args $tmp_in"; }
  139. # We know that $tmp_in contains a "0"
  140. grep_setup () { args="0 $tmp_in"; }
  141. egrep_setup () { args="0 $tmp_in"; }
  142. fgrep_setup () { args="0 $tmp_in"; }
  143. diff_setup () { args="$tmp_in $tmp_in2"; }
  144. sdiff_setup () { args="$tmp_in $tmp_in2"; }
  145. diff3_setup () { args="$tmp_in $tmp_in2 $tmp_in2"; }
  146. cp_setup () { args="$tmp_in $tmp_in2"; }
  147. ln_setup () { args="$tmp_in ln-target"; }
  148. ginstall_setup () { args="$tmp_in $tmp_in2"; }
  149. mv_setup () { args="$tmp_in $tmp_in2"; }
  150. mkdir_setup () { args=$tmp_dir/subdir; }
  151. rmdir_setup () { args=$tmp_dir; }
  152. rm_setup () { args=$tmp_in; }
  153. shred_setup () { args=$tmp_in; }
  154. touch_setup () { args=$tmp_in2; }
  155. truncate_setup () { args="--reference=$tmp_in $tmp_in2"; }
  156. basename_setup () { args=$tmp_in; }
  157. dirname_setup () { args=$tmp_in; }
  158. expr_setup () { args=foo; }
  159. # Punt, in case GNU `id' hasn't been installed yet.
  160. groups_setup () { args=--version; }
  161. pathchk_setup () { args=$tmp_in; }
  162. yes_setup () { args=--version; }
  163. logname_setup () { args=--version; }
  164. nohup_setup () { args=--version; }
  165. printf_setup () { args=foo; }
  166. seq_setup () { args=10; }
  167. sleep_setup () { args=0; }
  168. su_setup () { args=--version; }
  169. stdbuf_setup () { args="-oL true"; }
  170. timeout_setup () { args=--version; }
  171. # I'd rather not run sync, since it spins up disks that I've
  172. # deliberately caused to spin down (but not unmounted).
  173. sync_setup () { args=--version; }
  174. test_setup () { args=foo; }
  175. # This is necessary in the unusual event that there is
  176. # no valid entry in /etc/mtab.
  177. df_setup () { args=/; }
  178. # This is necessary in the unusual event that getpwuid (getuid ()) fails.
  179. id_setup () { args=-u; }
  180. # Use env to avoid invoking built-in sleep of Solaris 11's /bin/sh.
  181. kill_setup () {
  182. env sleep 10m &
  183. args=$!
  184. }
  185. link_setup () { args="$tmp_in link-target"; }
  186. unlink_setup () { args=$tmp_in; }
  187. readlink_setup () {
  188. ln -s . slink
  189. args=slink;
  190. }
  191. stat_setup () { args=$tmp_in; }
  192. unlink_setup () { args=$tmp_in; }
  193. lbracket_setup () { args=": ]"; }
  194. # Ensure that each program "works" (exits successfully) when doing
  195. # something more than --help or --version.
  196. for i in $built_programs; do
  197. # Skip these.
  198. case $i in chroot|stty|tty|false|chcon|runcon) continue;; esac
  199. rm -rf $tmp_in $tmp_in2 $tmp_dir $tmp_out $bigZ_in $zin $zin2
  200. echo z |gzip > $zin
  201. cp $zin $zin2
  202. cp $zin $bigZ_in
  203. # This is sort of kludgey: use numbers so this is valid input for factor,
  204. # and two tokens so it's valid input for tsort.
  205. echo 2147483647 0 > $tmp_in
  206. # Make $tmp_in2 identical. Then, using $tmp_in and $tmp_in2 as arguments
  207. # to the likes of cmp and diff makes them exit successfully.
  208. cp $tmp_in $tmp_in2
  209. mkdir $tmp_dir
  210. # echo ================== $i
  211. test $i = [ && prog=lbracket || prog=$i
  212. args=
  213. if type ${prog}_setup > /dev/null 2>&1; then
  214. ${prog}_setup
  215. fi
  216. if eval "env \$i $args < \$tmp_in > \$tmp_out"; then
  217. : # ok
  218. else
  219. echo FAIL: $i
  220. fail=1
  221. fi
  222. rm -rf $tmp_in $tmp_in2 $tmp_out $tmp_dir
  223. done
  224. Exit $fail