am-test-lib.sh 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. # -*- shell-script -*-
  2. #
  3. # Copyright (C) 1996-2017 Free Software Foundation, Inc.
  4. #
  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 2, or (at your option)
  8. # any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. ########################################################
  18. ### IMPORTANT NOTE: keep this file 'set -e' clean. ###
  19. ########################################################
  20. # Do not source several times.
  21. test ${am_test_lib_sourced-no} = yes && return 0
  22. am_test_lib_sourced=yes
  23. # A literal escape character. Used by test checking colored output.
  24. esc=''
  25. # This might be used in testcases checking distribution-related features.
  26. # Test scripts are free to override this if they need to.
  27. distdir=$me-1.0
  28. ## ---------------------- ##
  29. ## Environment cleanup. ##
  30. ## ---------------------- ##
  31. # Unset some make-related variables that may cause $MAKE to act like
  32. # a recursively invoked sub-make. Any $MAKE invocation in a test is
  33. # conceptually an independent invocation, not part of the main
  34. # 'automake' build.
  35. unset MFLAGS MAKEFLAGS AM_MAKEFLAGS MAKELEVEL
  36. unset __MKLVL__ MAKE_JOBS_FIFO # For BSD make.
  37. unset DMAKE_CHILD DMAKE_DEF_PRINTED DMAKE_MAX_JOBS # For Solaris dmake.
  38. # Unset verbosity flag.
  39. unset V
  40. # Also unset variables that might influence "make install".
  41. unset DESTDIR
  42. unset prefix exec_prefix bindir datarootdir datadir docdir dvidir
  43. unset htmldir includedir infodir libdir libexecdir localedir mandir
  44. unset oldincludedir pdfdir psdir sbindir sharedstatedir sysconfdir
  45. # Unset variables that might influence "make distcheck".
  46. unset DISTCHECK_CONFIGURE_FLAGS AM_DISTCHECK_CONFIGURE_FLAGS
  47. # Used by install rules for info files.
  48. unset AM_UPDATE_INFO_DIR
  49. # We don't want to use the $srcdir value exported by the test driver.
  50. unset srcdir
  51. # Also unset variables that control our test driver. While not
  52. # conceptually independent, they cause some changed semantics we
  53. # need to control (and test for) in some of the tests to ensure
  54. # backward-compatible behavior.
  55. unset TESTS_ENVIRONMENT AM_TESTS_ENVIRONMENT
  56. unset DISABLE_HARD_ERRORS
  57. unset AM_COLOR_TESTS
  58. unset TESTS
  59. unset XFAIL_TESTS
  60. unset TEST_LOGS
  61. unset TEST_SUITE_LOG
  62. unset RECHECK_LOGS
  63. unset VERBOSE
  64. for pfx in TEST_ SH_ TAP_ ''; do
  65. unset ${pfx}LOG_COMPILER
  66. unset ${pfx}LOG_COMPILE # Not a typo!
  67. unset ${pfx}LOG_FLAGS
  68. unset AM_${pfx}LOG_FLAGS
  69. unset ${pfx}LOG_DRIVER
  70. unset ${pfx}LOG_DRIVER_FLAGS
  71. unset AM_${pfx}LOG_DRIVER_FLAGS
  72. done
  73. unset pfx
  74. # cross_compiling
  75. # ---------------
  76. # Tell whether we are cross-compiling. This is especially useful to skip
  77. # tests (or portions of them) that requires a native compiler.
  78. cross_compiling ()
  79. {
  80. # Quoting from the autoconf manual:
  81. # ... [$host_alias and $build both] default to the result of running
  82. # config.guess, unless you specify either --build or --host. In
  83. # this case, the default becomes the system type you specified.
  84. # If you specify both, *and they're different*, configure enters
  85. # cross compilation mode (so it doesn't run any tests that require
  86. # execution).
  87. test x"$host_alias" != x && test x"$build_alias" != x"$host_alias"
  88. }
  89. # is_blocked_signal SIGNAL-NUMBER
  90. # --------------------------------
  91. # Return success if the given signal number is blocked in the shell,
  92. # return a non-zero exit status and print a proper diagnostic otherwise.
  93. is_blocked_signal ()
  94. {
  95. # Use perl, since trying to do this portably in the shell can be
  96. # very tricky, if not downright impossible. For reference, see:
  97. # <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
  98. if $PERL -w -e '
  99. use strict;
  100. use warnings FATAL => "all";
  101. use POSIX;
  102. my %oldsigaction = ();
  103. sigaction('"$1"', 0, \%oldsigaction);
  104. exit ($oldsigaction{"HANDLER"} eq "IGNORE" ? 0 : 77);
  105. '; then
  106. return 0
  107. elif test $? -eq 77; then
  108. return 1
  109. else
  110. fatal_ "couldn't determine whether signal $1 is blocked"
  111. fi
  112. }
  113. # single_quote STRING
  114. # -------------------
  115. # Single-quote STRING for the shell, also dealing with embedded single
  116. # quotes. Place the result in the '$am_result', that is thus to be
  117. # considered public.
  118. single_quote ()
  119. {
  120. am_result=$1
  121. case $am_result in
  122. *\'*) am_result=$(printf '%s\n' "$*" | sed -e "s/'/'\\\\''/g");;
  123. esac
  124. am_result="'$am_result'"
  125. }
  126. # append_single_quoted VARIABLE STRING
  127. # ------------------------------------
  128. append_single_quoted ()
  129. {
  130. am__var=$1; shift
  131. single_quote "$1" # Sets 'am_result'.
  132. eval "${am__var}=\${$am__var:+\"\${$am__var} \"}\$am_result"
  133. unset am__var am_result
  134. }
  135. # is_valid_varname STRING
  136. # -----------------------
  137. # Tell whether STRING is a valid name for a shell variable. Return 0
  138. # if yes, return 1 if not.
  139. is_valid_varname ()
  140. {
  141. # FIXME: is the below truly portable even for LC_COLLATE != "C" ?
  142. case $1 in
  143. [0-9]*) return 1;;
  144. *[!a-zA-Z0-9_]*) return 1;;
  145. esac
  146. return 0
  147. }
  148. # run_make [-e STATUS] [-O] [-E] [-M] [--] [VAR=VAL ...] [MAKE-ARGS...]
  149. # ---------------------------------------------------------------------
  150. #
  151. # Run $MAKE with the given command-line, and fail if it doesn't exit with
  152. # STATUS (default: 0). If STATUS is "FAIL", then any exit status > 0 is
  153. # acceptable. If STATUS is "IGNORE", any exit value is acceptable.
  154. #
  155. # Other options:
  156. #
  157. # -O save the standard output from make on disk, in a regular file
  158. # named 'stdout'.
  159. #
  160. # -E save the standard error from make on disk, in a regular file
  161. # named 'stderr'.
  162. #
  163. # -M save both the standard output and standard error from make on
  164. # disk, in a regular file named 'output'. This option supersedes
  165. # both the '-O' and '-E' options.
  166. #
  167. # This function also handle command-line override of variable definition
  168. # in a smart way, using AM_MAKEFLAGS if a non-GNU make implementation
  169. # is in use.
  170. #
  171. run_make ()
  172. {
  173. am__make_redirect_stdout=no
  174. am__make_redirect_stderr=no
  175. am__make_redirect_stdall=no
  176. am__make_flags=
  177. am__make_rc_exp=0
  178. # Follow-up code might want to analyse this, so mark is as
  179. # publicly accessible (no double undesrscore).
  180. am_make_rc=0
  181. # Parse options for this function.
  182. while test $# -gt 0; do
  183. case $1 in
  184. -e) am__make_rc_exp=$2; shift;;
  185. -O) am__make_redirect_stdout=yes;;
  186. -E) am__make_redirect_stderr=yes;;
  187. -M) am__make_redirect_stdall=yes;;
  188. --) shift; break;;
  189. *) break;;
  190. esac
  191. shift
  192. done
  193. # Use append mode here to avoid dropping output. See automake bug#11413
  194. if using_gmake; then
  195. # We can trust GNU make to correctly pass macro definitions given
  196. # on the command line down to sub-make invocations, and this allow
  197. # us to have a vary simple implementation: delegate all the work
  198. # to GNU make.
  199. :
  200. else
  201. # We have to explicitly parse arguments passed to make. Not 100%
  202. # safe w.r.t. options like '-I' that can have an argument, but
  203. # should be good enough for our usages so far.
  204. for am__x
  205. do
  206. case $am__x in
  207. *=*)
  208. am__maybe_var=${am__x%%=*}
  209. am__maybe_val=${am__x#*=}
  210. am__maybe_def="${am__maybe_var}=${am__maybe_val}"
  211. # Some variables should be portably overridable from the command
  212. # line, even when using non-GNU make.
  213. case $am__maybe_var in
  214. V|\
  215. DESTDIR|\
  216. SHELL|\
  217. VERBOSE|\
  218. DISABLE_HARD_ERRORS|\
  219. DISTCHECK_CONFIGURE_FLAGS)
  220. ;;
  221. *)
  222. if is_valid_varname "$am__maybe_var"; then
  223. append_single_quoted am__make_flags "$am__maybe_def"
  224. fi
  225. esac
  226. unset am__maybe_var am__maybe_val am__maybe_def
  227. ;;
  228. esac
  229. done
  230. unset am__x
  231. fi
  232. if test x"$am__make_flags" != x; then
  233. set AM_MAKEFLAGS="$am__make_flags" ${1+"$@"}
  234. unset am__make_flags
  235. fi
  236. # In redirecting make output below, use append mode, to avoid
  237. # dropping output. See automake bug#11413 for details.
  238. # The exit status of 253 is a more-or-less random choice, to
  239. # help us catch possible errors in redirections and error out
  240. # accordingly.
  241. (
  242. : exec $MAKE ${1+"$@"} # Display traces for future command.
  243. set +x # We need to remove them now, not to pollute redirected stderr.
  244. if test $am__make_redirect_stdall = yes; then
  245. : > output && exec 1>>output 2>&1 || exit 253
  246. else
  247. if test $am__make_redirect_stdout = yes; then
  248. : > stdout && exec 1>>stdout || exit 253
  249. fi
  250. if test $am__make_redirect_stderr = yes; then
  251. : > stderr && exec 2>>stderr || exit 253
  252. fi
  253. fi
  254. exec $MAKE ${1+"$@"}
  255. ) || am_make_rc=$?
  256. if test $am_make_rc -eq 253; then
  257. fatal_ "run_make: problems in redirecting make output"
  258. fi
  259. if test $am__make_redirect_stdall = yes; then
  260. cat output || fatal_ "displaying make output"
  261. else
  262. if test $am__make_redirect_stdout = yes; then
  263. cat stdout || fatal_ "displaying make output"
  264. fi
  265. if test $am__make_redirect_stderr = yes; then
  266. cat stderr >&2 || fatal_ "displaying make output"
  267. fi
  268. fi
  269. case $am__make_rc_exp in
  270. IGNORE)
  271. : Ignore exit status
  272. ;;
  273. FAIL)
  274. test $am_make_rc -gt 0 || return 1
  275. ;;
  276. *)
  277. test $am__make_rc_exp -ge 0 && test $am__make_rc_exp -le 255 \
  278. || fatal_ "invalid expected exit status: '$am__make_rc_exp'"
  279. test $am_make_rc -eq $am__make_rc_exp || return 1
  280. ;;
  281. esac
  282. }
  283. # AUTOMAKE_run [-e STATUS] [-d DESCRIPTION] [--] [AUTOMAKE-ARGS...]
  284. # -----------------------------------------------------------------
  285. # Run automake with AUTOMAKE-ARGS, and fail if it doesn't exit with
  286. # STATUS. Should be polymorphic for TAP and "plain" tests. The
  287. # DESCRIPTION, when provided, is used for console reporting, only if
  288. # the TAP protocol is in use in the current test script.
  289. AUTOMAKE_run ()
  290. {
  291. am__desc=
  292. am__exp_rc=0
  293. while test $# -gt 0; do
  294. case $1 in
  295. -d) am__desc=$2; shift;;
  296. -e) am__exp_rc=$2; shift;;
  297. --) shift; break;;
  298. # Don't fail on unknown option: assume they (and the rest of the
  299. # command line) are to be passed verbatim to automake (so stop our
  300. # own option parsing).
  301. *) break;;
  302. esac
  303. shift
  304. done
  305. am__got_rc=0
  306. $AUTOMAKE ${1+"$@"} >stdout 2>stderr || am__got_rc=$?
  307. cat stderr >&2
  308. cat stdout
  309. if test $am_test_protocol = none; then
  310. test $am__got_rc -eq $am__exp_rc || exit 1
  311. return
  312. fi
  313. if test -z "$am__desc"; then
  314. if test $am__got_rc -eq $am__exp_rc; then
  315. am__desc="automake exited $am__got_rc"
  316. else
  317. am__desc="automake exited $am__got_rc, expecting $am__exp_rc"
  318. fi
  319. fi
  320. command_ok_ "$am__desc" test $am__got_rc -eq $am__exp_rc
  321. }
  322. # AUTOMAKE_fails [-d DESCRIPTION] [OPTIONS...]
  323. # --------------------------------------------
  324. # Run automake with OPTIONS, and fail if doesn't exit with status 1.
  325. # Should be polymorphic for TAP and "plain" tests. The DESCRIPTION,
  326. # when provided, is used for console reporting, only if the TAP
  327. # protocol is in use in the current test script.
  328. AUTOMAKE_fails ()
  329. {
  330. AUTOMAKE_run -e 1 ${1+"$@"}
  331. }
  332. # extract_configure_help { --OPTION | VARIABLE-NAME } [FILES]
  333. # -----------------------------------------------------------
  334. # Use this to extract from the output of "./configure --help" (or similar)
  335. # the description or help message associated to the given --OPTION or
  336. # VARIABLE-NAME.
  337. extract_configure_help ()
  338. {
  339. am__opt_re='' am__var_re=''
  340. case $1 in
  341. --*'=') am__opt_re="^ $1";;
  342. --*'[=]') am__opt_re='^ '$(printf '%s\n' "$1" | sed 's/...$//')'\[=';;
  343. --*) am__opt_re="^ $1( .*|$)";;
  344. *) am__var_re="^ $1( .*|$)";;
  345. esac
  346. shift
  347. if test x"$am__opt_re" != x; then
  348. LC_ALL=C awk '
  349. /'"$am__opt_re"'/ { print; do_print = 1; next; }
  350. /^$/ { do_print = 0; next }
  351. /^ --/ { do_print = 0; next }
  352. (do_print == 1) { print }
  353. ' ${1+"$@"}
  354. else
  355. LC_ALL=C awk '
  356. /'"$am__var_re"'/ { print; do_print = 1; next; }
  357. /^$/ { do_print = 0; next }
  358. /^ [A-Z][A-Z0-9_]* / { do_print = 0; next }
  359. /^ [A-Z][A-Z0-9_]*$/ { do_print = 0; next }
  360. (do_print == 1) { print }
  361. ' ${1+"$@"}
  362. fi
  363. }
  364. # grep_configure_help { --OPTION | VARIABLE-NAME } REGEXP
  365. # -------------------------------------------------------
  366. # Grep the section of "./configure --help" output associated with either
  367. # --OPTION or VARIABLE-NAME for the given *extended* regular expression.
  368. grep_configure_help ()
  369. {
  370. ./configure --help > am--all-help \
  371. || { cat am--all-help; exit 1; }
  372. cat am--all-help
  373. extract_configure_help "$1" am--all-help > am--our-help \
  374. || { cat am--our-help; exit 1; }
  375. cat am--our-help
  376. $EGREP "$2" am--our-help || exit 1
  377. }
  378. # using_gmake
  379. # -----------
  380. # Return success if $MAKE is GNU make, return failure otherwise.
  381. # Caches the result for speed reasons.
  382. using_gmake ()
  383. {
  384. case $am__using_gmake in
  385. yes)
  386. return 0;;
  387. no)
  388. return 1;;
  389. '')
  390. # Use --version AND -v, because SGI Make doesn't fail on --version.
  391. # Also grep for GNU because newer versions of FreeBSD make do
  392. # not complain about --version (they seem to silently ignore it).
  393. if $MAKE --version -v | grep GNU; then
  394. am__using_gmake=yes
  395. return 0
  396. else
  397. am__using_gmake=no
  398. return 1
  399. fi;;
  400. *)
  401. fatal_ "invalid value for \$am__using_gmake: '$am__using_gmake'";;
  402. esac
  403. }
  404. am__using_gmake="" # Avoid interferences from the environment.
  405. # make_can_chain_suffix_rules
  406. # ---------------------------
  407. # Return 0 if $MAKE is a make implementation that can chain suffix rules
  408. # automatically, return 1 otherwise. Caches the result for speed reasons.
  409. make_can_chain_suffix_rules ()
  410. {
  411. if test -z "$am__can_chain_suffix_rules"; then
  412. if using_gmake; then
  413. am__can_chain_suffix_rules=yes
  414. return 0
  415. else
  416. mkdir am__chain.dir$$
  417. cd am__chain.dir$$
  418. unindent > Makefile << 'END'
  419. .SUFFIXES: .u .v .w
  420. .u.v: ; cp $< $@
  421. .v.w: ; cp $< $@
  422. END
  423. echo make can chain suffix rules > foo.u
  424. if $MAKE foo.w && diff foo.u foo.w; then
  425. am__can_chain_suffix_rules=yes
  426. else
  427. am__can_chain_suffix_rules=no
  428. fi
  429. cd ..
  430. rm -rf am__chain.dir$$
  431. fi
  432. fi
  433. case $am__can_chain_suffix_rules in
  434. yes) return 0;;
  435. no) return 1;;
  436. *) fatal_ "make_can_chain_suffix_rules: internal error";;
  437. esac
  438. }
  439. am__can_chain_suffix_rules="" # Avoid interferences from the environment.
  440. # useless_vpath_rebuild
  441. # ---------------------
  442. # Tell whether $MAKE suffers of the bug triggering automake bug#7884.
  443. # For example, this happens with FreeBSD make, since in a VPATH build
  444. # it tends to rebuilt files for which there is an explicit or even just
  445. # a suffix rule, even if said files are already available in the VPATH
  446. # directory.
  447. useless_vpath_rebuild ()
  448. {
  449. if test -z "$am__useless_vpath_rebuild"; then
  450. if using_gmake; then
  451. am__useless_vpath_rebuild=no
  452. return 1
  453. fi
  454. mkdir am__vpath.dir$$
  455. cd am__vpath.dir$$
  456. touch foo.a foo.b bar baz
  457. mkdir build
  458. cd build
  459. unindent > Makefile << 'END'
  460. .SUFFIXES: .a .b
  461. VPATH = ..
  462. all: foo.b baz
  463. .PHONY: all
  464. .a.b: ; cp $< $@
  465. baz: bar ; cp ../baz bar
  466. END
  467. if run_make all && test ! -e foo.b && test ! -e bar; then
  468. am__useless_vpath_rebuild=no
  469. else
  470. am__useless_vpath_rebuild=yes
  471. fi
  472. cd ../..
  473. rm -rf am__vpath.dir$$
  474. fi
  475. case $am__useless_vpath_rebuild in
  476. yes) return 0;;
  477. no) return 1;;
  478. "") ;;
  479. *) fatal_ "useless_vpath_rebuild: internal error";;
  480. esac
  481. }
  482. am__useless_vpath_rebuild=""
  483. yl_distcheck () { useless_vpath_rebuild || run_make distcheck ${1+"$@"}; }
  484. null_install ()
  485. {
  486. for am__v in nulldirs destdir instdir; do
  487. if ! eval 'test -n "$'$am__v'"'; then
  488. fatal_ "null_install() invoked with \$$am__v unset"
  489. fi
  490. done
  491. unset am__v
  492. case $#,$1 in
  493. 0,)
  494. am__inst='install';;
  495. 1,-t|1,--texi)
  496. am__inst='install install-html install-dvi install-ps install-pdf';;
  497. *)
  498. fatal_ "null_install(): invalid usage";;
  499. esac
  500. run_make $nulldirs $am__inst
  501. test ! -e "$instdir"
  502. run_make $nulldirs $am__inst DESTDIR="$destdir"
  503. test ! -e "$instdir"
  504. test ! -e "$destdir"
  505. run_make -M $nulldirs uninstall
  506. # Creative quoting below to please maintainer-check.
  507. grep 'rm'' ' output && exit 1
  508. run_make -M $nulldirs uninstall DESTDIR="$destdir"
  509. # Creative quoting below to please maintainer-check.
  510. grep 'rm'' ' output && exit 1
  511. : # For 'set -e'.
  512. }
  513. # count_test_results total=N pass=N fail=N xpass=N xfail=N skip=N error=N
  514. # -----------------------------------------------------------------------
  515. # Check that a testsuite run driven by the parallel-tests harness has
  516. # had the specified numbers of test results (specified by kind).
  517. # This function assumes that the output of "make check" or "make recheck"
  518. # has been saved in the 'stdout' file in the current directory, and its
  519. # log in the 'test-suite.log' file.
  520. count_test_results ()
  521. {
  522. # Use a subshell so that we won't pollute the script namespace.
  523. (
  524. # TODO: Do proper checks on the arguments?
  525. total=ERR pass=ERR fail=ERR xpass=ERR xfail=ERR skip=ERR error=ERR
  526. eval "$@"
  527. # For debugging.
  528. $EGREP -i '(total|x?pass|x?fail|skip|error)' stdout || :
  529. rc=0
  530. # Avoid spurious failures with shells with "overly sensible"
  531. # errexit shell flag, such as e.g., Solaris /bin/sh.
  532. set +e
  533. test $(grep -c '^PASS:' stdout) -eq $pass || rc=1
  534. test $(grep -c '^XFAIL:' stdout) -eq $xfail || rc=1
  535. test $(grep -c '^SKIP:' stdout) -eq $skip || rc=1
  536. test $(grep -c '^FAIL:' stdout) -eq $fail || rc=1
  537. test $(grep -c '^XPASS:' stdout) -eq $xpass || rc=1
  538. test $(grep -c '^ERROR:' stdout) -eq $error || rc=1
  539. grep "^# TOTAL: *$total$" stdout || rc=1
  540. grep "^# PASS: *$pass$" stdout || rc=1
  541. grep "^# XFAIL: *$xfail$" stdout || rc=1
  542. grep "^# SKIP: *$skip$" stdout || rc=1
  543. grep "^# FAIL: *$fail$" stdout || rc=1
  544. grep "^# XPASS: *$xpass$" stdout || rc=1
  545. grep "^# ERROR: *$error$" stdout || rc=1
  546. test $rc -eq 0
  547. )
  548. }
  549. # get_shell_script SCRIPT-NAME
  550. # -----------------------------
  551. # Fetch an Automake-provided shell script from the 'lib/' directory into
  552. # the current directory, and, if the '$am_test_prefer_config_shell'
  553. # variable is set to "yes", modify its shebang line to use $SHELL instead
  554. # of /bin/sh.
  555. get_shell_script ()
  556. {
  557. am_source=$1 am_target=${2-$1}
  558. test ! -f "$am_target" || rm -f "$am_target" || return 99
  559. if test x"$am_test_prefer_config_shell" = x"yes"; then
  560. sed "1s|#!.*|#! $SHELL|" "$am_scriptdir/$am_source" > "$am_target" \
  561. && chmod a+x "$am_target" \
  562. || return 99
  563. else
  564. cp -f "$am_scriptdir/$am_source" "$am_target" || return 99
  565. fi
  566. sed 10q "$am_target" # For debugging.
  567. unset am_target am_source
  568. }
  569. # fetch_tap_driver
  570. # ----------------
  571. # Fetch the Automake-provided TAP driver from the 'lib/' directory into
  572. # the current directory, and edit its shebang line so that it will be
  573. # run with the proper shell.
  574. fetch_tap_driver ()
  575. {
  576. AM_TAP_AWK=$AWK; export AM_TAP_AWK
  577. get_shell_script tap-driver.sh tap-driver
  578. }
  579. # require_xsi SHELL
  580. # -----------------
  581. # Skip the test if the given shell fails to support common XSI constructs.
  582. require_xsi ()
  583. {
  584. test $# -eq 1 || fatal_ "require_xsi needs exactly one argument"
  585. echo "$me: trying some XSI constructs with $1"
  586. $1 -c "$xsi_shell_code" || skip_all_ "$1 lacks XSI features"
  587. }
  588. # Shell code supposed to work only with XSI shells. Keep this in sync
  589. # with libtool.m4:_LT_CHECK_SHELL_FEATURES.
  590. xsi_shell_code='
  591. _lt_dummy="a/b/c"
  592. test "${_lt_dummy##*/},${_lt_dummy%/*},${_lt_dummy#??}"${_lt_dummy%"$_lt_dummy"}, \
  593. = c,a/b,b/c, \
  594. && eval '\''test $(( 1 + 1 )) -eq 2 \
  595. && test "${#_lt_dummy}" -eq 5'\'
  596. # $PYTHON and support for PEP-3147. Needed to check our python-related
  597. # install rules.
  598. python_has_pep3147 ()
  599. {
  600. if test -z "$am_pep3147_tag"; then
  601. am_pep3147_tag=$($PYTHON -c 'import imp; print(imp.get_tag())') \
  602. || am_pep3147_tag=none
  603. fi
  604. test $am_pep3147_tag != none
  605. }
  606. am_pep3147_tag=
  607. # pyc_location [-p] [FILE]
  608. # ------------------------
  609. # Determine what the actual location of the given '.pyc' or '.pyo'
  610. # byte-compiled file should be, taking into account PEP-3147. Save
  611. # the location in the '$am_pyc_file' variable. If the '-p' option
  612. # is given, print the location on the standard output as well.
  613. pyc_location ()
  614. {
  615. case $#,$1 in
  616. 2,-p) am_pyc_print=yes; shift;;
  617. 1,*) am_pyc_print=no;;
  618. *) fatal_ "pyc_location: invalid usage";;
  619. esac
  620. if python_has_pep3147; then
  621. case $1 in
  622. */*) am_pyc_dir=${1%/*} am_pyc_base=${1##*/};;
  623. *) am_pyc_dir=. am_pyc_base=$1;;
  624. esac
  625. am_pyc_ext=${am_pyc_base##*.}
  626. am_pyc_base=${am_pyc_base%.py?}
  627. am_pyc_file=$am_pyc_dir/__pycache__/$am_pyc_base.$am_pep3147_tag.$am_pyc_ext
  628. else
  629. am_pyc_file=$1
  630. fi
  631. test $am_pyc_print = no || printf '%s\n' "$am_pyc_file"
  632. }
  633. # py_installed [--not] FILE
  634. # --------------------------
  635. # Check that the given python FILE has been installed (resp. *not*
  636. # installed, if the '--not' option is specified). If FILE is a
  637. # byte-compiled '.pyc' file, the new installation layout specified
  638. # by PEP-3147 will be taken into account.
  639. py_installed ()
  640. {
  641. case $#,$1 in
  642. 1,*) am_test_py_file='test -f';;
  643. 2,--not) am_test_py_file='test ! -e'; shift;;
  644. *) fatal_ "pyc_installed: invalid usage";;
  645. esac
  646. case $1 in
  647. *.py[co]) pyc_location "$1"; am_target_py_file=$am_pyc_file;;
  648. *) am_target_py_file=$1;;
  649. esac
  650. $am_test_py_file "$am_target_py_file"
  651. }
  652. # Usage: require_compiler_ {cc|c++|fortran|fortran77}
  653. require_compiler_ ()
  654. {
  655. case $# in
  656. 0) fatal_ "require_compiler_: missing argument";;
  657. 1) ;;
  658. *) fatal_ "require_compiler_: too many arguments";;
  659. esac
  660. case $1 in
  661. cc)
  662. am__comp_lang="C"
  663. am__comp_var=CC
  664. am__comp_flag_vars='CFLAGS CPPFLAGS'
  665. ;;
  666. c++)
  667. am__comp_lang="C++"
  668. am__comp_var=CXX
  669. am__comp_flag_vars='CXXFLAGS CPPFLAGS'
  670. ;;
  671. fortran)
  672. am__comp_lang="Fortran"
  673. am__comp_var=FC
  674. am__comp_flag_vars='FCFLAGS'
  675. ;;
  676. fortran77)
  677. am__comp_lang="Fortran 77"
  678. am__comp_var=F77
  679. am__comp_flag_vars='FFLAGS'
  680. ;;
  681. esac
  682. shift
  683. eval "am__comp_prog=\${$am__comp_var}" \
  684. || fatal_ "expanding \${$am__comp_var} in require_compiler_"
  685. case $am__comp_prog in
  686. "")
  687. fatal_ "botched configuration: \$$am__comp_var is empty";;
  688. false)
  689. skip_all_ "no $am__comp_lang compiler available";;
  690. autodetect|autodetected)
  691. # Let the ./configure commands in the test script try to determine
  692. # these automatically.
  693. unset $am__comp_var $am__comp_flag_vars;;
  694. *)
  695. # Pre-set these for the ./configure commands in the test script.
  696. export $am__comp_var $am__comp_flag_vars;;
  697. esac
  698. # Delete private variables.
  699. unset am__comp_lang am__comp_prog am__comp_var am__comp_flag_vars
  700. }
  701. ## ----------------------------------------------------------- ##
  702. ## Checks for required tools, and additional setups (if any) ##
  703. ## required by them. ##
  704. ## ----------------------------------------------------------- ##
  705. require_tool ()
  706. {
  707. am_tool=$1
  708. case $1 in
  709. cc|c++|fortran|fortran77)
  710. require_compiler_ $1;;
  711. -c-o)
  712. if test x"$AM_TESTSUITE_SIMULATING_NO_CC_C_O" = x"yes"; then
  713. skip_all_ "need a C compiler that grasps -c and -o together"
  714. fi
  715. ;;
  716. xsi-lib-shell)
  717. if test x"$am_test_prefer_config_shell" = x"yes"; then
  718. require_xsi "$SHELL"
  719. else
  720. require_xsi "/bin/sh"
  721. fi
  722. ;;
  723. bzip2)
  724. # Do not use --version, older versions bzip2 still tries to compress
  725. # stdin.
  726. echo "$me: running bzip2 --help"
  727. bzip2 --help \
  728. || skip_all_ "required program 'bzip2' not available"
  729. ;;
  730. cl)
  731. CC=cl
  732. # Don't export CFLAGS, as that could have been initialized to only
  733. # work with the C compiler detected at configure time. If the user
  734. # wants CFLAGS to also influence 'cl', he can still export CFLAGS
  735. # in the environment "by hand" before calling the testsuite.
  736. export CC CPPFLAGS
  737. echo "$me: running $CC -?"
  738. # The IRAF package (http://iraf.noao.edu/) contains a 'cl' program
  739. # which is interactive, and which could cause the testsuite to hang
  740. # if its standard input is not redirected. See automake bug#14707.
  741. $CC -? </dev/null \
  742. || skip_all_ "Microsoft C compiler '$CC' not available"
  743. ;;
  744. icl)
  745. CC=icl
  746. # Don't export CFLAGS, as that could have been initialized to only
  747. # work with the C compiler detected at configure time. If the user
  748. # wants CFLAGS to also influence 'icl', he can still export CFLAGS
  749. # in the environment "by hand" before calling the testsuite.
  750. export CC CPPFLAGS
  751. echo "$me: running $CC -?"
  752. $CC -? >/dev/null \
  753. || skip_all_ "Intel C compiler '$CC' not available"
  754. ;;
  755. etags)
  756. # Exuberant Ctags will create a TAGS file even
  757. # when asked for --help or --version. (Emacs's etags
  758. # does not have such problem.) Use -o /dev/null
  759. # to make sure we do not pollute the build directory.
  760. echo "$me: running etags --version -o /dev/null"
  761. etags --version -o /dev/null \
  762. || skip_all_ "required program 'etags' not available"
  763. ;;
  764. GNUmake)
  765. for am_make in "$MAKE" gmake gnumake :; do
  766. MAKE=$am_make
  767. am__using_gmake= # Invalidate cache used by 'using_gmake()'.
  768. test "$MAKE" = : && break
  769. echo "$me: determine whether $MAKE is GNU make"
  770. using_gmake && break
  771. : For shells with busted 'set -e'.
  772. done
  773. test "$MAKE" = : && skip_all_ "this test requires GNU make"
  774. export MAKE
  775. unset am_make
  776. ;;
  777. gcj)
  778. GCJ=$GNU_GCJ GCJFLAGS=$GNU_GCJFLAGS; export GCJ GCJFLAGS
  779. test "$GCJ" = false && skip_all_ "GNU Java compiler unavailable"
  780. : For shells with busted 'set -e'.
  781. ;;
  782. gcc)
  783. CC=$GNU_CC CFLAGS=$GNU_CFLAGS; export CC CFLAGS CPPFLAGS
  784. test "$CC" = false && skip_all_ "GNU C compiler unavailable"
  785. : For shells with busted 'set -e'.
  786. ;;
  787. g++)
  788. CXX=$GNU_CXX CXXFLAGS=$GNU_CXXFLAGS; export CXX CXXFLAGS CPPFLAGS
  789. test "$CXX" = false && skip_all_ "GNU C++ compiler unavailable"
  790. : For shells with busted 'set -e'.
  791. ;;
  792. gfortran)
  793. FC=$GNU_FC FCFLAGS=$GNU_FCFLAGS; export FC FCFLAGS
  794. test "$FC" = false && skip_all_ "GNU Fortran compiler unavailable"
  795. case " $required " in
  796. *\ g77\ *) ;;
  797. *) F77=$FC FFLAGS=$FCFLAGS; export F77 FFLAGS;;
  798. esac
  799. ;;
  800. g77)
  801. F77=$GNU_F77 FFLAGS=$GNU_FFLAGS; export F77 FFLAGS
  802. test "$F77" = false && skip_all_ "GNU Fortran 77 compiler unavailable"
  803. case " $required " in
  804. *\ gfortran\ *) ;;
  805. *) FC=$F77 FCFLAGS=$FFLAGS; export FC FCFLAGS;;
  806. esac
  807. ;;
  808. grep-nonprint)
  809. # Check that grep can parse nonprinting characters correctly.
  810. # BSD 'grep' works from a pipe, but not a seekable file.
  811. # GNU or BSD 'grep -a' works on files, but is not portable.
  812. case $(echo "$esc" | grep .)$(echo "$esc" | grep "$esc") in
  813. "$esc$esc") ;;
  814. *) skip_ "grep can't handle nonprinting characters correctly";;
  815. esac
  816. ;;
  817. javac)
  818. # The Java compiler from JDK 1.5 (and presumably earlier versions)
  819. # cannot handle the '-version' option by itself: it bails out
  820. # telling that source files are missing. Adding also the '-help'
  821. # option seems to solve the problem.
  822. echo "$me: running javac -version -help"
  823. javac -version -help || skip_all_ "Sun Java compiler not available"
  824. ;;
  825. java)
  826. # See the comments above about 'javac' for why we use also '-help'.
  827. echo "$me: running java -version -help"
  828. java -version -help || skip_all_ "Sun Java interpreter not found"
  829. ;;
  830. lib)
  831. AR=lib; export AR
  832. # Attempting to create an empty archive will actually not
  833. # create the archive, but lib will output its version.
  834. echo "$me: running $AR -out:defstest.lib"
  835. $AR -out:defstest.lib \
  836. || skip_all_ "Microsoft 'lib' utility not available"
  837. ;;
  838. makedepend)
  839. echo "$me: running makedepend -f-"
  840. makedepend -f- \
  841. || skip_all_ "required program 'makedepend' not available"
  842. ;;
  843. mingw)
  844. uname_s=$(uname -s || echo UNKNOWN)
  845. echo "$me: system name: $uname_s"
  846. case $uname_s in
  847. MINGW*) ;;
  848. *) skip_all_ "this test requires MSYS in MinGW mode" ;;
  849. esac
  850. unset uname_s
  851. ;;
  852. non-root)
  853. # Skip this test case if the user is root.
  854. # We try to append to a read-only file to detect this.
  855. priv_check_temp=am--priv-check.$$
  856. touch $priv_check_temp && chmod a-w $priv_check_temp \
  857. || framework_failure_ "creating unwritable file $priv_check_temp"
  858. # Not a useless use of subshell: lesser shells might bail
  859. # out if a builtin fails.
  860. overwrite_status=0
  861. (echo foo >> $priv_check_temp) || overwrite_status=$?
  862. rm -f $priv_check_temp
  863. if test $overwrite_status -eq 0; then
  864. skip_all_ "cannot drop file write permissions"
  865. fi
  866. unset priv_check_temp overwrite_status
  867. ;;
  868. # Extra quoting required to avoid maintainer-check spurious failures.
  869. 'perl-threads')
  870. if test "$WANT_NO_THREADS" = "yes"; then
  871. skip_all_ "Devel::Cover cannot cope with threads"
  872. fi
  873. ;;
  874. native)
  875. # Don't use "&&" here, to avoid a bug of 'set -e' present in
  876. # some (even relatively recent) versions of the BSD shell.
  877. # We add the dummy "else" branch for extra safety.
  878. ! cross_compiling || skip_all_ "doesn't work in cross-compile mode"
  879. ;;
  880. python)
  881. PYTHON=${PYTHON-python}
  882. # Older python versions don't support --version, they have -V.
  883. echo "$me: running $PYTHON -V"
  884. $PYTHON -V || skip_all_ "python interpreter not available"
  885. ;;
  886. ro-dir)
  887. # Skip this test case if read-only directories aren't supported
  888. # (e.g., under DOS.)
  889. ro_dir_temp=ro_dir.$$
  890. mkdir $ro_dir_temp && chmod a-w $ro_dir_temp \
  891. || framework_failure_ "creating unwritable directory $ro_dir_temp"
  892. # Not a useless use of subshell: lesser shells might bail
  893. # out if a builtin fails.
  894. create_status=0
  895. (: > $ro_dir_temp/probe) || create_status=$?
  896. rm -rf $ro_dir_temp
  897. if test $create_status -eq 0; then
  898. skip_all_ "cannot drop directory write permissions"
  899. fi
  900. unset ro_dir_temp create_status
  901. ;;
  902. runtest)
  903. # DejaGnu's runtest program. We rely on being able to specify
  904. # the program on the runtest command-line. This requires
  905. # DejaGnu 1.4.3 or later.
  906. echo "$me: running runtest SOMEPROGRAM=someprogram --version"
  907. runtest SOMEPROGRAM=someprogram --version \
  908. || skip_all_ "DejaGnu is not available"
  909. ;;
  910. tex)
  911. # No all versions of Tex support '--version', so we use
  912. # a configure check.
  913. if test -z "$TEX"; then
  914. skip_all_ "TeX is required, but it wasn't found by configure"
  915. fi
  916. ;;
  917. lex)
  918. test x"$LEX" = x"false" && skip_all_ "lex not found or disabled"
  919. export LEX
  920. ;;
  921. yacc)
  922. test x"$YACC" = x"false" && skip_all_ "yacc not found or disabled"
  923. export YACC
  924. ;;
  925. flex)
  926. LEX=flex; export LEX
  927. echo "$me: running flex --version"
  928. flex --version || skip_all_ "required program 'flex' not available"
  929. ;;
  930. bison)
  931. YACC='bison -y'; export YACC
  932. echo "$me: running bison --version"
  933. bison --version || skip_all_ "required program 'bison' not available"
  934. ;;
  935. valac)
  936. echo "$me: running valac --version"
  937. if ! valac --version; then
  938. skip_all_ "required program 'valac' not available"
  939. elif cross_compiling; then
  940. skip_all_ "cross-compiling valac-generated C files is brittle"
  941. fi
  942. # TODO: We also know we need GNU make, the C compiler, and pkg-config
  943. # here, but there is no easy way to express this with the current
  944. # code organization. We should improve the situation, sooner or
  945. # later. At which point the tests requiring 'valac' can drop the
  946. # explicit requirements for those tools.
  947. ;;
  948. *)
  949. # Generic case: the tool must support --version.
  950. echo "$me: running $1 --version"
  951. # It is not likely but possible that the required tool is a special
  952. # builtin, in which case the shell is allowed to exit after an error.
  953. # So we need the subshell here. Also, some tools, like Sun cscope,
  954. # can be interactive without redirection.
  955. ($1 --version) </dev/null \
  956. || skip_all_ "required program '$1' not available"
  957. ;;
  958. esac
  959. }
  960. process_requirements ()
  961. {
  962. # Look for (and maybe set up) required tools and/or system features;
  963. # skip the current test if they are not found.
  964. for am_tool in $*; do
  965. require_tool $am_tool
  966. done
  967. # We might need extra m4 macros, e.g., for Libtool or Gettext.
  968. for am_tool in gettext libtool pkg-config; do
  969. case " $required " in
  970. # The lack of whitespace after $am_tool is intended.
  971. *" $am_tool"*) . ./t/$am_tool-macros.dir/get.sh;;
  972. esac
  973. done
  974. unset am_tool
  975. }
  976. ## ---------------------------------------------------------------- ##
  977. ## Create and set up of the temporary directory used by the test. ##
  978. ## ---------------------------------------------------------------- ##
  979. am_setup_testdir ()
  980. {
  981. # The subdirectory where the current test script will run and write its
  982. # temporary/data files. This will be created shortly, and will be removed
  983. # by the cleanup trap below if the test passes. If the test doesn't pass,
  984. # this directory will be kept, to facilitate debugging.
  985. am_test_subdir=${argv0#$am_rel_srcdir/}
  986. case $am_test_subdir in
  987. */*) am_test_subdir=${am_test_subdir%/*}/$me.dir;;
  988. *) am_test_subdir=$me.dir;;
  989. esac
  990. test ! -e $am_test_subdir || rm_rf_ $am_test_subdir \
  991. || framework_failure_ "removing old test subdirectory"
  992. $MKDIR_P $am_test_subdir \
  993. || framework_failure_ "creating test subdirectory"
  994. cd $am_test_subdir \
  995. || framework_failure_ "cannot chdir into test subdirectory"
  996. if test x"$am_create_testdir" != x"empty"; then
  997. cp "$am_scriptdir"/install-sh "$am_scriptdir"/missing \
  998. "$am_scriptdir"/compile "$am_scriptdir"/depcomp . \
  999. || framework_failure_ "fetching common files from $am_scriptdir"
  1000. # Build appropriate environment in test directory. E.g., create
  1001. # configure.ac, touch all necessary files, etc. Don't use AC_OUTPUT,
  1002. # but AC_CONFIG_FILES so that appending still produces a valid
  1003. # configure.ac. But then, tests running config.status really need
  1004. # to append AC_OUTPUT.
  1005. {
  1006. echo "AC_INIT([$me], [1.0])"
  1007. if test x"$am_serial_tests" = x"yes"; then
  1008. echo "AM_INIT_AUTOMAKE([serial-tests])"
  1009. else
  1010. echo "AM_INIT_AUTOMAKE"
  1011. fi
  1012. echo "AC_CONFIG_FILES([Makefile])"
  1013. } >configure.ac || framework_failure_ "creating configure.ac skeleton"
  1014. fi
  1015. }
  1016. am_extra_info ()
  1017. {
  1018. echo "Running from installcheck: $am_running_installcheck"
  1019. echo "Test Protocol: $am_test_protocol"
  1020. echo "PATH = $PATH"
  1021. }