general.m4 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215
  1. # This file is part of Autoconf. -*- Autoconf -*-
  2. # M4 macros used in building test suites.
  3. m4_define([_AT_COPYRIGHT_YEARS], [
  4. Copyright (C) 2000-2012 Free Software Foundation, Inc.
  5. ])
  6. # This file is part of Autoconf. This program is free
  7. # software; you can redistribute it and/or modify it under the
  8. # terms of the GNU General Public License as published by the
  9. # Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # Under Section 7 of GPL version 3, you are granted additional
  18. # permissions described in the Autoconf Configure Script Exception,
  19. # version 3.0, as published by the Free Software Foundation.
  20. #
  21. # You should have received a copy of the GNU General Public License
  22. # and a copy of the Autoconf Configure Script Exception along with
  23. # this program; see the files COPYINGv3 and COPYING.EXCEPTION
  24. # respectively. If not, see <http://www.gnu.org/licenses/>.
  25. # _m4_divert(DIVERSION-NAME)
  26. # --------------------------
  27. # Convert a diversion name into its number. Otherwise, return
  28. # DIVERSION-NAME which is supposed to be an actual diversion number.
  29. # Of course it would be nicer to use m4_case here, instead of zillions
  30. # of little macros, but it then takes twice longer to run `autoconf'!
  31. #
  32. # From M4sugar:
  33. # -1. KILL
  34. # 10000. GROW
  35. #
  36. # From M4sh:
  37. # 0. BINSH
  38. # 1. HEADER-REVISION
  39. # 2. HEADER-COMMENT
  40. # 3. HEADER-COPYRIGHT
  41. # 4. M4SH-SANITIZE
  42. # 5. M4SH-INIT
  43. # 1000. BODY
  44. #
  45. # Defined below:
  46. # - DEFAULTS
  47. # Overall initialization, value of $at_groups_all.
  48. # - PARSE_ARGS_BEGIN
  49. # Setup defaults required for option processing.
  50. # - PARSE_ARGS
  51. # Option processing. After AT_INIT, user options can be entered here as
  52. # cases of a case statement.
  53. # - PARSE_ARGS_END
  54. # Finish up the option processing.
  55. #
  56. # - HELP
  57. # Start printing the help message.
  58. # - HELP_MODES
  59. # Modes help text. Additional modes can be appended as self-contained
  60. # cat'd here-docs as generated by AS_HELP_STRING.
  61. # - HELP_TUNING_BEGIN
  62. # Tuning help text. This is for Autotest-provided text.
  63. # - HELP_TUNING
  64. # Additional tuning options' help text can be appended here as
  65. # self-contained cat'd here-docs as generated by AS_HELP_STRING.
  66. # - HELP_OTHER
  67. # User help can be appended to this as self-contained cat'd here-docs.
  68. # - HELP_END
  69. # Finish up the help texts.
  70. #
  71. # - VERSION
  72. # Head of the handling of --version.
  73. # - VERSION_NOTICES
  74. # Copyright notices for --version.
  75. # - VERSION_END
  76. # Tail of the handling of --version.
  77. #
  78. # - BANNERS
  79. # Output shell initialization for the associative array of banner text.
  80. # - TESTS_BEGIN
  81. # Like DEFAULTS but run after argument processing for purposes of
  82. # optimization. Do anything else that needs to be done to prepare for
  83. # tests. Sets up verbose and log file descriptors. Sets and logs PATH.
  84. # - PREPARE_TESTS
  85. # Declares functions shared among the tests. Perform any user
  86. # initialization to be shared among all tests.
  87. # - TESTS
  88. # The core of the test suite.
  89. #
  90. # - TEST_SCRIPT
  91. # The collector for code for each test, the ``normal'' diversion, but
  92. # undiverted into other locations before final output.
  93. #
  94. # - TEST_GROUPS
  95. # Contents of each test group. The tests deliberately occur after the
  96. # end of the shell script, so that the shell need not spend time parsing
  97. # commands it will not execute.
  98. m4_define([_m4_divert(DEFAULTS)], 100)
  99. m4_define([_m4_divert(PARSE_ARGS_BEGIN)], 200)
  100. m4_define([_m4_divert(PARSE_ARGS)], 201)
  101. m4_define([_m4_divert(PARSE_ARGS_END)], 202)
  102. m4_define([_m4_divert(HELP)], 300)
  103. m4_define([_m4_divert(HELP_MODES)], 301)
  104. m4_define([_m4_divert(HELP_TUNING_BEGIN)], 302)
  105. m4_define([_m4_divert(HELP_TUNING)], 303)
  106. m4_define([_m4_divert(HELP_OTHER)], 304)
  107. m4_define([_m4_divert(HELP_END)], 305)
  108. m4_define([_m4_divert(VERSION)], 350)
  109. m4_define([_m4_divert(VERSION_NOTICES)], 351)
  110. m4_define([_m4_divert(VERSION_END)], 352)
  111. m4_define([_m4_divert(BANNERS)], 400)
  112. m4_define([_m4_divert(TESTS_BEGIN)], 401)
  113. m4_define([_m4_divert(PREPARE_TESTS)], 402)
  114. m4_define([_m4_divert(TESTS)], 403)
  115. m4_define([_m4_divert(TEST_SCRIPT)], 450)
  116. m4_define([_m4_divert(TEST_GROUPS)], 500)
  117. # AT_LINE
  118. # -------
  119. # Return the current file sans directory, a colon, and the current
  120. # line. Be sure to return a _quoted_ file name, so if, for instance,
  121. # the user is lunatic enough to have a file named `dnl' (and I, for
  122. # one, love to be brainless and stubborn sometimes), then we return a
  123. # quoted name.
  124. #
  125. # Gee, we can't use simply
  126. #
  127. # m4_bpatsubst(__file__, [^.*/\(.*\)], [[\1]])
  128. #
  129. # since then, since `dnl' doesn't match the pattern, it is returned
  130. # with once quotation level less, so you lose! And since GNU M4
  131. # is one of the biggest junk in the whole universe wrt regexp, don't
  132. # even think about using `?' or `\?'. Bah, `*' will do.
  133. # Pleeeeeeeease, Gary, provide us with dirname and ERE!
  134. #
  135. # M4 recompiles the regular expression for every m4_bpatsubst, but __file__
  136. # rarely changes. Be fast - only compute the dirname when necessary; for
  137. # autoconf alone, this shaves off several seconds in building testsuite.
  138. m4_define([_AT_LINE_file])
  139. m4_define([_AT_LINE_base])
  140. m4_define([AT_LINE],
  141. [m4_if(m4_defn([_AT_LINE_file]), __file__, [],
  142. [m4_do([m4_define([_AT_LINE_file], __file__)],
  143. [m4_define([_AT_LINE_base],
  144. m4_bregexp(/__file__, [/\([^/]*\)$], [[\1]]))])])dnl
  145. m4_defn([_AT_LINE_base]):__line__])
  146. # _AT_LINE_ESCAPED
  147. # ----------------
  148. # Same as AT_LINE, but already escaped for the shell.
  149. m4_define([_AT_LINE_ESCAPED], ["AS_ESCAPE(m4_dquote(AT_LINE))"])
  150. # _AT_NORMALIZE_TEST_GROUP_NUMBER(SHELL-VAR)
  151. # ------------------------------------------
  152. # Normalize SHELL-VAR so that its value has the same number of digits as
  153. # all the other test group numbers.
  154. m4_define([_AT_NORMALIZE_TEST_GROUP_NUMBER],
  155. [
  156. eval 'while :; do
  157. case $$1 in #(
  158. '"$at_format"'*) break;;
  159. esac
  160. $1=0$$1
  161. done'
  162. ])
  163. # _AT_DEFINE_INIT(NAME, [DEFINITION])
  164. # -----------------------------------
  165. # Define macro NAME to die if invoked prior to AT_INIT, and to DEFINITION
  166. # after AT_INIT.
  167. m4_define([_AT_DEFINE_INIT],
  168. [m4_define($@)m4_pushdef([$1], [m4_fatal([$1: missing AT_INIT detected])])dnl
  169. m4_append([_AT_DEFINE_INIT_LIST], [[$1]], [,])])
  170. # _AT_DEFINE_SETUP(NAME, [DEFINITION])
  171. # ------------------------------------
  172. # Define macro NAME to die if invoked outside AT_SETUP/AT_CLEANUP, and
  173. # to DEFINITION otherwise.
  174. m4_define([_AT_DEFINE_SETUP],
  175. [m4_define([$1], [m4_ifndef([AT_ingroup],
  176. [m4_fatal([$1: missing AT_SETUP detected])])$2])])
  177. # AT_INIT([TESTSUITE-NAME])
  178. # -------------------------
  179. # Begin test suite.
  180. m4_define([AT_INIT],
  181. [m4_pushdef([AT_INIT], [m4_fatal([$0: invoked multiple times])])]
  182. [m4_pattern_forbid([^_?AT_])]
  183. [m4_pattern_allow([^_ATEOF$])]
  184. [m4_ifndef([AT_PACKAGE_BUGREPORT], [m4_fatal(
  185. [$1: AT_PACKAGE_BUGREPORT is missing, consider writing package.m4])])]
  186. [m4_define([AT_TESTSUITE_NAME],
  187. m4_defn([AT_PACKAGE_STRING])[ test suite]m4_ifval([$1],
  188. [m4_expand([: $1])]))]
  189. [m4_define([AT_ordinal], 0)]
  190. [m4_define([AT_banner_ordinal], 0)]
  191. [m4_define([AT_help_all], [])]
  192. [m4_map_args([_m4_popdef], _AT_DEFINE_INIT_LIST)]
  193. [m4_wrap([_AT_FINISH])]
  194. [AS_INIT[]]dnl
  195. dnl We don't use m4sh's BODY diversion, but AS_INIT sticks a banner there.
  196. dnl This trick removes that banner, since it adds nothing to autotest.
  197. [m4_cleardivert([BODY])]dnl
  198. [AS_ME_PREPARE[]]dnl
  199. [m4_divert_push([DEFAULTS])]dnl
  200. [AT_COPYRIGHT(m4_defn([_AT_COPYRIGHT_YEARS]), [
  201. m4_copyright_condense])]
  202. [AT_COPYRIGHT(
  203. [This test suite is free software; the Free Software Foundation gives
  204. unlimited permission to copy, distribute and modify it.], [m4_echo])]
  205. [AS_PREPARE
  206. SHELL=${CONFIG_SHELL-/bin/sh}
  207. # How were we run?
  208. at_cli_args="$[@]"
  209. m4_divert_push([BANNERS])dnl
  210. # Should we print banners? Yes if more than one test is run.
  211. case $at_groups in #(
  212. *$as_nl* )
  213. at_print_banners=: ;; #(
  214. * ) at_print_banners=false ;;
  215. esac
  216. # Text for banner N, set to a single space once printed.
  217. m4_divert_pop([BANNERS])dnl back to DEFAULTS
  218. m4_divert_push([PREPARE_TESTS])dnl
  219. m4_text_box([Autotest shell functions.])
  220. AS_FUNCTION_DESCRIBE([at_fn_banner], [NUMBER],
  221. [Output banner NUMBER, provided the testsuite is running multiple groups
  222. and this particular banner has not yet been printed.])
  223. at_fn_banner ()
  224. {
  225. $at_print_banners || return 0
  226. eval at_banner_text=\$at_banner_text_$[1]
  227. test "x$at_banner_text" = "x " && return 0
  228. eval "at_banner_text_$[1]=\" \""
  229. if test -z "$at_banner_text"; then
  230. $at_first || echo
  231. else
  232. AS_ECHO(["$as_nl$at_banner_text$as_nl"])
  233. fi
  234. } # at_fn_banner
  235. AS_FUNCTION_DESCRIBE([at_fn_check_prepare_notrace], [REASON LINE],
  236. [Perform AT_CHECK preparations for the command at LINE for an
  237. untraceable command; REASON is the reason for disabling tracing.])
  238. at_fn_check_prepare_notrace ()
  239. {
  240. $at_trace_echo "Not enabling shell tracing (command contains $[1])"
  241. AS_ECHO(["$[2]"]) >"$at_check_line_file"
  242. at_check_trace=: at_check_filter=:
  243. : >"$at_stdout"; : >"$at_stderr"
  244. }
  245. AS_FUNCTION_DESCRIBE([at_fn_check_prepare_trace], [LINE],
  246. [Perform AT_CHECK preparations for the command at LINE for a traceable
  247. command.])
  248. at_fn_check_prepare_trace ()
  249. {
  250. AS_ECHO(["$[1]"]) >"$at_check_line_file"
  251. at_check_trace=$at_traceon at_check_filter=$at_check_filter_trace
  252. : >"$at_stdout"; : >"$at_stderr"
  253. }
  254. AS_FUNCTION_DESCRIBE([at_fn_check_prepare_dynamic], [COMMAND LINE],
  255. [Decide if COMMAND at LINE is traceable at runtime, and call the
  256. appropriate preparation function.])
  257. at_fn_check_prepare_dynamic ()
  258. {
  259. case $[1] in
  260. *$as_nl*)
  261. at_fn_check_prepare_notrace 'an embedded newline' "$[2]" ;;
  262. *)
  263. at_fn_check_prepare_trace "$[2]" ;;
  264. esac
  265. }
  266. AS_FUNCTION_DESCRIBE([at_fn_filter_trace], [],
  267. [Remove the lines in the file "$at_stderr" generated by "set -x" and print
  268. them to stderr.])
  269. at_fn_filter_trace ()
  270. {
  271. mv "$at_stderr" "$at_stder1"
  272. grep '^ *+' "$at_stder1" >&2
  273. grep -v '^ *+' "$at_stder1" >"$at_stderr"
  274. }
  275. AS_FUNCTION_DESCRIBE([at_fn_log_failure], [FILE-LIST],
  276. [Copy the files in the list on stdout with a "> " prefix, and exit the shell
  277. with a failure exit code.])
  278. at_fn_log_failure ()
  279. {
  280. for file
  281. do AS_ECHO(["$file:"]); sed 's/^/> /' "$file"; done
  282. echo 1 > "$at_status_file"
  283. exit 1
  284. }
  285. AS_FUNCTION_DESCRIBE([at_fn_check_skip], [EXIT-CODE LINE],
  286. [Check whether EXIT-CODE is a special exit code (77 or 99), and if so exit
  287. the test group subshell with that same exit code. Use LINE in any report
  288. about test failure.])
  289. at_fn_check_skip ()
  290. {
  291. case $[1] in
  292. 99) echo 99 > "$at_status_file"; at_failed=:
  293. AS_ECHO(["$[2]: hard failure"]); exit 99;;
  294. 77) echo 77 > "$at_status_file"; exit 77;;
  295. esac
  296. }
  297. AS_FUNCTION_DESCRIBE([at_fn_check_status], [EXPECTED EXIT-CODE LINE],
  298. [Check whether EXIT-CODE is the EXPECTED exit code, and if so do nothing.
  299. Otherwise, if it is 77 or 99, exit the test group subshell with that same
  300. exit code; if it is anything else print an error message referring to LINE,
  301. and fail the test.])
  302. at_fn_check_status ()
  303. {
  304. dnl This order ensures that we don't `skip' if we are precisely checking
  305. dnl $? = 77 or $? = 99.
  306. case $[2] in
  307. $[1] ) ;;
  308. 77) echo 77 > "$at_status_file"; exit 77;;
  309. 99) echo 99 > "$at_status_file"; at_failed=:
  310. AS_ECHO(["$[3]: hard failure"]); exit 99;;
  311. *) AS_ECHO(["$[3]: exit code was $[2], expected $[1]"])
  312. at_failed=:;;
  313. esac
  314. }
  315. AS_FUNCTION_DESCRIBE([at_fn_diff_devnull], [FILE],
  316. [Emit a diff between /dev/null and FILE. Uses "test -s" to avoid useless
  317. diff invocations.])
  318. at_fn_diff_devnull ()
  319. {
  320. test -s "$[1]" || return 0
  321. $at_diff "$at_devnull" "$[1]"
  322. }
  323. AS_FUNCTION_DESCRIBE([at_fn_test], [NUMBER],
  324. [Parse out test NUMBER from the tail of this file.])
  325. at_fn_test ()
  326. {
  327. eval at_sed=\$at_sed$[1]
  328. sed "$at_sed" "$at_myself" > "$at_test_source"
  329. }
  330. AS_FUNCTION_DESCRIBE([at_fn_create_debugging_script], [],
  331. [Create the debugging script $at_group_dir/run which will reproduce the
  332. current test group.])
  333. at_fn_create_debugging_script ()
  334. {
  335. {
  336. echo "#! /bin/sh" &&
  337. echo 'test "${ZSH_VERSION+set}" = set dnl
  338. && alias -g '\''${1+"$[@]"}'\''='\''"$[@]"'\''' &&
  339. AS_ECHO(["cd '$at_dir'"]) &&
  340. AS_ECHO(["exec \${CONFIG_SHELL-$SHELL} \"$at_myself\" -v -d ]dnl
  341. [$at_debug_args $at_group \${1+\"\$[@]\"}"]) &&
  342. echo 'exit 1'
  343. } >"$at_group_dir/run" &&
  344. chmod +x "$at_group_dir/run"
  345. }
  346. m4_text_box([End of autotest shell functions.])
  347. m4_divert_pop([PREPARE_TESTS])dnl back to DEFAULTS
  348. # Not all shells have the 'times' builtin; the subshell is needed to make
  349. # sure we discard the 'times: not found' message from the shell.
  350. at_times_p=false
  351. (times) >/dev/null 2>&1 && at_times_p=:
  352. # CLI Arguments to pass to the debugging scripts.
  353. at_debug_args=
  354. # -e sets to true
  355. at_errexit_p=false
  356. # Shall we be verbose? ':' means no, empty means yes.
  357. at_verbose=:
  358. at_quiet=
  359. # Running several jobs in parallel, 0 means as many as test groups.
  360. at_jobs=1
  361. at_traceon=:
  362. at_trace_echo=:
  363. at_check_filter_trace=:
  364. # Shall we keep the debug scripts? Must be `:' when the suite is
  365. # run by a debug script, so that the script doesn't remove itself.
  366. at_debug_p=false
  367. # Display help message?
  368. at_help_p=false
  369. # Display the version message?
  370. at_version_p=false
  371. # List test groups?
  372. at_list_p=false
  373. # --clean
  374. at_clean=false
  375. # Test groups to run
  376. at_groups=
  377. # Whether to rerun failed tests.
  378. at_recheck=
  379. # Whether a write failure occurred
  380. at_write_fail=0
  381. # The directory we run the suite in. Default to . if no -C option.
  382. at_dir=`pwd`
  383. # An absolute reference to this testsuite script.
  384. dnl m4-double quote, to preserve []
  385. [case $as_myself in
  386. [\\/]* | ?:[\\/]* ) at_myself=$as_myself ;;
  387. * ) at_myself=$at_dir/$as_myself ;;
  388. esac]
  389. # Whether -C is in effect.
  390. at_change_dir=false
  391. m4_divert_pop([DEFAULTS])dnl
  392. m4_define([_AT_FINISH],
  393. [m4_ifdef([AT_ingroup], [m4_fatal([missing AT_CLEANUP detected])])dnl
  394. m4_divert_text([DEFAULTS],
  395. [
  396. # Whether to enable colored test results.
  397. at_color=m4_ifdef([AT_color], [AT_color], [no])
  398. # List of the tested programs.
  399. at_tested='m4_ifdef([AT_tested],
  400. [m4_translit(m4_dquote(m4_defn([AT_tested])), [ ], m4_newline)])'
  401. # As many question marks as there are digits in the last test group number.
  402. # Used to normalize the test group numbers so that `ls' lists them in
  403. # numerical order.
  404. at_format='m4_bpatsubst(m4_defn([AT_ordinal]), [.], [?])'
  405. # Description of all the test groups.
  406. at_help_all="AS_ESCAPE(m4_dquote(m4_defn([AT_help_all])))"
  407. # List of the all the test groups.
  408. at_groups_all=`AS_ECHO(["$at_help_all"]) | sed 's/;.*//'`
  409. AS_FUNCTION_DESCRIBE([at_fn_validate_ranges], [NAME...],
  410. [Validate and normalize the test group number contained in each
  411. variable NAME. Leading zeroes are treated as decimal.])
  412. at_fn_validate_ranges ()
  413. {
  414. for at_grp
  415. do
  416. eval at_value=\$$at_grp
  417. if test $at_value -lt 1 || test $at_value -gt AT_ordinal; then
  418. AS_ECHO(["invalid test group: $at_value"]) >&2
  419. exit 1
  420. fi
  421. case $at_value in
  422. 0*) # We want to treat leading 0 as decimal, like expr and test, but
  423. # AS_VAR_ARITH treats it as octal if it uses $(( )).
  424. # With XSI shells, ${at_value#${at_value%%[1-9]*}} avoids the
  425. # expr fork, but it is not worth the effort to determine if the
  426. # shell supports XSI when the user can just avoid leading 0.
  427. eval $at_grp='`expr $at_value + 0`' ;;
  428. esac
  429. done
  430. }])])dnl
  431. m4_divert_push([PARSE_ARGS])dnl
  432. at_prev=
  433. for at_option
  434. do
  435. # If the previous option needs an argument, assign it.
  436. if test -n "$at_prev"; then
  437. at_option=$at_prev=$at_option
  438. at_prev=
  439. fi
  440. case $at_option in
  441. *=?*) at_optarg=`expr "X$at_option" : '[[^=]]*=\(.*\)'` ;;
  442. *) at_optarg= ;;
  443. esac
  444. # Accept the important Cygnus configure options, so we can diagnose typos.
  445. case $at_option in
  446. --help | -h )
  447. at_help_p=:
  448. ;;
  449. --list | -l )
  450. at_list_p=:
  451. ;;
  452. --version | -V )
  453. at_version_p=:
  454. ;;
  455. --clean | -c )
  456. at_clean=:
  457. ;;
  458. --color )
  459. at_color=always
  460. ;;
  461. --color=* )
  462. case $at_optarg in
  463. no | never | none) at_color=never ;;
  464. auto | tty | if-tty) at_color=auto ;;
  465. always | yes | force) at_color=always ;;
  466. *) at_optname=`echo " $at_option" | sed 's/^ //; s/=.*//'`
  467. AS_ERROR([unrecognized argument to $at_optname: $at_optarg]) ;;
  468. esac
  469. ;;
  470. --debug | -d )
  471. at_debug_p=:
  472. ;;
  473. --errexit | -e )
  474. at_debug_p=:
  475. at_errexit_p=:
  476. ;;
  477. --verbose | -v )
  478. at_verbose=; at_quiet=:
  479. ;;
  480. --trace | -x )
  481. at_traceon='set -x'
  482. at_trace_echo=echo
  483. at_check_filter_trace=at_fn_filter_trace
  484. ;;
  485. [[0-9] | [0-9][0-9] | [0-9][0-9][0-9] | [0-9][0-9][0-9][0-9]])
  486. at_fn_validate_ranges at_option
  487. AS_VAR_APPEND([at_groups], ["$at_option$as_nl"])
  488. ;;
  489. # Ranges
  490. [[0-9]- | [0-9][0-9]- | [0-9][0-9][0-9]- | [0-9][0-9][0-9][0-9]-])
  491. at_range_start=`echo $at_option |tr -d X-`
  492. at_fn_validate_ranges at_range_start
  493. at_range=`AS_ECHO(["$at_groups_all"]) | \
  494. sed -ne '/^'$at_range_start'$/,$p'`
  495. AS_VAR_APPEND([at_groups], ["$at_range$as_nl"])
  496. ;;
  497. [-[0-9] | -[0-9][0-9] | -[0-9][0-9][0-9] | -[0-9][0-9][0-9][0-9]])
  498. at_range_end=`echo $at_option |tr -d X-`
  499. at_fn_validate_ranges at_range_end
  500. at_range=`AS_ECHO(["$at_groups_all"]) | \
  501. sed -ne '1,/^'$at_range_end'$/p'`
  502. AS_VAR_APPEND([at_groups], ["$at_range$as_nl"])
  503. ;;
  504. [[0-9]-[0-9] | [0-9]-[0-9][0-9] | [0-9]-[0-9][0-9][0-9]] | \
  505. [[0-9]-[0-9][0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9]] | \
  506. [[0-9][0-9]-[0-9][0-9][0-9] | [0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
  507. [[0-9][0-9][0-9]-[0-9][0-9][0-9]] | \
  508. [[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] | \
  509. [[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]] )
  510. at_range_start=`expr $at_option : '\(.*\)-'`
  511. at_range_end=`expr $at_option : '.*-\(.*\)'`
  512. if test $at_range_start -gt $at_range_end; then
  513. at_tmp=$at_range_end
  514. at_range_end=$at_range_start
  515. at_range_start=$at_tmp
  516. fi
  517. at_fn_validate_ranges at_range_start at_range_end
  518. at_range=`AS_ECHO(["$at_groups_all"]) | \
  519. sed -ne '/^'$at_range_start'$/,/^'$at_range_end'$/p'`
  520. AS_VAR_APPEND([at_groups], ["$at_range$as_nl"])
  521. ;;
  522. # Directory selection.
  523. --directory | -C )
  524. at_prev=--directory
  525. ;;
  526. --directory=* )
  527. at_change_dir=:
  528. at_dir=$at_optarg
  529. if test x- = "x$at_dir" ; then
  530. at_dir=./-
  531. fi
  532. ;;
  533. # Parallel execution.
  534. --jobs | -j )
  535. at_jobs=0
  536. ;;
  537. --jobs=* | -j[[0-9]]* )
  538. if test -n "$at_optarg"; then
  539. at_jobs=$at_optarg
  540. else
  541. at_jobs=`expr X$at_option : 'X-j\(.*\)'`
  542. fi
  543. case $at_jobs in *[[!0-9]]*)
  544. at_optname=`echo " $at_option" | sed 's/^ //; s/[[0-9=]].*//'`
  545. AS_ERROR([non-numeric argument to $at_optname: $at_jobs]) ;;
  546. esac
  547. ;;
  548. # Keywords.
  549. --keywords | -k )
  550. at_prev=--keywords
  551. ;;
  552. --keywords=* )
  553. at_groups_selected=$at_help_all
  554. at_save_IFS=$IFS
  555. IFS=,
  556. set X $at_optarg
  557. shift
  558. IFS=$at_save_IFS
  559. for at_keyword
  560. do
  561. at_invert=
  562. case $at_keyword in
  563. '!'*)
  564. at_invert="-v"
  565. at_keyword=`expr "X$at_keyword" : 'X!\(.*\)'`
  566. ;;
  567. esac
  568. # It is on purpose that we match the test group titles too.
  569. at_groups_selected=`AS_ECHO(["$at_groups_selected"]) |
  570. grep -i $at_invert ["^[1-9][^;]*;.*[; ]$at_keyword[ ;]"]`
  571. done
  572. # Smash the keywords.
  573. at_groups_selected=`AS_ECHO(["$at_groups_selected"]) | sed 's/;.*//'`
  574. AS_VAR_APPEND([at_groups], ["$at_groups_selected$as_nl"])
  575. ;;
  576. --recheck)
  577. at_recheck=:
  578. ;;
  579. m4_divert_pop([PARSE_ARGS])dnl
  580. dnl Process *=* last to allow for user specified --option=* type arguments.
  581. m4_divert_push([PARSE_ARGS_END])dnl
  582. *=*)
  583. at_envvar=`expr "x$at_option" : 'x\([[^=]]*\)='`
  584. # Reject names that are not valid shell variable names.
  585. case $at_envvar in
  586. '' | [[0-9]]* | *[[!_$as_cr_alnum]]* )
  587. AS_ERROR([invalid variable name: `$at_envvar']) ;;
  588. esac
  589. at_value=`AS_ECHO(["$at_optarg"]) | sed "s/'/'\\\\\\\\''/g"`
  590. # Export now, but save eval for later and for debug scripts.
  591. export $at_envvar
  592. AS_VAR_APPEND([at_debug_args], [" $at_envvar='$at_value'"])
  593. ;;
  594. *) AS_ECHO(["$as_me: invalid option: $at_option"]) >&2
  595. AS_ECHO(["Try \`$[0] --help' for more information."]) >&2
  596. exit 1
  597. ;;
  598. esac
  599. done
  600. # Verify our last option didn't require an argument
  601. AS_IF([test -n "$at_prev"], [AS_ERROR([`$at_prev' requires an argument])])
  602. # The file containing the suite.
  603. at_suite_log=$at_dir/$as_me.log
  604. # Selected test groups.
  605. if test -z "$at_groups$at_recheck"; then
  606. at_groups=$at_groups_all
  607. else
  608. if test -n "$at_recheck" && test -r "$at_suite_log"; then
  609. at_oldfails=`sed -n ['
  610. /^Failed tests:$/,/^Skipped tests:$/{
  611. s/^[ ]*\([1-9][0-9]*\):.*/\1/p
  612. }
  613. /^Unexpected passes:$/,/^## Detailed failed tests/{
  614. s/^[ ]*\([1-9][0-9]*\):.*/\1/p
  615. }
  616. /^## Detailed failed tests/q
  617. '] "$at_suite_log"`
  618. AS_VAR_APPEND([at_groups], ["$at_oldfails$as_nl"])
  619. fi
  620. # Sort the tests, removing duplicates.
  621. at_groups=`AS_ECHO(["$at_groups"]) | sort -nu | sed '/^$/d'`
  622. fi
  623. if test x"$at_color" = xalways \
  624. || { test x"$at_color" = xauto && test -t 1; }; then
  625. at_red=`printf '\033@<:@0;31m'`
  626. at_grn=`printf '\033@<:@0;32m'`
  627. at_lgn=`printf '\033@<:@1;32m'`
  628. at_blu=`printf '\033@<:@1;34m'`
  629. at_std=`printf '\033@<:@m'`
  630. else
  631. at_red= at_grn= at_lgn= at_blu= at_std=
  632. fi
  633. m4_divert_pop([PARSE_ARGS_END])dnl
  634. m4_divert_push([HELP])dnl
  635. # Help message.
  636. if $at_help_p; then
  637. cat <<_ATEOF || at_write_fail=1
  638. Usage: $[0] [[OPTION]... [VARIABLE=VALUE]... [TESTS]]
  639. Run all the tests, or the selected TESTS, given by numeric ranges, and
  640. save a detailed log file. Upon failure, create debugging scripts.
  641. Do not change environment variables directly. Instead, set them via
  642. command line arguments. Set \`AUTOTEST_PATH' to select the executables
  643. to exercise. Each relative directory is expanded as build and source
  644. directories relative to the top level of this distribution.
  645. E.g., from within the build directory /tmp/foo-1.0, invoking this:
  646. $ $[0] AUTOTEST_PATH=bin
  647. is equivalent to the following, assuming the source directory is /src/foo-1.0:
  648. PATH=/tmp/foo-1.0/bin:/src/foo-1.0/bin:\$PATH $[0]
  649. _ATEOF
  650. m4_divert_pop([HELP])dnl
  651. m4_divert_push([HELP_MODES])dnl
  652. cat <<_ATEOF || at_write_fail=1
  653. Operation modes:
  654. -h, --help print the help message, then exit
  655. -V, --version print version number, then exit
  656. -c, --clean remove all the files this test suite might create and exit
  657. -l, --list describes all the tests, or the selected TESTS
  658. _ATEOF
  659. m4_divert_pop([HELP_MODES])dnl
  660. m4_wrap([m4_divert_push([HELP_TUNING_BEGIN])dnl
  661. cat <<_ATEOF || at_write_fail=1
  662. dnl extra quoting prevents emacs whitespace mode from putting tabs in output
  663. Execution tuning:
  664. -C, --directory=DIR
  665. [ change to directory DIR before starting]
  666. --color[[=never|auto|always]]
  667. [ ]m4_ifdef([AT_color],
  668. [disable colored test results, or enable even without terminal],
  669. [enable colored test results on terminal, or always])
  670. -j, --jobs[[=N]]
  671. [ Allow N jobs at once; infinite jobs with no arg (default 1)]
  672. -k, --keywords=KEYWORDS
  673. [ select the tests matching all the comma-separated KEYWORDS]
  674. [ multiple \`-k' accumulate; prefixed \`!' negates a KEYWORD]
  675. --recheck select all tests that failed or passed unexpectedly last time
  676. -e, --errexit abort as soon as a test fails; implies --debug
  677. -v, --verbose force more detailed output
  678. [ default for debugging scripts]
  679. -d, --debug inhibit clean up and top-level logging
  680. [ default for debugging scripts]
  681. -x, --trace enable tests shell tracing
  682. _ATEOF
  683. m4_divert_pop([HELP_TUNING_BEGIN])])dnl
  684. m4_divert_push([HELP_END])dnl
  685. cat <<_ATEOF || at_write_fail=1
  686. Report bugs to <AT_PACKAGE_BUGREPORT>.dnl
  687. m4_ifdef([AT_PACKAGE_NAME],
  688. [m4_ifset([AT_PACKAGE_URL], [
  689. m4_defn([AT_PACKAGE_NAME]) home page: <AT_PACKAGE_URL>.])dnl
  690. m4_if(m4_index(m4_defn([AT_PACKAGE_NAME]), [GNU ]), [0], [
  691. General help using GNU software: <http://www.gnu.org/gethelp/>.])])
  692. _ATEOF
  693. exit $at_write_fail
  694. fi
  695. # List of tests.
  696. if $at_list_p; then
  697. cat <<_ATEOF || at_write_fail=1
  698. AT_TESTSUITE_NAME test groups:
  699. NUM: FILE-NAME:LINE TEST-GROUP-NAME
  700. KEYWORDS
  701. _ATEOF
  702. # Pass an empty line as separator between selected groups and help.
  703. AS_ECHO(["$at_groups$as_nl$as_nl$at_help_all"]) |
  704. awk 'NF == 1 && FS != ";" {
  705. selected[[$ 1]] = 1
  706. next
  707. }
  708. /^$/ { FS = ";" }
  709. NF > 0 {
  710. if (selected[[$ 1]]) {
  711. printf " %3d: %-18s %s\n", $ 1, $ 2, $ 3
  712. if ($ 4) {
  713. lmax = 79
  714. indent = " "
  715. line = indent
  716. len = length (line)
  717. n = split ($ 4, a, " ")
  718. for (i = 1; i <= n; i++) {
  719. l = length (a[[i]]) + 1
  720. if (i > 1 && len + l > lmax) {
  721. print line
  722. line = indent " " a[[i]]
  723. len = length (line)
  724. } else {
  725. line = line " " a[[i]]
  726. len += l
  727. }
  728. }
  729. if (n)
  730. print line
  731. }
  732. }
  733. }' || at_write_fail=1
  734. exit $at_write_fail
  735. fi
  736. m4_divert_pop([HELP_END])dnl
  737. m4_divert_push([VERSION])dnl
  738. if $at_version_p; then
  739. AS_ECHO(["$as_me (AT_PACKAGE_STRING)"]) &&
  740. cat <<\_ATEOF || at_write_fail=1
  741. m4_divert_pop([VERSION])dnl
  742. m4_divert_push([VERSION_END])dnl
  743. _ATEOF
  744. exit $at_write_fail
  745. fi
  746. m4_divert_pop([VERSION_END])dnl
  747. m4_divert_push([TESTS_BEGIN])dnl
  748. # Take any -C into account.
  749. if $at_change_dir ; then
  750. test x != "x$at_dir" && cd "$at_dir" \
  751. || AS_ERROR([unable to change directory])
  752. at_dir=`pwd`
  753. fi
  754. # Load the config files for any default variable assignments.
  755. for at_file in atconfig atlocal
  756. do
  757. test -r $at_file || continue
  758. . ./$at_file || AS_ERROR([invalid content: $at_file])
  759. done
  760. # Autoconf <=2.59b set at_top_builddir instead of at_top_build_prefix:
  761. : "${at_top_build_prefix=$at_top_builddir}"
  762. # Perform any assignments requested during argument parsing.
  763. eval "$at_debug_args"
  764. # atconfig delivers names relative to the directory the test suite is
  765. # in, but the groups themselves are run in testsuite-dir/group-dir.
  766. if test -n "$at_top_srcdir"; then
  767. builddir=../..
  768. for at_dir_var in srcdir top_srcdir top_build_prefix
  769. do
  770. AS_VAR_COPY([at_val], [at_$at_dir_var])
  771. case $at_val in
  772. [[\\/$]]* | ?:[[\\/]]* ) at_prefix= ;;
  773. *) at_prefix=../../ ;;
  774. esac
  775. AS_VAR_SET([$at_dir_var], [$at_prefix$at_val])
  776. done
  777. fi
  778. m4_text_box([Directory structure.])
  779. # This is the set of directories and files used by this script
  780. # (non-literals are capitalized):
  781. #
  782. # TESTSUITE - the testsuite
  783. # TESTSUITE.log - summarizes the complete testsuite run
  784. # TESTSUITE.dir/ - created during a run, remains after -d or failed test
  785. # + at-groups/ - during a run: status of all groups in run
  786. # | + NNN/ - during a run: meta-data about test group NNN
  787. # | | + check-line - location (source file and line) of current AT_CHECK
  788. # | | + status - exit status of current AT_CHECK
  789. # | | + stdout - stdout of current AT_CHECK
  790. # | | + stder1 - stderr, including trace
  791. # | | + stderr - stderr, with trace filtered out
  792. # | | + test-source - portion of testsuite that defines group
  793. # | | + times - timestamps for computing duration
  794. # | | + pass - created if group passed
  795. # | | + xpass - created if group xpassed
  796. # | | + fail - created if group failed
  797. # | | + xfail - created if group xfailed
  798. # | | + skip - created if group skipped
  799. # + at-stop - during a run: end the run if this file exists
  800. # + at-source-lines - during a run: cache of TESTSUITE line numbers for extraction
  801. # + 0..NNN/ - created for each group NNN, remains after -d or failed test
  802. # | + TESTSUITE.log - summarizes the group results
  803. # | + ... - files created during the group
  804. # The directory the whole suite works in.
  805. # Should be absolute to let the user `cd' at will.
  806. at_suite_dir=$at_dir/$as_me.dir
  807. # The file containing the suite ($at_dir might have changed since earlier).
  808. at_suite_log=$at_dir/$as_me.log
  809. # The directory containing helper files per test group.
  810. at_helper_dir=$at_suite_dir/at-groups
  811. # Stop file: if it exists, do not start new jobs.
  812. at_stop_file=$at_suite_dir/at-stop
  813. # The fifo used for the job dispatcher.
  814. at_job_fifo=$at_suite_dir/at-job-fifo
  815. if $at_clean; then
  816. test -d "$at_suite_dir" &&
  817. find "$at_suite_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
  818. rm -f -r "$at_suite_dir" "$at_suite_log"
  819. exit $?
  820. fi
  821. # Don't take risks: use only absolute directories in PATH.
  822. #
  823. # For stand-alone test suites (ie. atconfig was not found),
  824. # AUTOTEST_PATH is relative to `.'.
  825. #
  826. # For embedded test suites, AUTOTEST_PATH is relative to the top level
  827. # of the package. Then expand it into build/src parts, since users
  828. # may create executables in both places.
  829. AUTOTEST_PATH=`AS_ECHO(["$AUTOTEST_PATH"]) | sed "s|:|$PATH_SEPARATOR|g"`
  830. at_path=
  831. _AS_PATH_WALK([$AUTOTEST_PATH $PATH],
  832. [test -n "$at_path" && AS_VAR_APPEND([at_path], [$PATH_SEPARATOR])
  833. case $as_dir in
  834. [[\\/]]* | ?:[[\\/]]* )
  835. AS_VAR_APPEND([at_path], ["$as_dir"])
  836. ;;
  837. * )
  838. if test -z "$at_top_build_prefix"; then
  839. # Stand-alone test suite.
  840. AS_VAR_APPEND([at_path], ["$as_dir"])
  841. else
  842. # Embedded test suite.
  843. AS_VAR_APPEND([at_path], ["$at_top_build_prefix$as_dir$PATH_SEPARATOR"])
  844. AS_VAR_APPEND([at_path], ["$at_top_srcdir/$as_dir"])
  845. fi
  846. ;;
  847. esac])
  848. # Now build and simplify PATH.
  849. #
  850. # There might be directories that don't exist, but don't redirect
  851. # builtins' (eg., cd) stderr directly: Ultrix's sh hates that.
  852. at_new_path=
  853. _AS_PATH_WALK([$at_path],
  854. [test -d "$as_dir" || continue
  855. case $as_dir in
  856. [[\\/]]* | ?:[[\\/]]* ) ;;
  857. * ) as_dir=`(cd "$as_dir" && pwd) 2>/dev/null` ;;
  858. esac
  859. case $PATH_SEPARATOR$at_new_path$PATH_SEPARATOR in
  860. *$PATH_SEPARATOR$as_dir$PATH_SEPARATOR*) ;;
  861. $PATH_SEPARATOR$PATH_SEPARATOR) at_new_path=$as_dir ;;
  862. *) AS_VAR_APPEND([at_new_path], ["$PATH_SEPARATOR$as_dir"]) ;;
  863. esac])
  864. PATH=$at_new_path
  865. export PATH
  866. # Setting up the FDs.
  867. m4_define([AS_MESSAGE_LOG_FD], [5])
  868. dnl The parent needs two fds to the same fifo, otherwise, there is a race
  869. dnl where the parent can read the fifo before a child opens it for writing
  870. m4_define([AT_JOB_FIFO_IN_FD], [6])
  871. m4_define([AT_JOB_FIFO_OUT_FD], [7])
  872. [#] AS_MESSAGE_LOG_FD is the log file. Not to be overwritten if `-d'.
  873. if $at_debug_p; then
  874. at_suite_log=/dev/null
  875. else
  876. : >"$at_suite_log"
  877. fi
  878. exec AS_MESSAGE_LOG_FD>>"$at_suite_log"
  879. # Banners and logs.
  880. AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
  881. {
  882. AS_BOX(m4_defn([AT_TESTSUITE_NAME])[.])
  883. echo
  884. AS_ECHO(["$as_me: command line was:"])
  885. AS_ECHO([" \$ $[0] $at_cli_args"])
  886. echo
  887. # If ChangeLog exists, list a few lines in case it might help determining
  888. # the exact version.
  889. if test -n "$at_top_srcdir" && test -f "$at_top_srcdir/ChangeLog"; then
  890. AS_BOX([ChangeLog.])
  891. echo
  892. sed 's/^/| /;10q' "$at_top_srcdir/ChangeLog"
  893. echo
  894. fi
  895. AS_UNAME
  896. echo
  897. # Contents of the config files.
  898. for at_file in atconfig atlocal
  899. do
  900. test -r $at_file || continue
  901. AS_ECHO(["$as_me: $at_file:"])
  902. sed 's/^/| /' $at_file
  903. echo
  904. done
  905. } >&AS_MESSAGE_LOG_FD
  906. m4_divert_pop([TESTS_BEGIN])dnl
  907. m4_divert_push([PREPARE_TESTS])dnl
  908. {
  909. AS_BOX([Tested programs.])
  910. echo
  911. } >&AS_MESSAGE_LOG_FD
  912. # Report what programs are being tested.
  913. for at_program in : $at_tested
  914. do
  915. test "$at_program" = : && continue
  916. case $at_program in
  917. [[\\/]* | ?:[\\/]* ) $at_program_=$at_program ;;]
  918. * )
  919. _AS_PATH_WALK([$PATH], [test -f "$as_dir/$at_program" && break])
  920. at_program_=$as_dir/$at_program ;;
  921. esac
  922. if test -f "$at_program_"; then
  923. {
  924. AS_ECHO(["$at_srcdir/AT_LINE: $at_program_ --version"])
  925. "$at_program_" --version </dev/null
  926. echo
  927. } >&AS_MESSAGE_LOG_FD 2>&1
  928. else
  929. AS_ERROR([cannot find $at_program])
  930. fi
  931. done
  932. {
  933. AS_BOX([Running the tests.])
  934. } >&AS_MESSAGE_LOG_FD
  935. at_start_date=`date`
  936. at_start_time=`date +%s 2>/dev/null`
  937. AS_ECHO(["$as_me: starting at: $at_start_date"]) >&AS_MESSAGE_LOG_FD
  938. m4_divert_pop([PREPARE_TESTS])dnl
  939. m4_divert_push([TESTS])dnl
  940. # Create the master directory if it doesn't already exist.
  941. AS_MKDIR_P(["$at_suite_dir"]) ||
  942. AS_ERROR([cannot create `$at_suite_dir'])
  943. # Can we diff with `/dev/null'? DU 5.0 refuses.
  944. if diff /dev/null /dev/null >/dev/null 2>&1; then
  945. at_devnull=/dev/null
  946. else
  947. at_devnull=$at_suite_dir/devnull
  948. >"$at_devnull"
  949. fi
  950. # Use `diff -u' when possible.
  951. if at_diff=`diff -u "$at_devnull" "$at_devnull" 2>&1` && test -z "$at_diff"
  952. then
  953. at_diff='diff -u'
  954. else
  955. at_diff=diff
  956. fi
  957. # Get the last needed group.
  958. for at_group in : $at_groups; do :; done
  959. # Extract the start and end lines of each test group at the tail
  960. # of this file
  961. awk '
  962. BEGIN { FS="" }
  963. /^@%:@AT_START_/ {
  964. start = NR
  965. }
  966. /^@%:@AT_STOP_/ {
  967. test = substr ($ 0, 10)
  968. print "at_sed" test "=\"1," start "d;" (NR-1) "q\""
  969. if (test == "'"$at_group"'") exit
  970. }' "$at_myself" > "$at_suite_dir/at-source-lines" &&
  971. . "$at_suite_dir/at-source-lines" ||
  972. AS_ERROR([cannot create test line number cache])
  973. rm -f "$at_suite_dir/at-source-lines"
  974. # Set number of jobs for `-j'; avoid more jobs than test groups.
  975. set X $at_groups; shift; at_max_jobs=$[@%:@]
  976. if test $at_max_jobs -eq 0; then
  977. at_jobs=1
  978. fi
  979. if test $at_jobs -ne 1 &&
  980. { test $at_jobs -eq 0 || test $at_jobs -gt $at_max_jobs; }; then
  981. at_jobs=$at_max_jobs
  982. fi
  983. # If parallel mode, don't output banners, don't split summary lines.
  984. if test $at_jobs -ne 1; then
  985. at_print_banners=false
  986. at_quiet=:
  987. fi
  988. # Set up helper dirs.
  989. rm -rf "$at_helper_dir" &&
  990. mkdir "$at_helper_dir" &&
  991. cd "$at_helper_dir" &&
  992. { test -z "$at_groups" || mkdir $at_groups; } ||
  993. AS_ERROR([testsuite directory setup failed])
  994. # Functions for running a test group. We leave the actual
  995. # test group execution outside of a shell function in order
  996. # to avoid hitting zsh 4.x exit status bugs.
  997. AS_FUNCTION_DESCRIBE([at_fn_group_prepare], [],
  998. [Prepare for running a test group.])
  999. at_fn_group_prepare ()
  1000. {
  1001. # The directory for additional per-group helper files.
  1002. at_job_dir=$at_helper_dir/$at_group
  1003. # The file containing the location of the last AT_CHECK.
  1004. at_check_line_file=$at_job_dir/check-line
  1005. # The file containing the exit status of the last command.
  1006. at_status_file=$at_job_dir/status
  1007. # The files containing the output of the tested commands.
  1008. at_stdout=$at_job_dir/stdout
  1009. at_stder1=$at_job_dir/stder1
  1010. at_stderr=$at_job_dir/stderr
  1011. # The file containing the code for a test group.
  1012. at_test_source=$at_job_dir/test-source
  1013. # The file containing dates.
  1014. at_times_file=$at_job_dir/times
  1015. # Be sure to come back to the top test directory.
  1016. cd "$at_suite_dir"
  1017. # Clearly separate the test groups when verbose.
  1018. $at_first || $at_verbose echo
  1019. at_group_normalized=$at_group
  1020. _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
  1021. # Create a fresh directory for the next test group, and enter.
  1022. # If one already exists, the user may have invoked ./run from
  1023. # within that directory; we remove the contents, but not the
  1024. # directory itself, so that we aren't pulling the rug out from
  1025. # under the shell's notion of the current directory.
  1026. at_group_dir=$at_suite_dir/$at_group_normalized
  1027. at_group_log=$at_group_dir/$as_me.log
  1028. _AS_CLEAN_DIR("$at_group_dir") ||
  1029. AS_WARN([test directory for $at_group_normalized could not be cleaned])
  1030. # Be tolerant if the above `rm' was not able to remove the directory.
  1031. AS_MKDIR_P(["$at_group_dir"])
  1032. echo 0 > "$at_status_file"
  1033. # In verbose mode, append to the log file *and* show on
  1034. # the standard output; in quiet mode only write to the log.
  1035. if test -z "$at_verbose"; then
  1036. at_tee_pipe='tee -a "$at_group_log"'
  1037. else
  1038. at_tee_pipe='cat >> "$at_group_log"'
  1039. fi
  1040. }
  1041. AS_FUNCTION_DESCRIBE([at_fn_group_banner], [[ORDINAL LINE DESC PAD [BANNER]]],
  1042. [Declare the test group ORDINAL, located at LINE with group description
  1043. DESC, and residing under BANNER. Use PAD to align the status column.])
  1044. at_fn_group_banner ()
  1045. {
  1046. at_setup_line="$[2]"
  1047. test -n "$[5]" && at_fn_banner $[5]
  1048. at_desc="$[3]"
  1049. case $[1] in
  1050. [[0-9]]) at_desc_line=" $[1]: ";;
  1051. [[0-9][0-9]]) at_desc_line=" $[1]: " ;;
  1052. [*]) at_desc_line="$[1]: " ;;
  1053. esac
  1054. AS_VAR_APPEND([at_desc_line], ["$[3]$[4]"])
  1055. $at_quiet AS_ECHO_N(["$at_desc_line"])
  1056. echo "# -*- compilation -*-" >> "$at_group_log"
  1057. }
  1058. AS_FUNCTION_DESCRIBE([at_fn_group_postprocess], [],
  1059. [Perform cleanup after running a test group.])
  1060. at_fn_group_postprocess ()
  1061. {
  1062. # Be sure to come back to the suite directory, in particular
  1063. # since below we might `rm' the group directory we are in currently.
  1064. cd "$at_suite_dir"
  1065. if test ! -f "$at_check_line_file"; then
  1066. sed "s/^ */$as_me: WARNING: /" <<_ATEOF
  1067. A failure happened in a test group before any test could be
  1068. run. This means that test suite is improperly designed. Please
  1069. report this failure to <AT_PACKAGE_BUGREPORT>.
  1070. _ATEOF
  1071. AS_ECHO(["$at_setup_line"]) >"$at_check_line_file"
  1072. at_status=99
  1073. fi
  1074. $at_verbose AS_ECHO_N(["$at_group. $at_setup_line: "])
  1075. AS_ECHO_N(["$at_group. $at_setup_line: "]) >> "$at_group_log"
  1076. case $at_xfail:$at_status in
  1077. yes:0)
  1078. at_msg="UNEXPECTED PASS"
  1079. at_res=xpass
  1080. at_errexit=$at_errexit_p
  1081. at_color=$at_red
  1082. ;;
  1083. no:0)
  1084. at_msg="ok"
  1085. at_res=pass
  1086. at_errexit=false
  1087. at_color=$at_grn
  1088. ;;
  1089. *:77)
  1090. at_msg='skipped ('`cat "$at_check_line_file"`')'
  1091. at_res=skip
  1092. at_errexit=false
  1093. at_color=$at_blu
  1094. ;;
  1095. no:* | *:99)
  1096. at_msg='FAILED ('`cat "$at_check_line_file"`')'
  1097. at_res=fail
  1098. at_errexit=$at_errexit_p
  1099. at_color=$at_red
  1100. ;;
  1101. yes:*)
  1102. at_msg='expected failure ('`cat "$at_check_line_file"`')'
  1103. at_res=xfail
  1104. at_errexit=false
  1105. at_color=$at_lgn
  1106. ;;
  1107. esac
  1108. echo "$at_res" > "$at_job_dir/$at_res"
  1109. # In parallel mode, output the summary line only afterwards.
  1110. if test $at_jobs -ne 1 && test -n "$at_verbose"; then
  1111. AS_ECHO(["$at_desc_line $at_color$at_msg$at_std"])
  1112. else
  1113. # Make sure there is a separator even with long titles.
  1114. AS_ECHO([" $at_color$at_msg$at_std"])
  1115. fi
  1116. at_log_msg="$at_group. $at_desc ($at_setup_line): $at_msg"
  1117. case $at_status in
  1118. 0|77)
  1119. # $at_times_file is only available if the group succeeded.
  1120. # We're not including the group log, so the success message
  1121. # is written in the global log separately. But we also
  1122. # write to the group log in case they're using -d.
  1123. if test -f "$at_times_file"; then
  1124. at_log_msg="$at_log_msg ("`sed 1d "$at_times_file"`')'
  1125. rm -f "$at_times_file"
  1126. fi
  1127. AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
  1128. AS_ECHO(["$at_log_msg"]) >&AS_MESSAGE_LOG_FD
  1129. # Cleanup the group directory, unless the user wants the files
  1130. # or the success was unexpected.
  1131. if $at_debug_p || test $at_res = xpass; then
  1132. at_fn_create_debugging_script
  1133. if test $at_res = xpass && $at_errexit; then
  1134. echo stop > "$at_stop_file"
  1135. fi
  1136. else
  1137. if test -d "$at_group_dir"; then
  1138. find "$at_group_dir" -type d ! -perm -700 -exec chmod u+rwx \{\} \;
  1139. rm -fr "$at_group_dir"
  1140. fi
  1141. rm -f "$at_test_source"
  1142. fi
  1143. ;;
  1144. *)
  1145. # Upon failure, include the log into the testsuite's global
  1146. # log. The failure message is written in the group log. It
  1147. # is later included in the global log.
  1148. AS_ECHO(["$at_log_msg"]) >> "$at_group_log"
  1149. # Upon failure, keep the group directory for autopsy, and create
  1150. # the debugging script. With -e, do not start any further tests.
  1151. at_fn_create_debugging_script
  1152. if $at_errexit; then
  1153. echo stop > "$at_stop_file"
  1154. fi
  1155. ;;
  1156. esac
  1157. }
  1158. m4_text_box([Driver loop.])
  1159. dnl Catching signals correctly:
  1160. dnl
  1161. dnl The first idea was: trap the signal, send it to all spawned jobs,
  1162. dnl then reset the handler and reraise the signal for ourselves.
  1163. dnl However, before exiting, ksh will then send the signal to all
  1164. dnl process group members, potentially killing the outer testsuite
  1165. dnl and/or the 'make' process driving us.
  1166. dnl So now the strategy is: trap the signal, send it to all spawned jobs,
  1167. dnl then exit the script with the right status.
  1168. dnl
  1169. dnl In order to let the jobs know about the signal, we cannot just send it
  1170. dnl to the current process group (kill $SIG 0), for the same reason as above.
  1171. dnl Also, it does not reliably stop the suite to send the signal to the
  1172. dnl spawned processes, because they might not transport it further
  1173. dnl (maybe this can be fixed?).
  1174. dnl
  1175. dnl So what we do is enable shell job control if available, which causes the
  1176. dnl shell to start each parallel task as its own shell job, thus as a new
  1177. dnl process group leader. We then send the signal to all new process groups.
  1178. dnl Do we have job control?
  1179. if (set -m && set +m && set +b) >/dev/null 2>&1; then
  1180. set +b
  1181. at_job_control_on='set -m' at_job_control_off='set +m' at_job_group=-
  1182. else
  1183. at_job_control_on=: at_job_control_off=: at_job_group=
  1184. fi
  1185. for at_signal in 1 2 15; do
  1186. dnl This signal handler is not suitable for PIPE: it causes writes.
  1187. dnl The code that was interrupted may have the errexit, monitor, or xtrace
  1188. dnl flags enabled, so sanitize.
  1189. trap 'set +x; set +e
  1190. $at_job_control_off
  1191. at_signal='"$at_signal"'
  1192. dnl Safety belt: even with runaway processes, prevent starting new jobs.
  1193. echo stop > "$at_stop_file"
  1194. dnl Do not enter this area multiple times, do not kill self prematurely.
  1195. trap "" $at_signal
  1196. dnl Gather process group IDs of currently running jobs.
  1197. at_pgids=
  1198. for at_pgid in `jobs -p 2>/dev/null`; do
  1199. at_pgids="$at_pgids $at_job_group$at_pgid"
  1200. done
  1201. dnl Ignore `kill' errors, as some jobs may have finished in the meantime.
  1202. test -z "$at_pgids" || kill -$at_signal $at_pgids 2>/dev/null
  1203. dnl wait until all jobs have exited.
  1204. wait
  1205. dnl Status output. Do this after waiting for the jobs, for ordered output.
  1206. dnl Avoid scribbling onto the end of a possibly incomplete line.
  1207. if test "$at_jobs" -eq 1 || test -z "$at_verbose"; then
  1208. echo >&2
  1209. fi
  1210. at_signame=`kill -l $at_signal 2>&1 || echo $at_signal`
  1211. set x $at_signame
  1212. test $# -gt 2 && at_signame=$at_signal
  1213. AS_WARN([caught signal $at_signame, bailing out])
  1214. dnl Do not reinstall the default handler here and reraise the signal to
  1215. dnl let the default handler do its job, see the note about ksh above.
  1216. dnl trap - $at_signal
  1217. dnl kill -$at_signal $$
  1218. dnl Instead, exit with appropriate status.
  1219. AS_VAR_ARITH([exit_status], [128 + $at_signal])
  1220. AS_EXIT([$exit_status])' $at_signal
  1221. done
  1222. rm -f "$at_stop_file"
  1223. at_first=:
  1224. if test $at_jobs -ne 1 &&
  1225. rm -f "$at_job_fifo" &&
  1226. test -n "$at_job_group" &&
  1227. ( mkfifo "$at_job_fifo" && trap 'exit 1' PIPE STOP TSTP ) 2>/dev/null
  1228. then
  1229. # FIFO job dispatcher.
  1230. dnl Since we use job control, we need to propagate TSTP.
  1231. dnl This handler need not be used for serial execution.
  1232. dnl Again, we should stop all processes in the job groups, otherwise
  1233. dnl the stopping will not be effective while one test group is running.
  1234. dnl Apparently ksh does not honor the TSTP trap.
  1235. dnl As a safety measure, not use the same variable names as in the
  1236. dnl termination handlers above, one might get called during execution
  1237. dnl of the other.
  1238. trap 'at_pids=
  1239. for at_pid in `jobs -p`; do
  1240. at_pids="$at_pids $at_job_group$at_pid"
  1241. done
  1242. dnl Send it to all spawned jobs, ignoring those finished meanwhile.
  1243. if test -n "$at_pids"; then
  1244. dnl Unfortunately, ksh93 fork-bombs when we send TSTP, so send STOP
  1245. dnl if this might be ksh (STOP prevents possible TSTP handlers inside
  1246. dnl AT_CHECKs from running). Then stop ourselves.
  1247. at_sig=TSTP
  1248. test "${TMOUT+set}" = set && at_sig=STOP
  1249. kill -$at_sig $at_pids 2>/dev/null
  1250. fi
  1251. kill -STOP $$
  1252. dnl We got a CONT, so let's go again. Passing this to all processes
  1253. dnl in the groups is necessary (because we stopped them), but it may
  1254. dnl cause changed test semantics; e.g., a sleep will be interrupted.
  1255. test -z "$at_pids" || kill -CONT $at_pids 2>/dev/null' TSTP
  1256. echo
  1257. # Turn jobs into a list of numbers, starting from 1.
  1258. at_joblist=`AS_ECHO(["$at_groups"]) | sed -n 1,${at_jobs}p`
  1259. set X $at_joblist
  1260. shift
  1261. for at_group in $at_groups; do
  1262. dnl Enable job control only for spawning the test group:
  1263. dnl Let the jobs to run in separate process groups, but
  1264. dnl avoid all the status output by the shell.
  1265. $at_job_control_on 2>/dev/null
  1266. (
  1267. # Start one test group.
  1268. $at_job_control_off
  1269. dnl First child must open the fifo to avoid blocking parent; all other
  1270. dnl children inherit it already opened from the parent.
  1271. if $at_first; then
  1272. exec AT_JOB_FIFO_OUT_FD>"$at_job_fifo"
  1273. else
  1274. dnl Children do not need parent's copy of fifo.
  1275. exec AT_JOB_FIFO_IN_FD<&-
  1276. fi
  1277. dnl When a child receives PIPE, be sure to write back the token,
  1278. dnl so the master does not hang waiting for it.
  1279. dnl errexit and xtrace should not be set in this shell instance,
  1280. dnl except as debug measures. However, shells such as dash may
  1281. dnl optimize away the _AT_CHECK subshell, so normalize here.
  1282. trap 'set +x; set +e
  1283. dnl Ignore PIPE signals that stem from writing back the token.
  1284. trap "" PIPE
  1285. echo stop > "$at_stop_file"
  1286. echo >&AT_JOB_FIFO_OUT_FD
  1287. dnl Do not reraise the default PIPE handler.
  1288. dnl It wreaks havoc with ksh, see above.
  1289. dnl trap - 13
  1290. dnl kill -13 $$
  1291. AS_EXIT([141])' PIPE
  1292. at_fn_group_prepare
  1293. if cd "$at_group_dir" &&
  1294. at_fn_test $at_group &&
  1295. . "$at_test_source"
  1296. then :; else
  1297. AS_WARN([unable to parse test group: $at_group])
  1298. at_failed=:
  1299. fi
  1300. at_fn_group_postprocess
  1301. echo >&AT_JOB_FIFO_OUT_FD
  1302. ) &
  1303. $at_job_control_off
  1304. if $at_first; then
  1305. at_first=false
  1306. exec AT_JOB_FIFO_IN_FD<"$at_job_fifo" AT_JOB_FIFO_OUT_FD>"$at_job_fifo"
  1307. fi
  1308. shift # Consume one token.
  1309. if test $[@%:@] -gt 0; then :; else
  1310. read at_token <&AT_JOB_FIFO_IN_FD || break
  1311. set x $[*]
  1312. fi
  1313. test -f "$at_stop_file" && break
  1314. done
  1315. exec AT_JOB_FIFO_OUT_FD>&-
  1316. # Read back the remaining ($at_jobs - 1) tokens.
  1317. set X $at_joblist
  1318. shift
  1319. if test $[@%:@] -gt 0; then
  1320. shift
  1321. for at_job
  1322. do
  1323. read at_token
  1324. done <&AT_JOB_FIFO_IN_FD
  1325. fi
  1326. exec AT_JOB_FIFO_IN_FD<&-
  1327. wait
  1328. else
  1329. # Run serially, avoid forks and other potential surprises.
  1330. for at_group in $at_groups; do
  1331. at_fn_group_prepare
  1332. if cd "$at_group_dir" &&
  1333. at_fn_test $at_group &&
  1334. . "$at_test_source"; then :; else
  1335. AS_WARN([unable to parse test group: $at_group])
  1336. at_failed=:
  1337. fi
  1338. at_fn_group_postprocess
  1339. test -f "$at_stop_file" && break
  1340. at_first=false
  1341. done
  1342. fi
  1343. # Wrap up the test suite with summary statistics.
  1344. cd "$at_helper_dir"
  1345. # Use ?..???? when the list must remain sorted, the faster * otherwise.
  1346. at_pass_list=`for f in */pass; do echo $f; done | sed '/\*/d; s,/pass,,'`
  1347. at_skip_list=`for f in */skip; do echo $f; done | sed '/\*/d; s,/skip,,'`
  1348. at_xfail_list=`for f in */xfail; do echo $f; done | sed '/\*/d; s,/xfail,,'`
  1349. at_xpass_list=`for f in ?/xpass ??/xpass ???/xpass ????/xpass; do
  1350. echo $f; done | sed '/?/d; s,/xpass,,'`
  1351. at_fail_list=`for f in ?/fail ??/fail ???/fail ????/fail; do
  1352. echo $f; done | sed '/?/d; s,/fail,,'`
  1353. set X $at_pass_list $at_xpass_list $at_xfail_list $at_fail_list $at_skip_list
  1354. shift; at_group_count=$[@%:@]
  1355. set X $at_xpass_list; shift; at_xpass_count=$[@%:@]; at_xpass_list=$[*]
  1356. set X $at_xfail_list; shift; at_xfail_count=$[@%:@]
  1357. set X $at_fail_list; shift; at_fail_count=$[@%:@]; at_fail_list=$[*]
  1358. set X $at_skip_list; shift; at_skip_count=$[@%:@]
  1359. AS_VAR_ARITH([at_run_count], [$at_group_count - $at_skip_count])
  1360. AS_VAR_ARITH([at_unexpected_count], [$at_xpass_count + $at_fail_count])
  1361. AS_VAR_ARITH([at_total_fail_count], [$at_xfail_count + $at_fail_count])
  1362. # Back to the top directory.
  1363. cd "$at_dir"
  1364. rm -rf "$at_helper_dir"
  1365. # Compute the duration of the suite.
  1366. at_stop_date=`date`
  1367. at_stop_time=`date +%s 2>/dev/null`
  1368. AS_ECHO(["$as_me: ending at: $at_stop_date"]) >&AS_MESSAGE_LOG_FD
  1369. case $at_start_time,$at_stop_time in
  1370. [[0-9]*,[0-9]*])
  1371. AS_VAR_ARITH([at_duration_s], [$at_stop_time - $at_start_time])
  1372. AS_VAR_ARITH([at_duration_m], [$at_duration_s / 60])
  1373. AS_VAR_ARITH([at_duration_h], [$at_duration_m / 60])
  1374. AS_VAR_ARITH([at_duration_s], [$at_duration_s % 60])
  1375. AS_VAR_ARITH([at_duration_m], [$at_duration_m % 60])
  1376. at_duration="${at_duration_h}h ${at_duration_m}m ${at_duration_s}s"
  1377. AS_ECHO(["$as_me: test suite duration: $at_duration"]) >&AS_MESSAGE_LOG_FD
  1378. ;;
  1379. esac
  1380. echo
  1381. AS_BOX([Test results.])
  1382. echo
  1383. {
  1384. echo
  1385. AS_BOX([Test results.])
  1386. echo
  1387. } >&AS_MESSAGE_LOG_FD
  1388. dnl
  1389. dnl FIXME: this code is as far from i18n-cleanness as man
  1390. dnl could imagine...
  1391. dnl
  1392. if test $at_run_count = 1; then
  1393. at_result="1 test"
  1394. at_were=was
  1395. else
  1396. at_result="$at_run_count tests"
  1397. at_were=were
  1398. fi
  1399. if $at_errexit_p && test $at_unexpected_count != 0; then
  1400. if test $at_xpass_count = 1; then
  1401. at_result="$at_result $at_were run, one passed"
  1402. else
  1403. at_result="$at_result $at_were run, one failed"
  1404. fi
  1405. at_result="$at_result unexpectedly and inhibited subsequent tests."
  1406. at_color=$at_red
  1407. else
  1408. # Don't you just love exponential explosion of the number of cases?
  1409. at_color=$at_red
  1410. case $at_xpass_count:$at_fail_count:$at_xfail_count in
  1411. # So far, so good.
  1412. 0:0:0) at_result="$at_result $at_were successful." at_color=$at_grn ;;
  1413. 0:0:*) at_result="$at_result behaved as expected." at_color=$at_lgn ;;
  1414. # Some unexpected failures
  1415. 0:*:0) at_result="$at_result $at_were run,
  1416. $at_fail_count failed unexpectedly." ;;
  1417. # Some failures, both expected and unexpected
  1418. 0:*:1) at_result="$at_result $at_were run,
  1419. $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
  1420. 0:*:*) at_result="$at_result $at_were run,
  1421. $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
  1422. # No unexpected failures, but some xpasses
  1423. *:0:*) at_result="$at_result $at_were run,
  1424. $at_xpass_count passed unexpectedly." ;;
  1425. # No expected failures, but failures and xpasses
  1426. *:1:0) at_result="$at_result $at_were run,
  1427. $at_unexpected_count did not behave as expected dnl
  1428. ($at_fail_count unexpected failure)." ;;
  1429. *:*:0) at_result="$at_result $at_were run,
  1430. $at_unexpected_count did not behave as expected dnl
  1431. ($at_fail_count unexpected failures)." ;;
  1432. # All of them.
  1433. *:*:1) at_result="$at_result $at_were run,
  1434. $at_xpass_count passed unexpectedly,
  1435. $at_total_fail_count failed ($at_xfail_count expected failure)." ;;
  1436. *:*:*) at_result="$at_result $at_were run,
  1437. $at_xpass_count passed unexpectedly,
  1438. $at_total_fail_count failed ($at_xfail_count expected failures)." ;;
  1439. esac
  1440. if test $at_skip_count = 0 && test $at_run_count -gt 1; then
  1441. at_result="All $at_result"
  1442. fi
  1443. fi
  1444. # Now put skips in the mix.
  1445. case $at_skip_count in
  1446. 0) ;;
  1447. 1) at_result="$at_result
  1448. 1 test was skipped." ;;
  1449. *) at_result="$at_result
  1450. $at_skip_count tests were skipped." ;;
  1451. esac
  1452. if test $at_unexpected_count = 0; then
  1453. echo "$at_color$at_result$at_std"
  1454. echo "$at_result" >&AS_MESSAGE_LOG_FD
  1455. else
  1456. echo "${at_color}ERROR: $at_result$at_std" >&2
  1457. echo "ERROR: $at_result" >&AS_MESSAGE_LOG_FD
  1458. {
  1459. echo
  1460. AS_BOX([Summary of the failures.])
  1461. # Summary of failed and skipped tests.
  1462. if test $at_fail_count != 0; then
  1463. echo "Failed tests:"
  1464. $SHELL "$at_myself" $at_fail_list --list
  1465. echo
  1466. fi
  1467. if test $at_skip_count != 0; then
  1468. echo "Skipped tests:"
  1469. $SHELL "$at_myself" $at_skip_list --list
  1470. echo
  1471. fi
  1472. if test $at_xpass_count != 0; then
  1473. echo "Unexpected passes:"
  1474. $SHELL "$at_myself" $at_xpass_list --list
  1475. echo
  1476. fi
  1477. if test $at_fail_count != 0; then
  1478. AS_BOX([Detailed failed tests.])
  1479. echo
  1480. for at_group in $at_fail_list
  1481. do
  1482. at_group_normalized=$at_group
  1483. _AT_NORMALIZE_TEST_GROUP_NUMBER(at_group_normalized)
  1484. cat "$at_suite_dir/$at_group_normalized/$as_me.log"
  1485. echo
  1486. done
  1487. echo
  1488. fi
  1489. if test -n "$at_top_srcdir"; then
  1490. AS_BOX([${at_top_build_prefix}config.log])
  1491. sed 's/^/| /' ${at_top_build_prefix}config.log
  1492. echo
  1493. fi
  1494. } >&AS_MESSAGE_LOG_FD
  1495. AS_BOX([$as_me.log was created.])
  1496. echo
  1497. if $at_debug_p; then
  1498. at_msg='per-test log files'
  1499. else
  1500. at_msg="\`${at_testdir+${at_testdir}/}$as_me.log'"
  1501. fi
  1502. AS_ECHO(["Please send $at_msg and all information you think might help:
  1503. To: <AT_PACKAGE_BUGREPORT>
  1504. Subject: @<:@AT_PACKAGE_STRING@:>@ $as_me: dnl
  1505. $at_fail_list${at_fail_list:+ failed${at_xpass_list:+, }}dnl
  1506. $at_xpass_list${at_xpass_list:+ passed unexpectedly}
  1507. You may investigate any problem if you feel able to do so, in which
  1508. case the test suite provides a good starting point. Its output may
  1509. be found below \`${at_testdir+${at_testdir}/}$as_me.dir'.
  1510. "])
  1511. exit 1
  1512. fi
  1513. exit 0
  1514. m4_text_box([Actual tests.])
  1515. m4_divert_pop([TESTS])dnl
  1516. dnl End of AT_INIT: divert to KILL, only test groups are to be
  1517. dnl output, the rest is ignored. Current diversion is BODY, inherited
  1518. dnl from M4sh.
  1519. m4_divert([KILL])
  1520. ])# AT_INIT
  1521. # _AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ARGS],[ACTION-IF-GIVEN],
  1522. # [ACTION-IF-NOT-GIVEN])
  1523. # ----------------------------------------------------------
  1524. # Internal implementation of AT_ARG_OPTION & AT_ARG_OPTION_ARG
  1525. m4_defun([_AT_ARG_OPTION],
  1526. [m4_divert_once([HELP_OTHER],
  1527. [cat <<_ATEOF || at_write_fail=1
  1528. Other options:
  1529. _ATEOF
  1530. ])dnl m4_divert_once HELP_OTHER
  1531. m4_divert_text([HELP_OTHER],
  1532. [cat <<_ATEOF || at_write_fail=1
  1533. $2
  1534. _ATEOF])dnl
  1535. dnl Turn our options into our desired strings
  1536. m4_ifdef([AT_first_option],[m4_undefine([AT_first_option])])dnl
  1537. m4_ifdef([AT_case],[m4_undefine([AT_case])])dnl
  1538. m4_ifdef([AT_case_no],[m4_undefine([AT_case_no])])dnl
  1539. m4_ifdef([AT_case_arg],[m4_undefine([AT_case_arg])])dnl
  1540. m4_foreach([AT_option], m4_split(m4_normalize([$1]),[[ \|]+]),
  1541. [m4_define_default([AT_first_option],AT_option)dnl
  1542. m4_define_default([AT_first_option_tr],
  1543. [m4_bpatsubst(m4_defn([AT_first_option]), -, [_])])dnl
  1544. m4_append([AT_case],m4_if(m4_len(AT_option),1,[],[-])[-]AT_option, [ | ])dnl
  1545. m4_append([AT_case_no],[--no-]AT_option, [ | ])dnl
  1546. m4_append([AT_case_arg],
  1547. m4_if(m4_len(AT_option),1,[],[-])[-]AT_option[=*], [ | ])dnl
  1548. ])dnl m4_foreach AT_option
  1549. dnl keep track so we or the user may process ACTION-IF-NOT-GIVEN
  1550. m4_divert_once([PARSE_ARGS_BEGIN],
  1551. [
  1552. ##
  1553. ## Set up package specific options.
  1554. ##
  1555. ])dnl
  1556. m4_divert_text([PARSE_ARGS_BEGIN],
  1557. [dnl Provide a default value for options without arguments.
  1558. m4_ifvaln([$3],,[at_arg_[]AT_first_option_tr=false])dnl
  1559. at_arg_given_[]AT_first_option_tr=false
  1560. ])dnl m4_divert_text DEFAULTS
  1561. m4_divert_text([PARSE_ARGS],
  1562. [dnl Parse the options and args when necessary.
  1563. m4_ifvaln([$3],
  1564. [ AT_case )
  1565. at_prev=--AT_first_option_tr
  1566. ;;
  1567. AT_case_arg )
  1568. at_arg_[]AT_first_option_tr=$at_optarg
  1569. at_arg_given_[]AT_first_option_tr=:
  1570. $4
  1571. ;;],
  1572. [ AT_case )
  1573. at_optarg=:
  1574. at_arg_[]AT_first_option_tr=:
  1575. at_arg_given_[]AT_first_option_tr=:
  1576. m4_ifval([$4],[$4])[]dnl
  1577. ;;
  1578. AT_case_no )
  1579. at_optarg=false
  1580. at_arg_[]AT_first_option_tr=false
  1581. at_arg_given_[]AT_first_option_tr=:
  1582. m4_ifval([$4],[$4])[]dnl
  1583. ;;])dnl m4_ifvaln $3
  1584. ])dnl m4_divert_text PARSE_ARGS
  1585. m4_ifvaln([$5],
  1586. [m4_divert_once([PARSE_ARGS_END],
  1587. [
  1588. ##
  1589. ## Process package specific options when _not_ supplied.
  1590. ##])dnl m4_divert_once PARSE_ARGS_END
  1591. m4_divert_text([PARSE_ARGS_END],
  1592. [
  1593. AS_IF([$at_arg_given_[]AT_first_option_tr],,[$5])dnl
  1594. ])dnl m4_divert_text PARSE_ARGS_END
  1595. ])dnl m4_ifvaln $5
  1596. ])dnl _AT_ARG_OPTION
  1597. # AT_ARG_OPTION(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
  1598. # ------------------------------------------------------------------------
  1599. # Accept a list of space-separated OPTIONS, all aliases of the first one.
  1600. # Add HELP-TEXT to the HELP_OTHER diversion.
  1601. #
  1602. # Leading dashes should not be passed in OPTIONS. Users will be required
  1603. # to pass `--' before long options and `-' before single character options.
  1604. #
  1605. # $at_arg_OPTION will be set to `:' if this option is received, `false' if
  1606. # if --no-OPTION is received, and `false' by default.
  1607. #
  1608. # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered; here,
  1609. # $at_optarg will be set to `:' or `false' as appropriate. $at_optarg is
  1610. # actually just a copy of $at_arg_OPTION.
  1611. #
  1612. # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete and
  1613. # if no option from OPTIONS was used.
  1614. m4_defun([AT_ARG_OPTION],[_AT_ARG_OPTION([$1],[$2],,[$3],[$4])])
  1615. # AT_ARG_OPTION_ARG(OPTIONS,HELP-TEXT,[ACTION-IF-GIVEN],[ACTION-IF-NOT-GIVEN])
  1616. # ----------------------------------------------------------------------------
  1617. # Accept a set of space-separated OPTIONS with arguments, all aliases of the
  1618. # first one. Add HELP-TEXT to the HELP_OTHER diversion.
  1619. #
  1620. # Leading dashes should not be passed in OPTIONS. Users will be required
  1621. # to pass `--' before long options and `-' before single character options.
  1622. #
  1623. # By default, any argument to these options will be assigned to the shell
  1624. # variable $at_arg_OPTION, where OPTION is the first option in OPTIONS with
  1625. # any `-' characters replaced with `_'.
  1626. #
  1627. # Run ACTION-IF-GIVEN each time an option in OPTIONS is encountered; here,
  1628. # $at_optarg will be set to the option argument. $at_optarg is actually just
  1629. # a copy of $at_arg_OPTION.
  1630. #
  1631. # ACTION-IF-NOT-GIVEN will be run once after option parsing is complete
  1632. # and if no option from OPTIONS was used.
  1633. m4_defun([AT_ARG_OPTION_ARG],[_AT_ARG_OPTION([$1],[$2],1,[$3],[$4])])
  1634. # AT_TESTED(PROGRAMS)
  1635. # -------------------
  1636. # Specify the list of programs exercised by the test suite. Their
  1637. # versions are logged, and in the case of embedded test suite, they
  1638. # must correspond to the version of the package. PATH should be
  1639. # already preset so the proper executable will be selected.
  1640. m4_define([AT_TESTED],
  1641. [m4_append_uniq_w([AT_tested], [$1])])
  1642. # AT_COPYRIGHT(TEXT, [FILTER = m4_newline])
  1643. # -----------------------------------------
  1644. # Emit TEXT, a copyright notice, in the top of the test suite and in
  1645. # --version output. Macros in TEXT are evaluated once. Process
  1646. # the --version output through FILTER (m4_newline, m4_do, and
  1647. # m4_copyright_condense are common filters).
  1648. m4_define([AT_COPYRIGHT],
  1649. [AS_COPYRIGHT([$1])[]]dnl
  1650. [m4_divert_text([VERSION_NOTICES],
  1651. [m4_default([$2], [m4_newline])([$1])])])# AT_COPYRIGHT
  1652. # AT_COLOR_TESTS
  1653. # --------------
  1654. # Enable colored test results if standard error is connected to a terminal.
  1655. m4_define([AT_COLOR_TESTS],
  1656. [m4_define([AT_color], [auto])])
  1657. # AT_SETUP(DESCRIPTION)
  1658. # ---------------------
  1659. # Start a group of related tests, all to be executed in the same subshell.
  1660. # The group is testing what DESCRIPTION says.
  1661. _AT_DEFINE_INIT([AT_SETUP],
  1662. [m4_ifdef([AT_ingroup], [m4_fatal([$0: nested AT_SETUP detected])],
  1663. [m4_define([AT_ingroup], [AS_ECHO(["$at_setup_line"]) >"$at_check_line_file"
  1664. ])])
  1665. m4_ifdef([AT_keywords], [m4_undefine([AT_keywords])])
  1666. m4_define([AT_capture_files], [])
  1667. m4_define([AT_line], AT_LINE)
  1668. m4_define([AT_xfail], [at_xfail=no])
  1669. m4_define([AT_description], m4_expand([$1]))
  1670. m4_define([AT_ordinal], m4_incr(AT_ordinal))
  1671. m4_divert_push([TEST_GROUPS])dnl
  1672. [#AT_START_]AT_ordinal
  1673. at_fn_group_banner AT_ordinal 'm4_defn([AT_line])' \
  1674. "AS_ESCAPE(m4_dquote(m4_defn([AT_description])))" m4_format(["%*s"],
  1675. m4_max(0, m4_eval(47 - m4_qlen(m4_defn([AT_description])))), [])m4_if(
  1676. AT_banner_ordinal, [0], [], [ AT_banner_ordinal])
  1677. m4_divert_push([TEST_SCRIPT])dnl
  1678. ])
  1679. # AT_FAIL_IF(SHELL-EXPRESSION)
  1680. # ----------------------------
  1681. # Make the test die with hard failure if SHELL-EXPRESSION evaluates to
  1682. # true (exitcode = 0).
  1683. _AT_DEFINE_SETUP([AT_FAIL_IF],
  1684. [dnl
  1685. dnl Try to limit the amount of conditionals that we emit.
  1686. m4_case([$1],
  1687. [], [],
  1688. [false], [],
  1689. [:], [_AT_CHECK_EXIT([], [99])],
  1690. [true], [_AT_CHECK_EXIT([], [99])],
  1691. [_AT_CHECK_EXIT([$1], [99])])])
  1692. # AT_SKIP_IF(SHELL-EXPRESSION)
  1693. # ----------------------------
  1694. # Skip the rest of the group if SHELL-EXPRESSION evaluates to true
  1695. # (exitcode = 0).
  1696. _AT_DEFINE_SETUP([AT_SKIP_IF],
  1697. [dnl
  1698. dnl Try to limit the amount of conditionals that we emit.
  1699. m4_case([$1],
  1700. [], [],
  1701. [false], [],
  1702. [:], [_AT_CHECK_EXIT([], [77])],
  1703. [true], [_AT_CHECK_EXIT([], [77])],
  1704. [_AT_CHECK_EXIT([$1], [77])])])
  1705. # AT_XFAIL_IF(SHELL-EXPRESSION)
  1706. # -----------------------------
  1707. # Set up the test to be expected to fail if SHELL-EXPRESSION evaluates to
  1708. # true (exitcode = 0).
  1709. _AT_DEFINE_SETUP([AT_XFAIL_IF],
  1710. [dnl
  1711. dnl Try to limit the amount of conditionals that we emit.
  1712. m4_case([$1],
  1713. [], [],
  1714. [false], [],
  1715. [:], [m4_define([AT_xfail], [at_xfail=yes])],
  1716. [true], [m4_define([AT_xfail], [at_xfail=yes])],
  1717. [m4_append([AT_xfail], [
  1718. $1 && at_xfail=yes])])])
  1719. # AT_KEYWORDS(KEYWORDS)
  1720. # ---------------------
  1721. # Declare a list of keywords associated to the current test group.
  1722. # Since the -k option is case-insensitive, the list is stored in lower case
  1723. # to avoid duplicates that differ only by case.
  1724. _AT_DEFINE_SETUP([AT_KEYWORDS],
  1725. [m4_append_uniq_w([AT_keywords], m4_tolower(_m4_expand([$1
  1726. ])))])
  1727. # AT_CAPTURE_FILE(FILE)
  1728. # ---------------------
  1729. # If the current test group does not behave as expected, save the contents of
  1730. # FILE in the test suite log.
  1731. _AT_DEFINE_SETUP([AT_CAPTURE_FILE],
  1732. [m4_append_uniq([AT_capture_files], ["$1"], [ \
  1733. ])])
  1734. # AT_CLEANUP
  1735. # ----------
  1736. # Complete a group of related tests.
  1737. _AT_DEFINE_INIT([AT_CLEANUP],
  1738. [m4_ifdef([AT_ingroup], [AT_ingroup[]_m4_undefine([AT_ingroup])],
  1739. [m4_fatal([$0: missing AT_SETUP detected])])dnl
  1740. m4_append([AT_help_all],
  1741. m4_defn([AT_ordinal]);m4_defn([AT_line]);m4_defn([AT_description]);dnl
  1742. m4_ifdef([AT_keywords], [m4_defn([AT_keywords])]);
  1743. )dnl
  1744. m4_divert_pop([TEST_SCRIPT])dnl Back to TEST_GROUPS
  1745. AT_xfail
  1746. (
  1747. AS_ECHO(["AT_ordinal. $at_setup_line: testing $at_desc ..."])
  1748. $at_traceon
  1749. m4_undivert([TEST_SCRIPT])dnl Insert the code here
  1750. set +x
  1751. $at_times_p && times >"$at_times_file"
  1752. ) AS_MESSAGE_LOG_FD>&1 2>&1 AT_JOB_FIFO_OUT_FD>&- | eval $at_tee_pipe
  1753. read at_status <"$at_status_file"
  1754. [#AT_STOP_]AT_ordinal
  1755. m4_divert_pop([TEST_GROUPS])dnl Back to KILL.
  1756. ])# AT_CLEANUP
  1757. # AT_BANNER([TEXT])
  1758. # -----------------
  1759. # Start a category of related test groups. If multiple groups are executed,
  1760. # output TEXT as a banner without any shell expansion, prior to any test
  1761. # from the category. If TEXT is empty, no banner is printed.
  1762. _AT_DEFINE_INIT([AT_BANNER],
  1763. [m4_ifdef([AT_ingroup], [m4_fatal([$0: nested AT_SETUP detected])])dnl
  1764. m4_define([AT_banner_ordinal], m4_incr(AT_banner_ordinal))
  1765. m4_divert_text([BANNERS],
  1766. [@%:@ Banner AT_banner_ordinal. AT_LINE
  1767. @%:@ Category starts at test group m4_incr(AT_ordinal).
  1768. at_banner_text_[]AT_banner_ordinal="AS_ESCAPE([$1])"])dnl
  1769. ])# AT_BANNER
  1770. # AT_DATA(FILE, CONTENTS)
  1771. # -----------------------
  1772. # Initialize an input data FILE with given CONTENTS, which should be
  1773. # empty or end with a newline.
  1774. # This macro is not robust to active symbols in CONTENTS *on purpose*.
  1775. # If you don't want CONTENTS to be evaluated, quote it twice.
  1776. _AT_DEFINE_SETUP([AT_DATA],
  1777. [m4_if([$2], [], [: >$1],
  1778. [$2], [[]], [: >$1],
  1779. [cat >$1 <<'_ATEOF'
  1780. $2[]_ATEOF
  1781. ])])
  1782. # AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
  1783. # [RUN-IF-FAIL], [RUN-IF-PASS])
  1784. # ------------------------------------------------
  1785. # Execute a test by performing given shell COMMANDS. These commands
  1786. # should normally exit with STATUS, while producing expected STDOUT and
  1787. # STDERR contents. Shell metacharacters in STDOUT and STDERR are
  1788. # _not_ processed by the shell, but are treated as string literals.
  1789. #
  1790. # STATUS, STDOUT, and STDERR are not checked if equal to `ignore'.
  1791. #
  1792. # If STDOUT is `expout', then stdout is compared to the content of the file
  1793. # `expout'. Likewise for STDERR and `experr'.
  1794. #
  1795. # If STDOUT is `stdout', then the stdout is left in the file `stdout',
  1796. # likewise for STDERR and `stderr'. Don't do this:
  1797. #
  1798. # AT_CHECK([command >out])
  1799. # # Some checks on `out'
  1800. #
  1801. # do this instead:
  1802. #
  1803. # AT_CHECK([command], [], [stdout])
  1804. # # Some checks on `stdout'
  1805. #
  1806. # You might wonder why you can't just use `ignore', then directly use stdout
  1807. # and stderr left by the test suite:
  1808. #
  1809. # AT_CHECK([command], [], [ignore])
  1810. # AT_CHECK([check stdout])
  1811. #
  1812. # If the test suite always captured data in the file `stdout', then the
  1813. # second command would be trying to read and write from the same file, with
  1814. # undefined behavior. Therefore, the test suite actually captures data in
  1815. # an internal file of a different name, and only creates `stdout' when
  1816. # explicitly requested.
  1817. #
  1818. # Any line of stderr starting with leading blanks and a `+' are filtered
  1819. # out, since most shells when tracing include subshell traces in stderr.
  1820. # This may cause spurious failures when the test suite is run with `-x'.
  1821. #
  1822. _AT_DEFINE_SETUP([AT_CHECK],
  1823. [_AT_CHECK(m4_expand([$1]), [$2], AS_ESCAPE(m4_dquote(m4_expand([$3]))),
  1824. AS_ESCAPE(m4_dquote(m4_expand([$4]))), [$5], [$6])])
  1825. # AT_CHECK_UNQUOTED(COMMANDS, [STATUS = 0], STDOUT, STDERR,
  1826. # [RUN-IF-FAIL], [RUN-IF-PASS])
  1827. # ---------------------------------------------------------
  1828. # Like AT_CHECK, but do not AS_ESCAPE shell metacharacters in the STDOUT
  1829. # and STDERR arguments before running the comparison.
  1830. _AT_DEFINE_SETUP([AT_CHECK_UNQUOTED],
  1831. [_AT_CHECK(m4_expand([$1]), [$2], AS_ESCAPE(m4_dquote(m4_expand([$3])), [""]),
  1832. AS_ESCAPE(m4_dquote(m4_expand([$4])), [""]), [$5], [$6])])
  1833. # AT_CHECK_NOESCAPE(COMMANDS, [STATUS = 0], STDOUT, STDERR,
  1834. # [RUN-IF-FAIL], [RUN-IF-PASS])
  1835. # ---------------------------------------------------------
  1836. # Obsolete spelling of AT_CHECK_UNQUOTED.
  1837. m4_define([AT_CHECK_NOESCAPE],
  1838. [m4_warn([obsolete], [consider using AT_CHECK_UNQUOTED instead of $0])]dnl
  1839. [_AT_CHECK(m4_expand([$1]), [$2], m4_expand([$3]),
  1840. m4_expand([$4]), [$5], [$6])])
  1841. # _AT_DECIDE_TRACEABLE(COMMANDS)
  1842. # ------------------------------
  1843. # Worker for _AT_CHECK that expands to shell code. If COMMANDS are safe to
  1844. # trace with `set -x', the shell code will evaluate to true. Otherwise,
  1845. # the shell code will print a message stating an aspect of COMMANDS that makes
  1846. # tracing them unsafe, and evaluate to false.
  1847. #
  1848. # Tracing COMMANDS is not safe if they contain a command that spans multiple
  1849. # lines. When the test suite user passes `-x' or `--trace', the test suite
  1850. # precedes every command with a `set -x'. Since most tests expect a specific
  1851. # stderr, if only to confirm that it is empty, the test suite filters ^+ from
  1852. # the captured stderr before comparing with the expected stderr. If a command
  1853. # spans multiple lines, so will its trace, but a `+' only prefixes the first
  1854. # line of that trace:
  1855. #
  1856. # $ echo 'foo
  1857. # bar'
  1858. # => stdout
  1859. # foo
  1860. # bar
  1861. # => stderr
  1862. # + foo
  1863. # bar
  1864. #
  1865. # In a subset of cases, one could filter such extended shell traces from
  1866. # stderr. Since test commands spanning several lines are rare, I chose
  1867. # instead to simply not trace COMMANDS that could yield multiple trace lines.
  1868. # Distinguishing such COMMANDS became the task at hand.
  1869. #
  1870. # These features may cause a shell command to span multiple lines:
  1871. #
  1872. # (a) A quoted literal newline.
  1873. # Example:
  1874. # echo foo'
  1875. # 'bar
  1876. # M4 is a hostile language for the job of parsing COMMANDS to determine whether
  1877. # each literal newline is quoted, so we simply disable tracing for all COMMANDS
  1878. # that bear literal newlines.
  1879. #
  1880. # (b) A command substitution not subject to word splitting.
  1881. # Example:
  1882. # var=$(printf 'foo\nbar')
  1883. # Example:
  1884. # echo "`printf 'foo\\nbar`"
  1885. # One cannot know in general the number of lines a command substitution will
  1886. # yield without executing the substituted command. As such, we disable tracing
  1887. # for all COMMANDS containing these constructs.
  1888. #
  1889. # (c) A parameter expansion not subject to word splitting.
  1890. # Example:
  1891. # var=foo'
  1892. # 'bar
  1893. # echo "$var"
  1894. # Parameter expansions appear in COMMANDS with much greater frequency than do
  1895. # newlines and command substitutions, so disabling tracing for all such
  1896. # COMMANDS would much more substantially devalue `testsuite -x'. To determine
  1897. # which parameter expansions yield multiple lines, we escape all ``', `"',
  1898. # and `\' in a copy of COMMANDS and expand that string within double quotes
  1899. # at runtime. If the result of that expansion contains multiple lines, the
  1900. # test suite disables tracing for the command in question.
  1901. #
  1902. # This method leads the test suite to expand some parameters that the shell
  1903. # itself will never expand due to single-quotes or backslash escapes. This is
  1904. # not a problem for `$foo' expansions, which will simply yield the empty string
  1905. # or some unrelated value. A `${...}' expansion could actually form invalid
  1906. # shell code, however; consider `${=foo}'. Therefore, we disable tracing for
  1907. # all COMMANDS containing `${...}'. This affects few COMMANDS.
  1908. #
  1909. # This macro falls in a very hot path; the Autoconf test suite expands it 1640
  1910. # times as of this writing. To give a sense of the impact of the heuristics I
  1911. # just described, the test suite preemptively disables tracing for 31 of those,
  1912. # and 268 contain parameter expansions that require runtime evaluation. The
  1913. # balance are always safe to trace.
  1914. m4_define([_AT_DECIDE_TRACEABLE],
  1915. dnl Utility macro.
  1916. dnl
  1917. dnl Examine COMMANDS for a reason to never trace COMMANDS.
  1918. [m4_pushdef([at_reason],
  1919. m4_cond([m4_eval(m4_index([$1], [`]) >= 0)], [1],
  1920. [[a `...` command substitution]],
  1921. [m4_eval(m4_index([$1], [$(]) >= 0)], [1],
  1922. [[a $(...) command substitution]],
  1923. [m4_eval(m4_index([$1], [${]) >= 0)], [1],
  1924. [[a ${...} parameter expansion]],
  1925. [m4_eval(m4_index([$1], m4_newline) >= 0)], [1],
  1926. [[an embedded newline]],
  1927. [m4_eval(m4_bregexp([$1], [[^|]|[^|]]) >= 0)], [1],
  1928. [[a shell pipeline]],
  1929. []))]dnl No reason.
  1930. [m4_if(m4_index(_m4_defn([at_reason]), [a]), [0],]dnl
  1931. dnl We know at build time that tracing COMMANDS is never safe.
  1932. [[at_fn_check_prepare_notrace '_m4_defn([at_reason])'],
  1933. m4_index([$1], [$]), [-1],]dnl
  1934. dnl We know at build time that tracing COMMANDS is always safe.
  1935. [[at_fn_check_prepare_trace],]dnl
  1936. dnl COMMANDS may contain parameter expansions; expand them at runtime.
  1937. [[at_fn_check_prepare_dynamic "AS_ESCAPE([[$1]], [`\"])"])[]]dnl
  1938. [_m4_popdef([at_reason])])
  1939. # AT_DIFF_STDERR/AT_DIFF_STDOUT
  1940. # -----------------------------
  1941. # These are subroutines of AT_CHECK. Using indirect dispatch is a tad
  1942. # faster than using m4_case, and these are called very frequently.
  1943. m4_define([AT_DIFF_STDERR(stderr)],
  1944. [echo stderr:; tee stderr <"$at_stderr"])
  1945. m4_define([AT_DIFF_STDERR(stderr-nolog)],
  1946. [echo stderr captured; cp "$at_stderr" stderr])
  1947. m4_define([AT_DIFF_STDERR(ignore)],
  1948. [echo stderr:; cat "$at_stderr"])
  1949. m4_define([AT_DIFF_STDERR(ignore-nolog)])
  1950. m4_define([AT_DIFF_STDERR(experr)],
  1951. [$at_diff experr "$at_stderr" || at_failed=:])
  1952. m4_define([AT_DIFF_STDERR()],
  1953. [at_fn_diff_devnull "$at_stderr" || at_failed=:])
  1954. m4_define([AT_DIFF_STDOUT(stdout)],
  1955. [echo stdout:; tee stdout <"$at_stdout"])
  1956. m4_define([AT_DIFF_STDOUT(stdout-nolog)],
  1957. [echo stdout captured; cp "$at_stdout" stdout])
  1958. m4_define([AT_DIFF_STDOUT(ignore)],
  1959. [echo stdout:; cat "$at_stdout"])
  1960. m4_define([AT_DIFF_STDOUT(ignore-nolog)])
  1961. m4_define([AT_DIFF_STDOUT(expout)],
  1962. [$at_diff expout "$at_stdout" || at_failed=:])
  1963. m4_define([AT_DIFF_STDOUT()],
  1964. [at_fn_diff_devnull "$at_stdout" || at_failed=:])
  1965. # _AT_CHECK(COMMANDS, [STATUS = 0], STDOUT, STDERR,
  1966. # [RUN-IF-FAIL], [RUN-IF-PASS])
  1967. # -------------------------------------------------
  1968. # Worker for AT_CHECK and AT_CHECK_UNQUOTED, with COMMANDS, STDOUT, and
  1969. # STDERR pre-expanded.
  1970. #
  1971. # Implementation Details
  1972. # ----------------------
  1973. # Ideally, we would like to run
  1974. #
  1975. # ( $at_traceon; COMMANDS >at-stdout 2> at-stderr )
  1976. #
  1977. # but we must group COMMANDS as it is not limited to a single command, and
  1978. # then the shells will save the traces in at-stderr. So we have to filter
  1979. # them out when checking stderr, and we must send them into the test suite's
  1980. # stderr to honor -x properly. Since only the first line of the trace of a
  1981. # multiline command starts with a `+', and I know of no straightforward way to
  1982. # filter out the unadorned trace lines, we disable shell tracing entirely for
  1983. # commands that could span multiple lines.
  1984. #
  1985. # Limiting COMMANDS to a single command is not good either, since then
  1986. # the user herself would use {} or (), and then we face the same problem.
  1987. #
  1988. # But then, there is no point in running
  1989. #
  1990. # ( $at_traceon { $1 ; } >at-stdout 2>at-stder1 )
  1991. #
  1992. # instead of the simpler
  1993. #
  1994. # ( $at_traceon; $1 ) >at-stdout 2>at-stder1
  1995. #
  1996. # Note that we truncate and append to the output files, to avoid losing
  1997. # output from multiple concurrent processes, e.g., an inner testsuite
  1998. # with parallel jobs.
  1999. m4_define([_AT_CHECK],
  2000. [m4_define([AT_ingroup])]dnl
  2001. [{ set +x
  2002. AS_ECHO(["$at_srcdir/AT_LINE: AS_ESCAPE([[$1]])"])
  2003. _AT_DECIDE_TRACEABLE([$1]) _AT_LINE_ESCAPED
  2004. ( $at_check_trace; [$1]
  2005. ) >>"$at_stdout" 2>>"$at_stderr" AS_MESSAGE_LOG_FD>&-
  2006. at_status=$? at_failed=false
  2007. $at_check_filter
  2008. m4_ifdef([AT_DIFF_STDERR($4)], [m4_indir([AT_DIFF_STDERR($4)])],
  2009. [echo >>"$at_stderr"; AS_ECHO([["$4"]]) | \
  2010. $at_diff - "$at_stderr" || at_failed=:])
  2011. m4_ifdef([AT_DIFF_STDOUT($3)], [m4_indir([AT_DIFF_STDOUT($3)])],
  2012. [echo >>"$at_stdout"; AS_ECHO([["$3"]]) | \
  2013. $at_diff - "$at_stdout" || at_failed=:])
  2014. m4_if([$2], [ignore], [at_fn_check_skip],
  2015. [at_fn_check_status m4_default([$2], [0])]) $at_status "$at_srcdir/AT_LINE"
  2016. m4_ifvaln([$5$6], [AS_IF($at_failed, [$5], [$6])])]dnl
  2017. [$at_failed && at_fn_log_failure AT_capture_files
  2018. $at_traceon; }
  2019. ])# _AT_CHECK
  2020. # _AT_CHECK_EXIT(COMMANDS, [EXIT-STATUS-IF-PASS])
  2021. # -----------------------------------------------
  2022. # Minimal version of _AT_CHECK for AT_SKIP_IF and AT_FAIL_IF.
  2023. m4_define([_AT_CHECK_EXIT],
  2024. [m4_define([AT_ingroup])]dnl
  2025. [AS_ECHO(_AT_LINE_ESCAPED) >"$at_check_line_file"
  2026. m4_ifval([$1], [($1) \
  2027. && ])at_fn_check_skip $2 "$at_srcdir/AT_LINE"])# _AT_CHECK_EXIT