general.m4 72 KB

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