autotest.at 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955
  1. # -*- Autotest -*-
  2. AT_BANNER([Autotest.])
  3. # Copyright (C) 2004-2012 Free Software Foundation, Inc.
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. # AT_DATA_AUTOTEST(FILE-NAME, CONTENTS)
  18. # -------------------------------------
  19. # Escape the invalid tokens with @&t@.
  20. m4_define([AT_DATA_AUTOTEST],
  21. [AT_DATA([$1],
  22. [m4_bpatsubst([$2], [\(@.\)\(.@\)\|\(m4\|AS\|AT\)\(_\)\|\(d\)\(nl\)],
  23. [\1\3\5@&t@\2\4\6])])])
  24. # AT_CHECK_AT_PREP(NAME, SUITE-CODE, [STATUS = 0], [STDOUT], [STDERR],
  25. # [DIR = .])
  26. # --------------------------------------------------------------------
  27. # Create a new testsuite named NAME that runs a minimal Autotest test suite,
  28. # SUITE-CODE. Do not use `testsuite' for NAME, or the log file it generates
  29. # will overwrite the log that the Autoconf test produces when managing
  30. # this test case. STATUS, STDOUT, and STDERR pass directly to the AT_CHECK
  31. # that compiles the testsuite. DIR can specify a particular subdirectory
  32. # where the testsuite should live.
  33. m4_define([AT_CHECK_AT_PREP],
  34. [AT_KEYWORDS([autotest])dnl
  35. dnl overquote AT_dir, to make it easier to use
  36. m4_pushdef([AT_dir], m4_ifval([$6], [[[$6]]], [.]))dnl
  37. dnl
  38. AT_CAPTURE_FILE(AT_dir[/$1.log])dnl
  39. dnl
  40. AT_DATA_AUTOTEST(AT_dir[/package.m4],
  41. [[m4_define([AT_PACKAGE_NAME], [GNU Nonsense])
  42. m4_define([AT_PACKAGE_TARNAME], [nonsense])
  43. m4_define([AT_PACKAGE_VERSION], [1.0])
  44. m4_define([AT_PACKAGE_STRING], [GNU Nonsense 1.0])
  45. m4_define([AT_PACKAGE_BUGREPORT], [bug-autoconf@gnu.org])
  46. ]])
  47. dnl
  48. AT_DATA_AUTOTEST(AT_dir[/$1.at], [$2])
  49. AT_CHECK([cat >m4_default([$6], [.])/atconfig <<EOF
  50. at_testdir=m4_default([$6], [.])
  51. abs_builddir='`pwd`'
  52. at_srcdir=.
  53. abs_srcdir='`pwd`'
  54. at_top_srcdir=.
  55. abs_top_srcdir='`pwd`'
  56. at_top_build_prefix=
  57. abs_top_builddir='`pwd`'
  58. EOF])
  59. m4_ifval([$6], [(cd AT_dir])
  60. AT_CHECK_AUTOM4TE([--language=autotest -o $1 $1.at], [$3], [$4], [$5])
  61. m4_ifval([$6], [)])
  62. m4_popdef([AT_dir])dnl
  63. ]) # AT_CHECK_AT_PREP
  64. # AT_CHECK_AT(TITLE, SUITE-CODE, [XFAIL-CONDITION], [STATUS = 0],
  65. # [STDOUT = ignore], STDERR, [PRE-TEST-CODE],
  66. # [POST-TEST-CODE], [SUITE-ARGS])
  67. # ---------------------------------------------------------------
  68. # Create a new test named TITLE that runs a minimal Autotest test suite,
  69. # SUITE-CODE with additional SUITE-ARGS, once without and once with
  70. # '-v -x' added. Call AT_XFAIL_IF with XFAIL-CONDITION. Pass STDERR
  71. # directly to the AT_CHECK that calls the minimal test suite, STDOUT to
  72. # the AT_CHECK without '-v -x'; ignore stdout for the latter.
  73. # Run PRE-TEST-CODE at the top level after the micro-suite is created, but
  74. # before it is run, and POST-TEST-CODE after the micro-suite has been run.
  75. m4_define([AT_CHECK_AT],
  76. [AT_SETUP([$1])
  77. AT_XFAIL_IF([$3])
  78. AT_CHECK_AT_PREP([micro-suite], [$2])
  79. $7
  80. AT_CHECK([$CONFIG_SHELL ./micro-suite $9], m4_default([$4], 0),
  81. m4_default([$5], [ignore]), [$6])
  82. AT_CHECK([$CONFIG_SHELL ./micro-suite -v -x $9], m4_default([$4], 0),
  83. [ignore], [$6])
  84. $8
  85. AT_CLEANUP
  86. ])# AT_CHECK_AT
  87. # AT_CHECK_AT_TEST(TITLE, SUITE-SNIPPET, ...)
  88. # -------------------------------------------
  89. # Wrapper for AT_CHECK_AT that surrounds SUITE-SNIPPET with a boilerplate
  90. # AT_INIT, AT_SETUP, and AT_CLEANUP and passes other arguments verbatim.
  91. m4_define([AT_CHECK_AT_TEST],
  92. [AT_CHECK_AT([$1],
  93. [[
  94. AT_INIT([artificial test suite])
  95. AT_SETUP([my only test])
  96. $2
  97. AT_CLEANUP
  98. ]], m4_shift2($@))]) # AT_CHECK_AT_TEST
  99. # AT_CHECK_AT_SYNTAX(TITLE, SUITE, MESSAGE)
  100. # -----------------------------------------
  101. # Create a test named TITLE that tries compiling SUITE with syntax
  102. # errors with autotest. Expect a failed compilation, and grep for
  103. # MESSAGE occurring within the error output.
  104. m4_define([AT_CHECK_AT_SYNTAX],
  105. [AT_SETUP([$1])
  106. AT_CHECK_AT_PREP([micro-suite], [$2], [1], [], [stderr])
  107. AT_CHECK([grep '$3' stderr], [0], [ignore])
  108. AT_CLEANUP
  109. ])# AT_CHECK_AT_SYNTAX
  110. # AT_NO_CMDSUBST
  111. # --------------
  112. m4_define([AT_NO_CMDSUBST],
  113. [if (eval 'foo=$(echo bar) && test "$foo" = bar') >/dev/null 2>&1; then ]dnl
  114. [false; else :; fi])
  115. # AT_CHECK_EGREP(PATTERN, STATUS, COUNT)
  116. # --------------------------------------
  117. # Run grep -E, counting how many times PATTERN occurs in the file 'stdout',
  118. # and expecting exit STATUS and output COUNT.
  119. m4_define([AT_CHECK_EGREP],
  120. [AT_CHECK([$EGREP -c '$1' stdout], [$2], [$3
  121. ], [ignore])
  122. ])
  123. ## -------------- ##
  124. ## AT_COPYRIGHT. ##
  125. ## -------------- ##
  126. # Ensure the FSF notice as well as the user-provided one are present
  127. # in the head of the testsuite as well as the --version output.
  128. AT_CHECK_AT([AT@&t@_COPYRIGHT],
  129. [[AT_INIT([Testing AT@&t@_COPYRIGHT])
  130. AT_COPYRIGHT([[This is just a test notice, not a real one, so let's avoid
  131. words that may be matched by scanners for legal things,
  132. causing extra work for distributors.
  133. Multi-line values should be supported.
  134. ]])
  135. ]], [], [], [stdout], [], [], [
  136. AT_CHECK([grep 'Copyright.*Free Software Foundation' stdout], [], [ignore])
  137. AT_CHECK([grep 'This is just a test notice' stdout], [], [ignore])
  138. AT_CHECK([sed 50q micro-suite | grep 'Copyright.*Free Software Foundation'],
  139. [], [ignore])
  140. AT_CHECK([sed 50q micro-suite | grep 'This is just a test notice'],
  141. [], [ignore])],
  142. [--version])
  143. ## --------- ##
  144. ## AT_DATA. ##
  145. ## --------- ##
  146. AT_CHECK_AT_TEST([AT@&t@_DATA], [
  147. AT_CHECK([test -f file1], [1])
  148. AT_DATA([file1])
  149. AT_CHECK([test -f file1 && test ! -s file1])
  150. AT_CHECK([echo hi > file1])
  151. AT_DATA([file1], [[]])
  152. AT_CHECK([test -f file1 && test ! -s file1])
  153. file=file2
  154. AT_DATA([$file], [[$file
  155. ]])
  156. AT_CHECK([echo '$file' > file3])
  157. AT_CHECK([cmp file2 file3])
  158. ])
  159. ## ------------------ ##
  160. ## Empty test suite. ##
  161. ## ------------------ ##
  162. # This is not a sensible thing to do, but the user should not get an unhelpful
  163. # error message.
  164. AT_CHECK_AT([Empty test suite],
  165. [[AT_INIT([empty test suite])
  166. ]])
  167. AT_CHECK_AT([Banner-only test suite],
  168. [[AT_INIT([empty test suite])
  169. AT_BANNER([banner])
  170. ]])
  171. # Next level of emptiness.
  172. AT_CHECK_AT_TEST([Empty test], [])
  173. # And finally, an empty check should not cause a syntax error.
  174. AT_CHECK_AT_TEST([Empty check], [AT_CHECK])
  175. # Check for sensible error messages for common bugs.
  176. AT_CHECK_AT_SYNTAX([AT@&t@_SETUP without AT@&t@_INIT],
  177. [[AT_SETUP([only test])
  178. AT_CHECK([:])
  179. AT_CLEANUP
  180. ]], [AT@&t@_SETUP: missing AT@&t@_INIT detected])
  181. AT_CHECK_AT_SYNTAX([AT@&t@_BANNER without AT@&t@_INIT],
  182. [[AT_BANNER([just a banner])
  183. ]], [AT@&t@_BANNER: missing AT@&t@_INIT detected])
  184. AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_INIT],
  185. [[AT_CLEANUP
  186. ]], [AT@&t@_CLEANUP: missing AT@&t@_INIT detected])
  187. AT_CHECK_AT_SYNTAX([Missing AT@&t@_CLEANUP],
  188. [[AT_INIT([incomplete test suite])
  189. AT_SETUP([only test])
  190. AT_CHECK([:])
  191. ]], [missing AT@&t@_CLEANUP detected])
  192. AT_CHECK_AT_SYNTAX([AT@&t@_FAIL_IF without AT@&t@_SETUP],
  193. [[AT_INIT([incomplete test suite])
  194. AT_FAIL_IF([:])
  195. ]], [AT@&t@_FAIL_IF: missing AT@&t@_SETUP detected])
  196. AT_CHECK_AT_SYNTAX([AT@&t@_SKIP_IF without AT@&t@_SETUP],
  197. [[AT_INIT([incomplete test suite])
  198. AT_SKIP_IF([:])
  199. ]], [AT@&t@_SKIP_IF: missing AT@&t@_SETUP detected])
  200. AT_CHECK_AT_SYNTAX([AT@&t@_CHECK without AT@&t@_SETUP],
  201. [[AT_INIT([incomplete test suite])
  202. AT_CHECK([:])
  203. ]], [AT@&t@_CHECK: missing AT@&t@_SETUP detected])
  204. AT_CHECK_AT_SYNTAX([AT@&t@_DATA without AT@&t@_SETUP],
  205. [[AT_INIT([incomplete test suite])
  206. AT_DATA([file])
  207. ]], [AT@&t@_DATA: missing AT@&t@_SETUP detected])
  208. AT_CHECK_AT_SYNTAX([AT@&t@_XFAIL_IF without AT@&t@_SETUP],
  209. [[AT_INIT([incomplete test suite])
  210. AT_XFAIL_IF([:])
  211. ]], [AT@&t@_XFAIL_IF: missing AT@&t@_SETUP detected])
  212. AT_CHECK_AT_SYNTAX([AT@&t@_KEYWORDS without AT@&t@_SETUP],
  213. [[AT_INIT([incomplete test suite])
  214. AT_KEYWORDS([keyword])
  215. ]], [AT@&t@_KEYWORDS: missing AT@&t@_SETUP detected])
  216. AT_CHECK_AT_SYNTAX([AT@&t@_CLEANUP without AT@&t@_SETUP],
  217. [[AT_INIT([incomplete test suite])
  218. AT_CLEANUP
  219. ]], [AT@&t@_CLEANUP: missing AT@&t@_SETUP detected])
  220. AT_CHECK_AT_SYNTAX([AT@&t@_BANNER inside AT@&t@_SETUP],
  221. [[AT_INIT([incomplete test suite])
  222. AT_SETUP([only test])
  223. AT_BANNER([banner])
  224. AT_CHECK([:])
  225. AT_CLEANUP
  226. ]], [AT@&t@_BANNER: nested AT@&t@_SETUP detected])
  227. AT_CHECK_AT_SYNTAX([AT@&t@_SETUP inside AT@&t@_SETUP],
  228. [[AT_INIT([incomplete test suite])
  229. AT_SETUP([only test])
  230. AT_SETUP([nested test])
  231. AT_CHECK([:])
  232. AT_CLEANUP
  233. AT_CHECK([:])
  234. AT_CLEANUP
  235. ]], [AT@&t@_SETUP: nested AT@&t@_SETUP detected])
  236. AT_CHECK_AT_SYNTAX([Multiple AT@&t@_INIT],
  237. [[AT_INIT([[suite, take one]])
  238. AT_INIT([repeat])
  239. ]], [AT@&t@_INIT: invoked multiple times])
  240. # Check for tested programs. autoconf should only appear once.
  241. AT_CHECK_AT([Tested programs],
  242. [[AT_INIT([programs test suite])
  243. AT_TESTED([autoconf autom4te])
  244. AT_TESTED([autoconf])
  245. ]], [], [], [], [], [],
  246. [AT_CHECK([[sed -n 's|.*/\([^ /]* --version\)|\1|p' micro-suite.log]], [],
  247. [[autoconf --version
  248. autom4te --version
  249. ]])])
  250. AT_CHECK_AT([Startup error messages],
  251. [[AT_INIT([[suite]])
  252. AT_SETUP([only test])
  253. AT_CHECK([:])
  254. AT_CLEANUP
  255. ]], [], [], [], [], [],
  256. [AT_CHECK([sed -n '/exec AS_MESSAGE_LOG_FD/q; />&AS_MESSAGE_LOG_FD/p' < micro-suite])])
  257. ## ----------------- ##
  258. ## Status handling. ##
  259. ## ----------------- ##
  260. AT_CHECK_AT_TEST([Truth],
  261. [AT_CHECK([:], 0, [], [])])
  262. AT_CHECK_AT_TEST([Fallacy],
  263. [AT_CHECK([false], [], [], [])],
  264. [], [1], [], [ignore], [],
  265. [AT_CHECK([grep failed micro-suite.log], [], [ignore])])
  266. AT_CHECK_AT_TEST([Skip],
  267. [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])],
  268. [], [], [], [], [],
  269. [AT_CHECK([grep skipped micro-suite.log], [], [ignore])])
  270. AT_CHECK_AT_TEST([Hard fail],
  271. [AT_CHECK([exit 99])
  272. AT_CLEANUP
  273. AT_SETUP([another test])
  274. AT_XFAIL_IF([:])
  275. AT_CHECK([exit 99])],
  276. [], [1], [], [ignore], [],
  277. [AT_CHECK([grep '2 failed unexpectedly' micro-suite.log], [], [ignore])
  278. AT_CHECK([grep '^[[12]].*ok' micro-suite.log], [1])])
  279. AT_CHECK_AT_TEST([AT@&t@_FAIL_IF],
  280. [AT_FAIL_IF([:])
  281. AT_CLEANUP
  282. AT_SETUP
  283. AT_FAIL_IF([false])
  284. AT_CLEANUP
  285. AT_SETUP
  286. AT_FAIL_IF([test x = y])
  287. AT_CLEANUP
  288. AT_SETUP
  289. AT_FAIL_IF([bah])
  290. AT_CLEANUP
  291. AT_SETUP
  292. AT_FAIL_IF([test x = x])
  293. AT_CLEANUP
  294. AT_SETUP
  295. AT_FAIL_IF([test $foo = x])],
  296. [], [1], [stdout], [ignore], [],
  297. [AT_CHECK([grep '1 5 failed' stdout], [], [ignore], [ignore])])
  298. AT_CHECK_AT_TEST([AT@&t@_SKIP_IF],
  299. [AT_SKIP_IF([:])
  300. AT_CLEANUP
  301. AT_SETUP
  302. AT_SKIP_IF([false])
  303. AT_CLEANUP
  304. AT_SETUP
  305. AT_SKIP_IF([test x = y])
  306. AT_CLEANUP
  307. AT_SETUP
  308. AT_SKIP_IF([bah])
  309. AT_CLEANUP
  310. AT_SETUP
  311. AT_SKIP_IF([test x = x])
  312. AT_CLEANUP
  313. AT_SETUP
  314. AT_SKIP_IF([test $foo = x])],
  315. [], [], [], [], [],
  316. [AT_CHECK([grep '2.*skipped' micro-suite.log], [], [ignore], [ignore])])
  317. AT_CHECK_AT_TEST([Syntax error],
  318. [AT_CHECK([:])
  319. AT_CLEANUP
  320. AT_SETUP([syntax])
  321. AT_CHECK([if])
  322. AT_CLEANUP
  323. AT_SETUP([another test])
  324. AT_CHECK([:])],
  325. [], [0], [], [], [],
  326. [dnl Until we can find a way to avoid catastrophic failure (ash) or
  327. dnl lack of failure (zsh), skip the rest of this test on such shells.
  328. echo 'if' > syntax
  329. AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
  330. 0|"") exit 77;;
  331. esac'], [0], [ignore], [ignore])
  332. AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore], [stderr])
  333. AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])],
  334. [1 3])
  335. AT_CHECK_AT_TEST([errexit],
  336. [AT_CHECK([false])
  337. AT_CLEANUP
  338. AT_SETUP([test that should not be run])
  339. AT_CHECK([:])
  340. AT_CLEANUP
  341. AT_SETUP([xpassing test])
  342. AT_XFAIL_IF([:])
  343. AT_CHECK([:])
  344. AT_CLEANUP
  345. AT_SETUP([another test that should not be run])
  346. AT_CHECK([:])
  347. AT_CLEANUP
  348. AT_SETUP([skipping test])
  349. AT_CHECK([exit 77])
  350. AT_CLEANUP
  351. AT_SETUP([xfailing test])
  352. AT_XFAIL_IF([:])
  353. AT_CHECK([false])
  354. AT_CLEANUP
  355. AT_SETUP([a test that should be run])
  356. AT_CLEANUP
  357. AT_SETUP([hard failure])
  358. AT_XFAIL_IF([:])
  359. AT_CHECK([exit 99])
  360. AT_CLEANUP
  361. AT_SETUP([yet another test that should not be run])],
  362. [], [1], [stdout], [stderr], [],
  363. [AT_CHECK([test -f micro-suite.log], [1])
  364. touch micro-suite.log # shut up AT_CAPTURE_FILE.
  365. AT_CHECK([grep "should not be run" stdout], [1])
  366. AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore])
  367. AT_CHECK([$CONFIG_SHELL ./micro-suite --errexit 3-], [1], [stdout], [stderr])
  368. AT_CHECK([grep "should not be run" stdout], [1])
  369. AT_CHECK([grep "1 .* inhibited subsequent" stderr], [], [ignore])
  370. AT_CHECK([$CONFIG_SHELL ./micro-suite --errexit 5-], [1], [stdout], [stderr])
  371. AT_CHECK([grep "should be run" stdout], [0], [ignore])
  372. AT_CHECK([grep "should not be run" stdout], [1])
  373. AT_CHECK([grep "inhibited subsequent" stderr], [], [ignore])],
  374. [--errexit])
  375. AT_CHECK_AT_TEST([at_status],
  376. [AT_CHECK([exit $mystatus], [$expected], [], [],
  377. [AT_CHECK([echo run-if-fail: $at_status], [], [ignore])],
  378. [AT_CHECK([echo run-if-pass: $at_status], [], [ignore])])
  379. AT_CLEANUP
  380. AT_SETUP([test with nested checks])
  381. AT_CHECK([exit $mystatus], [$expected], [], [],
  382. [AT_CHECK([exit $mystatus], [$expected], [], [],
  383. [AT_CHECK([echo inner run-if-fail: $at_status], [],
  384. [ignore])])])],
  385. [], [], [stdout], [],
  386. [], [
  387. AT_CHECK([grep 'inner run-if-fail: 42' stdout], [], [ignore])
  388. AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=0 expected=0], [], [stdout])
  389. AT_CHECK([grep 'run-if-pass: 0' stdout], [], [ignore])
  390. AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=42 expected=0], [], [stdout])
  391. AT_CHECK([grep 'run-if-fail: 42' stdout], [], [ignore])
  392. AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=0 expected=42], [], [stdout])
  393. AT_CHECK([grep 'run-if-fail: 0' stdout], [], [ignore])
  394. AT_CHECK([$CONFIG_SHELL ./micro-suite -x -v 1 mystatus=42 expected=42], [], [stdout])
  395. AT_CHECK([grep 'run-if-pass: 42' stdout], [], [ignore])
  396. ],
  397. [-v mystatus=42 expected=1
  398. ])
  399. AT_CHECK_AT_TEST([AT@&t@_CHECK execution environment],
  400. [dnl The first test should fail, so we enter RUN-IF-FAIL.
  401. AT_CHECK([test "$state" != before], [], [], [],
  402. [state=run-if-fail
  403. AT_CHECK([:]) dnl need this so we do not bail out at this point.
  404. ])
  405. dnl This should pass, so we enter RUN-IF-PASS.
  406. AT_CHECK([test "$state" = run-if-fail], [], [], [], [],
  407. [state=run-if-pass])
  408. AT_CHECK([test "$state" = run-if-pass])
  409. dnl However, COMMANDS are run inside a subshell, so do not change state.
  410. AT_CHECK([state=broken; false], [], [], [],
  411. [AT_CHECK([test "$state" = run-if-pass])])
  412. AT_CHECK([state=broken], [], [], [], [],
  413. [AT_CHECK([test "$state" = run-if-pass])])
  414. ],
  415. [], [], [], [], [], [], [state=before])
  416. AT_CHECK_AT_TEST([unquoted output],
  417. [m4_define([backtick], [`])
  418. a=a
  419. AT_CHECK_UNQUOTED([echo 'a"b backtick`'], [],
  420. [${a}"`echo 'b '`\`\backtick]m4_newline)],
  421. [], [], [], [], [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])])
  422. AT_CHECK_AT_TEST([Trace output],
  423. [AT_CHECK([echo some longer longer longer command piped | ]dnl
  424. [sed 's,into some other longer longer longer command,,'],
  425. [], [some longer longer longer command piped
  426. ])])
  427. AT_CHECK_AT([Logging],
  428. [[AT_INIT([artificial test suite])
  429. dnl intentionally write failing tests, to see what gets logged
  430. AT_SETUP([one])
  431. AT_CHECK([echo magicstring01], [1], [ignore])
  432. AT_CLEANUP
  433. AT_SETUP([two])
  434. AT_CHECK([echo magicstring02 >&2], [1], [], [ignore])
  435. AT_CLEANUP
  436. AT_SETUP([three])
  437. AT_CHECK([echo magicstring03], [1], [ignore-nolog])
  438. AT_CLEANUP
  439. AT_SETUP([four])
  440. AT_CHECK([echo magicstring04 >&2], [1], [], [ignore-nolog])
  441. AT_CLEANUP
  442. AT_SETUP([five])
  443. AT_CHECK([echo magicstring05], [1], [stdout])
  444. AT_CLEANUP
  445. AT_SETUP([six])
  446. AT_CHECK([echo magicstring06 >&2], [1], [], [stderr])
  447. AT_CLEANUP
  448. AT_SETUP([seven])
  449. AT_CHECK([echo magicstring07], [1], [stdout-nolog])
  450. AT_CLEANUP
  451. AT_SETUP([eight])
  452. AT_CHECK([echo magicstring08 >&2], [1], [], [stderr-nolog])
  453. AT_CLEANUP
  454. AT_SETUP([nine])
  455. echo magicstring09 > expout
  456. AT_CHECK([echo magicstring09], [1], [expout])
  457. AT_CLEANUP
  458. AT_SETUP([ten])
  459. echo magicstring10 > experr
  460. AT_CHECK([echo magicstring10 >&2], [1], [], [experr])
  461. AT_CLEANUP
  462. ]], [], [1], [], [ignore], [],
  463. [AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore-nolog], [ignore-nolog])
  464. AT_CHECK([grep '^magicstring' micro-suite.log], [],
  465. [[magicstring01
  466. magicstring02
  467. magicstring05
  468. magicstring06
  469. ]])])
  470. AT_CHECK_AT([Binary output],
  471. [[AT_INIT([artificial test suite])
  472. AT_SETUP([pass: no trailing newline])
  473. AT_CHECK([printf short], [0], [stdout-nolog])
  474. AT_CHECK([cat stdout], [0], [[short]])
  475. AT_CLEANUP
  476. AT_SETUP([pass: non-printing characters])
  477. AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
  478. printf '\1\n' > expout
  479. AT_CHECK([cat stderr], [0], [expout])
  480. AT_CLEANUP
  481. AT_SETUP([pass: long lines])
  482. # 5000 bytes in str
  483. str=..........
  484. str=$str$str$str$str$str$str$str$str$str$str
  485. str=$str$str$str$str$str$str$str$str$str$str
  486. str=$str$str$str$str$str
  487. AT_CHECK_UNQUOTED([echo $str], [0], [[$str]m4_newline])
  488. AT_CLEANUP
  489. AT_SETUP([fail: no trailing newline])
  490. AT_CHECK([printf short], [0], [stdout-nolog])
  491. AT_CHECK([cat stdout], [0], [[long]])
  492. AT_CLEANUP
  493. AT_SETUP([fail: non-printing characters])
  494. AT_CHECK([printf '\1\n' >&2], [0], [], [stderr-nolog])
  495. printf '\2\n' > expout
  496. AT_CHECK([cat stderr], [0], [expout])
  497. AT_CLEANUP
  498. AT_SETUP([fail: long lines])
  499. # 5000 bytes in str
  500. str=..........
  501. str=$str$str$str$str$str$str$str$str$str$str
  502. str=$str$str$str$str$str$str$str$str$str$str
  503. str=$str$str$str$str$str
  504. AT_CHECK_UNQUOTED([echo x$str], [0], [[${str}x]m4_newline])
  505. AT_CLEANUP
  506. ]], [], [0], [], [], [],
  507. [AT_CHECK([$CONFIG_SHELL ./micro-suite 4], [1], [ignore], [ignore])
  508. AT_CHECK([$CONFIG_SHELL ./micro-suite 5], [1], [ignore], [ignore])
  509. AT_CHECK([$CONFIG_SHELL ./micro-suite 6], [1], [ignore], [ignore])], [1-3])
  510. AT_CHECK_AT_TEST([Cleanup],
  511. [AT_CHECK([test ! -f cleanup.success && test ! -f cleanup.failure])
  512. AT_XFAIL_IF([$xfail])
  513. AT_CHECK_UNQUOTED([exit $value], [ignore], [$output],
  514. [], [touch cleanup.failure], [touch cleanup.success])],
  515. [], [], [], [],
  516. [AT_KEYWORDS([AT@&t@_CHECK_UNQUOTED])
  517. output=; export output],
  518. [AT_CHECK([test -d micro-suite.dir/1])
  519. AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
  520. AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
  521. AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=1], [], [ignore])
  522. AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
  523. AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
  524. AT_CHECK([$CONFIG_SHELL ./micro-suite xfail=: value=0],
  525. [1], [ignore], [ignore])
  526. AT_CHECK([test -f micro-suite.dir/1/cleanup.success])
  527. AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
  528. AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=1 output=mismatch],
  529. [1], [ignore], [ignore])
  530. AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
  531. AT_CHECK([test -f micro-suite.dir/1/cleanup.failure])
  532. AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=77], [], [ignore])
  533. AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
  534. AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
  535. AT_CHECK([$CONFIG_SHELL ./micro-suite -d xfail=false value=99],
  536. [1], [ignore], [ignore])
  537. AT_CHECK([test ! -f micro-suite.dir/1/cleanup.success])
  538. AT_CHECK([test ! -f micro-suite.dir/1/cleanup.failure])
  539. ], [-d xfail=false value=0])
  540. ## ----------------------------------------------------- ##
  541. ## Newlines and command substitutions in test commands. ##
  542. ## ----------------------------------------------------- ##
  543. AT_CHECK_AT_TEST([Literal multiline command],
  544. [AT_CHECK([echo Auto'
  545. 'conf], 0, [Auto
  546. conf
  547. ], [])])
  548. AT_CHECK_AT_TEST([Multiline parameter expansion],
  549. [FOO='one
  550. two'
  551. AT_CHECK([echo "$FOO"], 0, [one
  552. two
  553. ], [])])
  554. AT_CHECK_AT_TEST([Backquote command substitution],
  555. [AT_CHECK([echo `echo hi`], 0, [hi
  556. ], [])])
  557. AT_CHECK_AT_TEST([Multiline backquote command substitution],
  558. [AT_DATA([myfile],[foo
  559. bar
  560. ])
  561. AT_CHECK([echo "`cat myfile`"], 0, [foo
  562. bar
  563. ], [])])
  564. AT_CHECK_AT_TEST([Parenthetical command substitution],
  565. [AT_CHECK([echo $(echo hi)], 0, [hi
  566. ], [])],
  567. [AT_NO_CMDSUBST])
  568. AT_CHECK_AT_TEST([Multiline parenthetical command substitution],
  569. [AT_DATA([myfile],[foo
  570. bar
  571. ])
  572. AT_CHECK([echo "$(cat myfile)"], 0, [foo
  573. bar
  574. ], [])],
  575. [AT_NO_CMDSUBST])
  576. AT_CHECK_AT_TEST([Shell comment in command],
  577. [my_echo=echo
  578. AT_CHECK([$my_echo one [#] two], [], [one
  579. ])])
  580. ## ------------------------- ##
  581. ## ${...} in test commands. ##
  582. ## ------------------------- ##
  583. # If this invalid parameter expansion capsizes the test suite, the entire
  584. # AT_SETUP ... AT_CLEANUP subshell will exit, and the commands it runs will
  585. # appear to have succeeded. Therefore, we verify a failing test case.
  586. AT_CHECK_AT_TEST([Invalid brace-enclosed parameter expansion],
  587. [AT_CHECK([echo '${=invalid}'], 0, [wrong])], [false], 1, ignore, ignore)
  588. ## ---------------------------- ##
  589. ## M4 macros in test commands. ##
  590. ## ---------------------------- ##
  591. AT_CHECK_AT_TEST([Multiline command from M4 expansion],
  592. [m4_define([GNU], ['foo
  593. bar'])
  594. AT_CHECK([echo GNU], 0, [foo
  595. bar
  596. ], [])])
  597. AT_CHECK_AT_TEST([Double-M4-quoted command],
  598. [m4_define([GNU], ['foo
  599. bar'])
  600. AT_CHECK([[echo GNU]], 0, [[GNU
  601. ]], [])])
  602. AT_CHECK_AT_TEST([Metacharacters in command from M4 expansion],
  603. [m4_define([GNU], [\"`])
  604. AT_CHECK([echo '\"`' [GNU] 'GNU'], 0, [GNU [G][NU] [\"`
  605. ]], [])])
  606. ## -------------------------------------- ##
  607. ## Backslash-<newline> in test commands. ##
  608. ## -------------------------------------- ##
  609. AT_CHECK_AT_TEST([BS-newline in command],
  610. [AT_CHECK([echo Auto"\
  611. "conf], 0, [Autoconf
  612. ], [])])
  613. AT_CHECK_AT_TEST([^BS-newline in command],
  614. [AT_CHECK([\
  615. echo GNU], 0, [GNU
  616. ], [])])
  617. AT_CHECK_AT_TEST([BSx641-newline in command],
  618. [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  619. "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\conf
  620. ], [])])
  621. AT_CHECK_AT_TEST([BS-BS-newline in command],
  622. [AT_CHECK([printf '%s\n' Auto"\\
  623. "conf], 0, [Auto\
  624. conf
  625. ], [])])
  626. # A `^BS-BS-newline in command' test will run a command named `\'. No, thanks.
  627. AT_CHECK_AT_TEST([BSx640-newline in command],
  628. [AT_CHECK([printf '%s\n' Auto"\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  629. "conf], 0, [Auto\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  630. conf
  631. ], [])])
  632. # This command has both escaped and unescaped newlines.
  633. AT_CHECK_AT_TEST([Newline-CODE-BS-newline in command],
  634. [AT_CHECK([printf '%s\n' Auto'
  635. 'co\
  636. nf], 0, [Auto
  637. conf
  638. ], [])])
  639. AT_CHECK_AT_TEST([Single-quote-BS-newline in command],
  640. [AT_CHECK([printf '%s\n' Auto'\
  641. 'conf], 0, [Auto\
  642. conf
  643. ], [])])
  644. AT_CHECK_AT_TEST([Single-quote-newline-BS-newline in command],
  645. [AT_CHECK([printf '%s\n' Auto'
  646. \
  647. 'conf], 0, [Auto
  648. \
  649. conf
  650. ], [])])
  651. ## ----------------- ##
  652. ## Input from stdin. ##
  653. ## ----------------- ##
  654. AT_SETUP([Input from stdin])
  655. AT_CHECK_AT_PREP([micro-suite],
  656. [[AT_INIT
  657. AT_SETUP([please enter hello<RETURN><EOF>])
  658. AT_CHECK([cat], [], [hello
  659. ])
  660. AT_CLEANUP
  661. ]])
  662. AT_CHECK([echo hello | $CONFIG_SHELL ./micro-suite], [], [ignore])
  663. AT_CHECK([$CONFIG_SHELL ./micro-suite </dev/null], [1], [ignore], [ignore])
  664. AT_CLEANUP
  665. ## ------------------------------- ##
  666. ## Funny characters in test names. ##
  667. ## ------------------------------- ##
  668. # AT_CHECK_AT_TITLE(TITLE, TITLE-TO-TEST, EXPANDED-TITLE-TO-TEST,
  669. # [XFAIL-CONDITION], [COLUMN = 53])
  670. # ---------------------------------------------------------------
  671. # Create a new test named TITLE that runs an Autotest test suite
  672. # comprised of a trivial test named TITLE-TO-TEST, which expands
  673. # to EXPANDED-TITLE-TO-TEST. XFAIL-CONDITION passes verbatim to
  674. # AT_CHECK_AT. Verify that `ok' prints at COLUMN.
  675. m4_define([AT_CHECK_AT_TITLE],
  676. [AT_CHECK_AT([$1],
  677. [[
  678. m4_define([macro_name], [[macro_expanded]])
  679. m4_define([macro_expanded], [[macro_overexpanded]])
  680. m4_define([macro_backquote], [`])
  681. m4_define([macro_single_quote], ['])
  682. m4_define([macro_double_quote], ["])
  683. ]]dnl restore font-lock: "
  684. [[m4_define([macro_backslash], [\])
  685. m4_define([macro_echo], [$][1])
  686. AT_INIT([artificial test suite])
  687. AT_SETUP([$2])
  688. AT_CHECK([:])
  689. AT_CLEANUP
  690. ]], [$4], [], [], [], [],
  691. dnl This sed script checks for two things - that the output is properly
  692. dnl expanded, and that the 'ok' starts on the right column.
  693. [AT_KEYWORDS([m4@&t@_expand])
  694. AT_CHECK([[$CONFIG_SHELL ./micro-suite |
  695. sed -n '/^ 1:/{
  696. h
  697. s/[^:]*: \(.*[^ ]\)[ ]*ok.*/\1/p
  698. x
  699. s/^.\{]]]m4_default($5, 53)[[[\}ok.*/ok/p
  700. }']],,
  701. [[$3
  702. ok
  703. ]])
  704. dnl This sed script checks for two things - that -v output doesn't have
  705. dnl an empty $at_srcdir expansion, and that the 'testing ...' line
  706. dnl contains the test group title.
  707. AT_CHECK([[$CONFIG_SHELL ./micro-suite -v |
  708. sed -n 's/.*testing \(.*\) \.\.\./\1/p; /^\/micro-suite\.at:/p']],,
  709. [[$3
  710. ]])
  711. AT_CHECK([[$CONFIG_SHELL ./micro-suite -l |
  712. sed -n 's/.*[0-9]: [^ ][^ ]*[ ][ ]*\(.*[^ ]\)[ ]*/\1/p']],,
  713. [[$3
  714. ]])
  715. AT_CHECK([[sed -n 's/[^.]*\. \(.*\) ([^)]*): ok.*/\1/p' micro-suite.log]],,
  716. [[$3
  717. ]])
  718. ])])
  719. m4_define([AT_CHECK_AT_TITLE_CHAR],
  720. [AT_CHECK_AT_TITLE([$1 in a test title], [A $2 in my name],
  721. [A ]m4_ifval([$3], [[$3]], [[$2]])[ in my name], $4, $5)])
  722. AT_CHECK_AT_TITLE_CHAR([Backquote], [`])
  723. AT_CHECK_AT_TITLE_CHAR([Single-quote], ['])
  724. AT_CHECK_AT_TITLE_CHAR([Double-quote], ["])
  725. dnl restore font-lock: "
  726. AT_CHECK_AT_TITLE_CHAR([Backslash], [\])
  727. AT_CHECK_AT_TITLE_CHAR([Brackets], [[[]]], [[]])
  728. AT_CHECK_AT_TITLE_CHAR([Left bracket], [@<:@], [@<:@])
  729. AT_CHECK_AT_TITLE_CHAR([Right bracket], [@:>@], [@:>@])
  730. AT_CHECK_AT_TITLE_CHAR([Quoted pound], [[#]], [#])
  731. AT_CHECK_AT_TITLE_CHAR([Pound], [#])
  732. AT_CHECK_AT_TITLE_CHAR([Quoted comma], [[,]], [,])
  733. AT_CHECK_AT_TITLE_CHAR([Comma], [,])
  734. dnl this test also hits quadrigraphs for ()
  735. AT_CHECK_AT_TITLE_CHAR([Parentheses], [(@{:@)@:}@], [(())])
  736. AT_CHECK_AT_TITLE_CHAR([Left paren], [[(]], [(])
  737. AT_CHECK_AT_TITLE_CHAR([Right paren], [[)]], [)])
  738. AT_CHECK_AT_TITLE_CHAR([Quoted Macro], [[macro_name]], [macro_name])
  739. AT_CHECK_AT_TITLE_CHAR([Macro], [macro_name], [macro_expanded])
  740. AT_CHECK_AT_TITLE_CHAR([Macro with backquote], [macro_backquote], [`])
  741. AT_CHECK_AT_TITLE_CHAR([Macro with single-quote], [macro_single_quote], ['])
  742. AT_CHECK_AT_TITLE_CHAR([Macro with double-quote], [macro_double_quote], ["])
  743. dnl restore font-lock: "
  744. AT_CHECK_AT_TITLE_CHAR([Macro with backslash], [macro_backslash], [\])
  745. AT_CHECK_AT_TITLE_CHAR([Macro echoing macro], [macro_echo([macro_name])],
  746. [macro_expanded])
  747. AT_CHECK_AT_TITLE_CHAR([Macro echoing single-quote], [macro_echo(['])], ['])
  748. AT_CHECK_AT_TITLE_CHAR([Long test title], [0123456789012345678901234567890123])
  749. AT_CHECK_AT_TITLE_CHAR([Longer test title],
  750. [01234567890123456789012345678901234], [], [], [54])
  751. ## ----------------------- ##
  752. ## Long test source lines. ##
  753. ## ----------------------- ##
  754. # Create a test file that has more than 99 words in a line, for Solaris awk.
  755. # While at that, try out the limit of 2000 bytes in a text file line.
  756. AT_CHECK_AT_TEST([Long test source lines],
  757. [m4_for([nnn], [1], [999], [], [: ])
  758. AT_CHECK([:])
  759. ], [], [], [], [ignore], [],
  760. [AT_CHECK([$CONFIG_SHELL ./micro-suite -k skipalltests], [], [ignore], [ignore])
  761. ])
  762. ## ---------------- ##
  763. ## Huge testsuite. ##
  764. ## ---------------- ##
  765. # Ensure we don't hit line length limits with large test suites.
  766. AT_CHECK_AT_TEST([Huge testsuite],
  767. [m4_for([nnn], [1], [1999], [],
  768. [AT_CLEANUP
  769. AT_SETUP([test ]nnn)
  770. ])
  771. ], [], [], [], [ignore], [], [], [1999])
  772. ## ----------------- ##
  773. ## Debugging a test. ##
  774. ## ----------------- ##
  775. AT_CHECK_AT_TEST([Debugging a successful test],
  776. [AT_CHECK([:])], [], [], [], [ignore], [],
  777. [# Without options, when all tests pass, no test directory should exist.
  778. AT_CHECK([test -d micro-suite.dir/1 && exit 42
  779. $CONFIG_SHELL ./micro-suite -d 1], [], [ignore], [ignore])
  780. # Running with -d should leave a reproducible test group.
  781. # Also, running the test script from the test group locks the
  782. # directory from removal on some platforms; the script should still be
  783. # able to run even if rmdir fails.
  784. AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
  785. # Running a debugging script implies -d.
  786. AT_CHECK([(cd micro-suite.dir/1 && ./run)], [], [ignore], [ignore])
  787. ])
  788. AT_CHECK_AT_TEST([Debugging script and environment],
  789. [AT_CHECK([test "$MY_VAR" = pass || exit 42])],
  790. [], [1], [], [ignore], [], [
  791. # Changing environment outside of debugging script is not preserved.
  792. AT_CHECK([(cd micro-suite.dir/1 && MY_VAR=pass ./run)],
  793. [0], [ignore], [ignore])
  794. AT_CHECK([(cd micro-suite.dir/1 && ./run)],
  795. [1], [ignore], [ignore])
  796. # Changing environment as argument to debugging script is preserved.
  797. AT_CHECK([(cd micro-suite.dir/1; ./run MY_VAR=pass)],
  798. [0], [ignore], [ignore])
  799. AT_CHECK([(cd micro-suite.dir/1; ./run)],
  800. [0], [ignore], [ignore])
  801. ])
  802. # The run script must still be valid when shell metacharacters are passed
  803. # in via an environment option.
  804. AT_CHECK_AT_TEST([Debugging a failed test],
  805. [AT_CHECK([test "$MY_VAR" = "one space" || exit 42])],
  806. [], [1], [], [ignore], [], [
  807. AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='two spaces')],
  808. [1], [ignore], [ignore])
  809. AT_CHECK([(cd micro-suite.dir/1 && ./run MY_VAR='one space')],
  810. [0], [ignore], [ignore])
  811. ])
  812. # Setting default variable values via atlocal.
  813. AT_CHECK_AT_TEST([Using atlocal],
  814. [AT_CHECK([test "x$MY_VAR" = "xodd; 'string" || exit 42])],
  815. [], [1], [ignore], [ignore], [], [
  816. dnl check that command line can set variable
  817. AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR="odd; 'string"], [0], [ignore])
  818. dnl check that command line overrides environment
  819. AT_CHECK([MY_VAR="odd; 'string" $CONFIG_SHELL ./micro-suite MY_VAR=unset],
  820. [1], [ignore], [ignore])
  821. dnl check that atlocal can give it a default
  822. AT_CHECK([cat <<EOF >atlocal
  823. MY_VAR="odd; 'string"
  824. export MY_VAR
  825. dnl Also populate enough of atlocal to do what atconfig normally does.
  826. at_testdir=.
  827. abs_builddir='`pwd`'
  828. at_srcdir=.
  829. abs_srcdir='`pwd`'
  830. at_top_srcdir=.
  831. abs_top_srcdir='`pwd`'
  832. at_top_build_prefix=
  833. abs_top_builddir='`pwd`'
  834. EOF
  835. ])
  836. AT_CHECK([$CONFIG_SHELL ./micro-suite], [0], [ignore])
  837. dnl check that atlocal overrides environment
  838. AT_CHECK([MY_VAR=unset $CONFIG_SHELL ./micro-suite], [0], [ignore])
  839. dnl check that command line overrides atlocal
  840. AT_CHECK([$CONFIG_SHELL ./micro-suite MY_VAR=], [1], [ignore], [ignore])
  841. dnl check that syntax error is detected
  842. AT_CHECK([$CONFIG_SHELL ./micro-suite =], [1], [], [ignore], [ignore])
  843. AT_CHECK([$CONFIG_SHELL ./micro-suite 1=2], [1], [], [ignore], [ignore])
  844. ])
  845. # Controlling where the testsuite is run.
  846. AT_CHECK_AT_TEST([Choosing where testsuite is run],
  847. [AT_CHECK([:])], [], [], [], [], [], [
  848. dnl AT_CHECK_AT_TEST tests the default of running in `.'.
  849. AT_CHECK([$CONFIG_SHELL ./micro-suite --clean])
  850. AT_CHECK([test -f micro-suite.log], [1])
  851. AT_CHECK([test -d micro-suite.dir], [1])
  852. AT_CHECK([mkdir sub1 sub2])
  853. dnl check specifying a different relative path to run in.
  854. AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [0], [ignore], [])
  855. AT_CHECK([test -f micro-suite.log], [1])
  856. AT_CHECK([test -f sub1/micro-suite.log], [0])
  857. AT_CHECK([test -d micro-suite.dir], [1])
  858. AT_CHECK([test -d sub1/micro-suite.dir], [0])
  859. AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --clean])
  860. AT_CHECK([test -f sub1/micro-suite.log], [1])
  861. AT_CHECK([test -d sub1/micro-suite.dir], [1])
  862. dnl check specifying an absolute path to run in.
  863. AT_CHECK([$CONFIG_SHELL ./micro-suite --directory="`pwd`/sub2"],
  864. [0], [ignore], [])
  865. AT_CHECK([test -f micro-suite.log], [1])
  866. AT_CHECK([test -f sub2/micro-suite.log], [0])
  867. AT_CHECK([$CONFIG_SHELL ./micro-suite --clean --directory="`pwd`/sub2"])
  868. AT_CHECK([test -f sub2/micro-suite.log], [1])
  869. AT_CHECK([test -f sub2/micro-suite.dir], [1])
  870. dnl check for failure detection with bad, missing, or empty directory.
  871. AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch || exit 1], [1], [ignore], [ignore])
  872. AT_CHECK([$CONFIG_SHELL ./micro-suite -C ''], [1], [ignore], [ignore])
  873. AT_CHECK([$CONFIG_SHELL ./micro-suite -C - || exit 1], [1], [ignore], [ignore])
  874. AT_CHECK([$CONFIG_SHELL ./micro-suite -C], [1], [ignore], [ignore])
  875. dnl check that --help overrides bad directory selection.
  876. AT_CHECK([$CONFIG_SHELL ./micro-suite -C nonesuch --help], [0], [ignore], [])
  877. ])
  878. # --recheck.
  879. AT_CHECK_AT_TEST([recheck],
  880. [AT_CHECK([:])
  881. AT_CLEANUP
  882. AT_SETUP([failing test])
  883. AT_CHECK([exit 1])
  884. AT_CLEANUP
  885. AT_SETUP([xpassing test])
  886. AT_XFAIL_IF([:])
  887. AT_CHECK([:])
  888. AT_CLEANUP
  889. AT_SETUP([xfailing test])
  890. AT_XFAIL_IF([:])
  891. AT_CHECK([exit 1])
  892. ], [], [], [], [], [], [
  893. AT_CHECK([$CONFIG_SHELL ./micro-suite --recheck], [0], [stdout])
  894. AT_CHECK([grep "0 tests were successful" stdout], [0], [ignore])
  895. AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [ignore], [ignore])
  896. AT_CHECK([grep 'only test' micro-suite.log], [0], [ignore])
  897. AT_CHECK([$CONFIG_SHELL ./micro-suite --recheck], [1], [ignore], [ignore])
  898. AT_CHECK([grep 'only test' micro-suite.log], [1])
  899. AT_CHECK([grep 'xfailing' micro-suite.log], [1])
  900. AT_CHECK([grep 'failing test' micro-suite.log], [0], [ignore])
  901. AT_CHECK([grep 'xpassing test' micro-suite.log], [0], [ignore])
  902. AT_CHECK([$CONFIG_SHELL ./micro-suite --clean], [0])
  903. AT_CHECK([test -f micro-suite.log], [1])
  904. dnl check specifying a different relative path to run in.
  905. AT_CHECK([mkdir sub1])
  906. AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1], [1], [ignore], [ignore])
  907. AT_CHECK([test -f micro-suite.log], [1])
  908. AT_CHECK([test -f sub1/micro-suite.log], [0])
  909. AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --recheck --list], [0], [stdout])
  910. AT_CHECK([grep 'only test' stdout], [1])
  911. AT_CHECK([grep 'xfailing test' stdout], [1])
  912. AT_CHECK([grep 'failing test' stdout], [0], [ignore])
  913. AT_CHECK([grep 'xpassing test' stdout], [0], [ignore])
  914. AT_CHECK([$CONFIG_SHELL ./micro-suite -C sub1 --recheck], [1], [ignore],
  915. [ignore])
  916. AT_CHECK([grep 'failing test' sub1/micro-suite.log], [0], [ignore])
  917. AT_CHECK([grep 'xpassing test' sub1/micro-suite.log], [0], [ignore])
  918. ], [1 4])
  919. ## -------- ##
  920. ## Banners. ##
  921. ## -------- ##
  922. AT_SETUP([Banners])
  923. AT_CHECK_AT_PREP([b],
  924. [[AT_INIT
  925. AT_SETUP(zero)# 1
  926. AT_CHECK(:)
  927. AT_CLEANUP
  928. AT_BANNER([first])
  929. AT_SETUP(one a)# 2
  930. AT_CHECK(:)
  931. AT_CLEANUP
  932. AT_SETUP(one b)# 3
  933. AT_CHECK(:)
  934. AT_CLEANUP
  935. AT_BANNER()
  936. AT_SETUP(two a)# 4
  937. AT_CHECK(:)
  938. AT_CLEANUP
  939. AT_SETUP(two b)# 5
  940. AT_CHECK(:)
  941. AT_CLEANUP
  942. AT_BANNER([second])
  943. AT_SETUP(three a)# 6
  944. AT_CHECK(:)
  945. AT_CLEANUP
  946. AT_SETUP(three b)# 7
  947. AT_CHECK(:)
  948. AT_CLEANUP
  949. ]])
  950. # AT_CHECK_BANNERS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
  951. m4_define([AT_CHECK_BANNERS],
  952. [AT_CHECK([$CONFIG_SHELL ./b $1], [], [stdout])
  953. AT_CHECK_EGREP([$2], m4_if([$3], [0], [1], [0]), [$3])
  954. AT_CHECK_EGREP([$4], m4_if([$5], [0], [1], [0]), [$5])
  955. ])
  956. AT_CHECK_BANNERS([], [first], [1], [second], [1])
  957. AT_CHECK_BANNERS([-k zero], [first], [0], [second], [0])
  958. AT_CHECK_BANNERS([1], [first], [0], [second], [0])
  959. AT_CHECK_BANNERS([-2], [first], [1], [second], [0])
  960. AT_CHECK_BANNERS([-3], [first], [1], [second], [0])
  961. AT_CHECK_BANNERS([-k one], [first], [1], [second], [0])
  962. AT_CHECK_BANNERS([3-4], [first], [1], [second], [0])
  963. dnl There should be an empty line separating the first category from the
  964. dnl unnamed one.
  965. AT_CHECK([sed -n '/one b/,/two a/p' stdout | grep '^$'], [0], [ignore])
  966. AT_CHECK_BANNERS([3-6], [first], [1], [second], [1])
  967. AT_CHECK_BANNERS([4-6], [first], [0], [second], [1])
  968. AT_CHECK_BANNERS([3-], [first], [1], [second], [1])
  969. AT_CHECK_BANNERS([-k a], [first], [1], [second], [1])
  970. AT_CHECK_BANNERS([4], [first], [0], [second], [0])
  971. AT_CHECK_BANNERS([4-], [first], [0], [second], [1])
  972. AT_CHECK_BANNERS([-k two], [first], [0], [second], [0])
  973. AT_CHECK_BANNERS([1 4], [first], [0], [second], [0])
  974. AT_CHECK_BANNERS([-k three], [first], [0], [second], [1])
  975. AT_CHECK_BANNERS([5], [first], [0], [second], [0])
  976. AT_CHECK_BANNERS([5-], [first], [0], [second], [1])
  977. AT_CLEANUP
  978. ## --------- ##
  979. ## Keywords. ##
  980. ## --------- ##
  981. AT_SETUP([Keywords and ranges])
  982. AT_CHECK_AT_PREP([k],
  983. [[AT_INIT
  984. AT_SETUP(none) # 01
  985. AT_CHECK(:)
  986. AT_CLEANUP
  987. AT_SETUP(first) # 02
  988. AT_KEYWORDS(key1)
  989. AT_CHECK(:)
  990. AT_CLEANUP
  991. AT_SETUP(second) # 03
  992. AT_KEYWORDS(key2)
  993. AT_CHECK(:)
  994. AT_CLEANUP
  995. AT_SETUP(both) # 04
  996. AT_KEYWORDS([key1 key2])
  997. AT_KEYWORDS([m4_echo([Key1])])
  998. AT_CHECK(:)
  999. AT_CLEANUP
  1000. AT_SETUP(test5) # 05
  1001. AT_CHECK(:)
  1002. AT_CLEANUP
  1003. AT_SETUP(test6) # 06
  1004. AT_CHECK(:)
  1005. AT_CLEANUP
  1006. AT_SETUP(test7) # 07
  1007. AT_CHECK(:)
  1008. AT_CLEANUP
  1009. AT_SETUP(test8) # 08
  1010. AT_CHECK(:)
  1011. AT_CLEANUP
  1012. AT_SETUP(test9) # 09
  1013. AT_CHECK(:)
  1014. AT_CLEANUP
  1015. AT_SETUP(test10) # 10
  1016. AT_CHECK(:)
  1017. AT_CLEANUP
  1018. ]])
  1019. dnl check that AT_KEYWORDS does not duplicate words
  1020. AT_CHECK([grep -i 'key1.*key1' k], [1])
  1021. dnl check that -k requires an argument
  1022. AT_CHECK([$CONFIG_SHELL ./k -k], [1], [], [ignore])
  1023. # AT_CHECK_KEYS(TESTSUITE-OPTIONS, PATTERN1, COUNT1, PATTERN2, COUNT2)
  1024. m4_define([AT_CHECK_KEYS],
  1025. [AT_CHECK([$CONFIG_SHELL ./k $1], 0, [stdout])
  1026. AT_CHECK_EGREP([$2], 0, [$3])
  1027. AT_CHECK_EGREP([$4], 1, [$5])
  1028. ])
  1029. AT_CHECK_KEYS([-k key1], [first|both], [2], [none|second], [0])
  1030. AT_CHECK_KEYS([-k key2], [second|both], [2], [none|first], [0])
  1031. AT_CHECK_KEYS([-k key1,key2], [both], [1], [none|first|second], [0])
  1032. AT_CHECK_KEYS([-k key1 -k key2], [first|second|both], [3], [none], [0])
  1033. AT_CHECK_KEYS([-k '!key1'], [none|second], [2], [first|both], [0])
  1034. AT_CHECK_KEYS([-k '!key2'], [none|first], [2], [second|both], [0])
  1035. AT_CHECK_KEYS([-k '!key1,key2'], [second], [1], [none|first|both], [0])
  1036. AT_CHECK_KEYS([-k 'key1,!key2'], [first], [1], [none|second|both], [0])
  1037. AT_CHECK_KEYS([-k '!key1,!key2'], [none], [1], [first|second|both], [0])
  1038. AT_CHECK_KEYS([-k '!key1' -k KEY2], [none|second|both], [3], [first], [0])
  1039. AT_CHECK_KEYS([-k key1 -k '!key2'], [none|first|both], [3], [second], [0])
  1040. AT_CHECK_KEYS([-k '!KEY1' -k '!key2'], [none|first|second], [3], [both], [0])
  1041. AT_CHECK_KEYS([-k none], [none], [1], [first|second|both], [0])
  1042. AT_CHECK_KEYS([-k key1,both], [both], [1], [none|first|second], [0])
  1043. AT_CHECK_KEYS([-k key1 -k both], [first|both], [2], [none|second], [0])
  1044. AT_CHECK_KEYS([-k none,first], [successful], [1], [none|first|second|both], [0])
  1045. AT_CHECK_KEYS([-k none,first,second,both], [successful], [1], [none|first|second|both], [0])
  1046. AT_CHECK_KEYS([-k !none,first], [first], [1], [none|second|both], [0])
  1047. AT_CHECK_KEYS([-k '.*eco.*'], [second], [1], [none|first|both], [0])
  1048. AT_CHECK_KEYS([-k 'ECO'], [successful], [1], [none|first|second|both], [0])
  1049. AT_CHECK_KEYS([-k '.*eco'], [successful], [1], [none|first|second|both], [0])
  1050. AT_CHECK_KEYS([-k 'eco.*'], [successful], [1], [none|first|second|both], [0])
  1051. AT_CHECK_KEYS([-k 'fir.*'], [first], [1], [none|second|both], [0])
  1052. AT_CHECK_KEYS([1-2], [none|first], [2], [second|both], [0])
  1053. AT_CHECK_KEYS([01-002 08], [none|first], [2], [second|both], [0])
  1054. AT_CHECK_KEYS([1-3 2-1], [none|first|second], [3], [both], [0])
  1055. AT_CHECK_KEYS([-3], [none|first|second], [3], [both], [0])
  1056. AT_CHECK_KEYS([4-], [both], [1], [none|first|second], [0])
  1057. AT_CHECK_KEYS([010], [test10], [1], [none|first|second|both], [0])
  1058. AT_CHECK_KEYS([-k second 4-], [second|both], [2], [none|first], [0])
  1059. AT_CHECK([$CONFIG_SHELL ./k 0], [1], [ignore], [ignore])
  1060. AT_CHECK([$CONFIG_SHELL ./k 0-], [1], [ignore], [ignore])
  1061. AT_CHECK([$CONFIG_SHELL ./k -0], [1], [ignore], [ignore])
  1062. AT_CHECK([$CONFIG_SHELL ./k 11], [1], [ignore], [ignore])
  1063. AT_CHECK([$CONFIG_SHELL ./k 11-], [1], [ignore], [ignore])
  1064. AT_CHECK([$CONFIG_SHELL ./k 1-011], [1], [ignore], [ignore])
  1065. AT_CHECK([$CONFIG_SHELL ./k -k nonexistent], [0], [ignore])
  1066. AT_CHECK_KEYS([--list -k nonexistent], [KEYWORDS], [1], [first|second|both], [0])
  1067. AT_CHECK_KEYS([--list 1], [none], [1], [first|second|both], [0])
  1068. AT_CHECK_KEYS([--list 01], [none], [1], [first|second|both], [0])
  1069. AT_CHECK_KEYS([--list -k none -k first], [none|first], [2], [second|both], [0])
  1070. AT_CLEANUP
  1071. ## ----------------- ##
  1072. ## Keyword wrapping. ##
  1073. ## ----------------- ##
  1074. AT_SETUP([Keyword wrapping])
  1075. AT_CHECK_AT_PREP([k],
  1076. [[AT_INIT
  1077. AT_SETUP([test])
  1078. AT_KEYWORDS([a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 k1 l1 m1 n1 o1 p1 q1 r1 s1 t1])
  1079. AT_KEYWORDS([u1 v1 w1 x1 y1 z1])
  1080. AT_KEYWORDS([a b c d e f g h i j k l m n o p q r s t u v w x y z])
  1081. AT_CLEANUP
  1082. AT_SETUP([test with long keywords])
  1083. AT_KEYWORDS(
  1084. [this-is-a-long-keyword-that-cannot-be-wrapped-so-we-exceed-the-length-limit-here])
  1085. # surrounded by short ones
  1086. AT_KEYWORDS([s])
  1087. AT_KEYWORDS(
  1088. [another-very-long-keyword-that-hits-the-line-length-limit-bla-bla-bla-bla])
  1089. AT_KEYWORDS([t])
  1090. AT_CLEANUP
  1091. ]])
  1092. AT_CHECK_KEYS([-l], [.{80}], [1], [.{87}], [0])
  1093. AT_CLEANUP
  1094. ## ------------- ##
  1095. ## AT_ARG_OPTION ##
  1096. ## ------------- ##
  1097. AT_CHECK_AT([AT@&t@_ARG_OPTION],
  1098. [[
  1099. AT_INIT([artificial test suite])
  1100. AT_ARG_OPTION([frob fro fr f],
  1101. [AS_HELP_STRING([-f, --frob], [frobnicate the test run])],
  1102. [frob=$at_optarg], [frob=default])
  1103. AT_ARG_OPTION([opt-with-hyphen],
  1104. [AS_HELP_STRING([--opt-with-hyphen], [option name with hypen])])
  1105. AT_ARG_OPTION([ping],
  1106. [AS_HELP_STRING([--ping], [ping on every encounter])],
  1107. [echo ping])
  1108. AT_SETUP([test argument handling])
  1109. AT_CHECK([test "$frob" = "$FROB"])
  1110. AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"])
  1111. AT_CLEANUP
  1112. AT_SETUP([test hyphen normalization])
  1113. AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"])
  1114. AT_CLEANUP
  1115. ]],
  1116. [], [], [stdout], [], [],
  1117. [# We already invoked --help.
  1118. AT_CHECK([grep ' -f, --frob.*frobnicate' stdout], [], [ignore])
  1119. for args in \
  1120. '1 FROB=default FROB_ARG=false' \
  1121. '1 -f FROB=: FROB_ARG=:' \
  1122. '1 --fr FROB=: FROB_ARG=:' \
  1123. '1 --fro FROB=: FROB_ARG=:' \
  1124. '1 --frob FROB=: FROB_ARG=:' \
  1125. '1 --no-f FROB=false FROB_ARG=false' \
  1126. '1 --no-fr FROB=false FROB_ARG=false' \
  1127. '1 --no-fro FROB=false FROB_ARG=false' \
  1128. '1 --no-frob FROB=false FROB_ARG=false' \
  1129. '2 expected=false' \
  1130. '2 --opt-with-hyphen expected=:' \
  1131. '2 --no-opt-with-hyphen expected=false'
  1132. do
  1133. AT_CHECK([$CONFIG_SHELL ./micro-suite -x $args], [], [ignore])
  1134. done
  1135. AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping --no-ping --ping expected=false],
  1136. [], [stdout])
  1137. AT_CHECK([grep -c ping stdout], [], [[3
  1138. ]])
  1139. ], [--help])
  1140. ## ----------------- ##
  1141. ## AT_ARG_OPTION_ARG ##
  1142. ## ----------------- ##
  1143. AT_CHECK_AT([AT@&t@_ARG_OPTION_ARG],
  1144. [[
  1145. AT_INIT([artificial test suite])
  1146. AT_ARG_OPTION_ARG([frob fro fr f],
  1147. [AS_HELP_STRING([-f, --frob=FOO], [frobnicate FOO])],
  1148. [frob=$at_optarg], [frob=default])
  1149. AT_ARG_OPTION_ARG([opt-with-hyphen],
  1150. [AS_HELP_STRING([--opt-with-hyphen=ARG],
  1151. [option name with hypen])])
  1152. AT_ARG_OPTION_ARG([ping],
  1153. [AS_HELP_STRING([--ping], [ping on every encounter])],
  1154. [echo ping])
  1155. AT_SETUP([test argument handling])
  1156. AT_CHECK([test "$frob" = "$FROB"])
  1157. AT_CHECK([test "$at_arg_frob" = "$FROB_ARG"])
  1158. AT_CLEANUP
  1159. AT_SETUP([test hyphen normalization])
  1160. AT_CHECK([test "$at_arg_opt_with_hyphen" = "$expected"])
  1161. AT_CLEANUP
  1162. ]],
  1163. [], [], [stdout], [], [],
  1164. [# We already invoked --help.
  1165. AT_CHECK([grep ' -f, --frob.*frobnicate' stdout], [], [ignore])
  1166. AT_CHECK([$CONFIG_SHELL ./micro-suite -x --frob], [1], [ignore], [stderr])
  1167. AT_CHECK([grep 'requires an argument' stderr], [], [ignore])
  1168. AT_CHECK([$CONFIG_SHELL ./micro-suite -x --no-frob], [1], [ignore], [stderr])
  1169. AT_CHECK([grep 'invalid option' stderr], [], [ignore])
  1170. for args in \
  1171. '1 FROB=default FROB_ARG=' \
  1172. '1 -f bar FROB=bar FROB_ARG=bar' \
  1173. '1 --fr bar FROB=bar FROB_ARG=bar' \
  1174. '1 --fro bar FROB=bar FROB_ARG=bar' \
  1175. '1 --frob bar FROB=bar FROB_ARG=bar' \
  1176. '1 -f=bar FROB=bar FROB_ARG=bar' \
  1177. '1 --fr=bar FROB=bar FROB_ARG=bar' \
  1178. '1 --fro=bar FROB=bar FROB_ARG=bar' \
  1179. '1 --frob=bar FROB=bar FROB_ARG=bar' \
  1180. '2 expected=' \
  1181. '2 --opt-with-hyphen=baz expected=baz'
  1182. do
  1183. AT_CHECK([$CONFIG_SHELL ./micro-suite -x $args], [], [ignore])
  1184. done
  1185. AT_CHECK([$CONFIG_SHELL ./micro-suite 2 --ping=1 --ping=2 expected=],
  1186. [], [stdout])
  1187. AT_CHECK([grep -c ping stdout], [], [[2
  1188. ]])
  1189. ], [--help])
  1190. m4_define([AT_SKIP_PARALLEL_TESTS],
  1191. [# Per BUGS, we have not yet figured out how to run parallel tests cleanly
  1192. # under dash and some ksh variants. For now, only run this test under
  1193. # limited conditions; help is appreciated in widening this test base.
  1194. AT_SKIP_IF([${CONFIG_SHELL-$SHELL} -c 'test -z "${BASH_VERSION+set}]]dnl
  1195. [[${ZSH_VERSION+set}${TEST_PARALLEL_AUTOTEST+set}"'])
  1196. # The parallel scheduler requires mkfifo and job control to work.
  1197. AT_CHECK([mkfifo fifo || exit 77])
  1198. AT_CHECK([${CONFIG_SHELL-$SHELL} -c '(set -m && set +m) || exit 77'],
  1199. [], [], [ignore])
  1200. ])
  1201. ## ----------------------- ##
  1202. ## parallel test execution ##
  1203. ## ----------------------- ##
  1204. AT_SETUP([parallel test execution])
  1205. # This test tries to ensure that -j runs tests in parallel.
  1206. # Such a test is inherently racy, because there are no real-time
  1207. # guarantees about scheduling delays. So we try to minimize
  1208. # the chance to lose the race.
  1209. # The time needed for a micro-suite consisting of NTESTS tests each
  1210. # sleeping for a second is estimated by
  1211. # startup + ntests * (serial_overhead + 1 / njobs)
  1212. #
  1213. # in absence of major scheduling delays. This leads to side conditions:
  1214. # - NTESTS should be high, so the STARTUP time is small compared to the
  1215. # test run time, and scheduling delays can even out; it should not be
  1216. # too high, to not slow down the testsuite unnecessarily,
  1217. # - the number of concurrent jobs NJOBS should not be too low, so the
  1218. # race is not lost so easily; it should not be too high, to avoid fork
  1219. # failures on tightly limited systems. 4 seems a good compromise
  1220. # here, considering that Autotest spawns several other processes.
  1221. # - STARTUP is assumed to be the same for parallel and serial runs, so
  1222. # the latter can estimate the former.
  1223. # - To avoid unportable output from time measurement commands, spawn
  1224. # both a parallel and a serial testsuite run; check that the former
  1225. # completes before the latter has completed a fraction SERIAL_NTESTS
  1226. # of the tests (the serial run is executed in a subdirectory), plus
  1227. # some additional time to allow for compensation of SERIAL_OVERHEAD.
  1228. # - when adding this time to the serial test execution, an initial delay
  1229. # SERIAL_DELAY of the serial test helps to avoid unreliable scheduling
  1230. # due to the startup burst of the suites.
  1231. dnl total number of tests.
  1232. m4_define([AT_PARALLEL_NTESTS], [16])
  1233. dnl number of jobs to run in parallel.
  1234. m4_define([AT_PARALLEL_NJOBS], [4])
  1235. dnl number of tests to run serially, as comparison.
  1236. m4_define([AT_PARALLEL_SERIAL_NTESTS],
  1237. m4_eval(AT_PARALLEL_NTESTS / AT_PARALLEL_NJOBS))
  1238. dnl initial delay of serial run, to compensate for SERIAL_OVERHEAD.
  1239. dnl This corresponds to 0.67 s of overhead per test.
  1240. m4_define([AT_PARALLEL_SERIAL_DELAY],
  1241. m4_eval((AT_PARALLEL_NTESTS - AT_PARALLEL_SERIAL_NTESTS + 1) * 2 / 3))
  1242. AT_CHECK_AT_PREP([micro-suite],
  1243. [[AT_INIT([suite to test parallel execution])
  1244. m4_for([count], [1], ]]AT_PARALLEL_NTESTS[[, [],
  1245. [AT_SETUP([test number count])
  1246. AT_CHECK([sleep 1])
  1247. AT_CLEANUP
  1248. ])
  1249. ]])
  1250. # Even if parallel jobs are not supported, the command line must work.
  1251. AT_CHECK([$CONFIG_SHELL ./micro-suite --help | grep " --jobs"], [0], [ignore])
  1252. AT_CHECK([$CONFIG_SHELL ./micro-suite -j2foo], [1], [], [stderr])
  1253. AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
  1254. AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=foo], [1], [], [stderr])
  1255. AT_CHECK([grep 'non-numeric argument' stderr], [], [ignore])
  1256. AT_SKIP_PARALLEL_TESTS
  1257. # Ensure that all tests run, and lines are not split.
  1258. AT_CHECK([$CONFIG_SHELL ./micro-suite -j[]AT_PARALLEL_NJOBS], [], [stdout])
  1259. AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
  1260. ])
  1261. # Running one test with -j should produce correctly formatted output:
  1262. AT_CHECK([$CONFIG_SHELL ./micro-suite -j 3], [], [stdout])
  1263. AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
  1264. ])
  1265. # Specifying more jobs than tests should not hang:
  1266. AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 3], [], [stdout])
  1267. AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [1
  1268. ])
  1269. # Not even with zero tests:
  1270. AT_CHECK([$CONFIG_SHELL ./micro-suite -j -k nomatch], [], [ignore])
  1271. AT_CHECK([$CONFIG_SHELL ./micro-suite -j3 -k nomatch], [], [ignore])
  1272. mkdir serial
  1273. # Unfortunately, the return value of wait is unreliable,
  1274. # so we check that kill fails.
  1275. AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=[]AT_PARALLEL_NJOBS & ]dnl
  1276. [sleep AT_PARALLEL_SERIAL_DELAY && ]dnl
  1277. [cd serial && $CONFIG_SHELL ../micro-suite -AT_PARALLEL_SERIAL_NTESTS >/dev/null && ]dnl
  1278. [{ kill $! && exit 1; :; }], [], [stdout], [ignore])
  1279. AT_CHECK([grep -c '^.\{53\}ok' stdout], [], [AT_PARALLEL_NTESTS
  1280. ])
  1281. AT_CHECK([grep 'AT_PARALLEL_NTESTS tests' stdout], [], [ignore])
  1282. AT_CLEANUP
  1283. AT_CHECK_AT_TEST([parallel truth],
  1284. [AT_CHECK([:], 0, [], [])],
  1285. [], [], [], [], [AT_SKIP_PARALLEL_TESTS],
  1286. [], [-j])
  1287. AT_CHECK_AT_TEST([parallel fallacy],
  1288. [AT_CHECK([false], [], [], [])],
  1289. [], [1], [], [ignore], [AT_SKIP_PARALLEL_TESTS],
  1290. [AT_CHECK([grep failed micro-suite.log], [], [ignore])], [-j])
  1291. AT_CHECK_AT_TEST([parallel skip],
  1292. [AT_CHECK([echo output; echo irrelevant >&2; exit 77], 0, [mismatch], [])],
  1293. [], [], [], [], [AT_SKIP_PARALLEL_TESTS],
  1294. [AT_CHECK([grep skipped micro-suite.log], [], [ignore])], [-j])
  1295. AT_CHECK_AT_TEST([parallel syntax error],
  1296. [AT_CHECK([:])
  1297. AT_CLEANUP
  1298. AT_SETUP([syntax])
  1299. AT_CHECK([if])
  1300. AT_CLEANUP
  1301. AT_SETUP([another test])
  1302. AT_CHECK([:])],
  1303. [], [0], [], [], [AT_SKIP_PARALLEL_TESTS],
  1304. [dnl Until we can find a way to avoid catastrophic failure (ash) or
  1305. dnl lack of failure (zsh), skip the rest of this test on such shells.
  1306. echo 'if' > syntax
  1307. AT_CHECK([${CONFIG_SHELL-$SHELL} -c 'case `. ./syntax; echo $?` in
  1308. 0|"") exit 77;;
  1309. esac'], [0], [ignore], [ignore])
  1310. AT_CHECK([$CONFIG_SHELL ./micro-suite -j], [1], [ignore], [stderr])
  1311. AT_CHECK([grep "unable to parse test group: 2" stderr], [0], [ignore])],
  1312. [-j2 1 3])
  1313. AT_CHECK_AT_TEST([parallel errexit],
  1314. [AT_CHECK([false])
  1315. AT_CLEANUP
  1316. AT_SETUP([barrier test])
  1317. AT_CHECK([sleep 4])
  1318. AT_CLEANUP
  1319. AT_SETUP([test that should not be run])
  1320. AT_CHECK([:])],
  1321. [], [1], [stdout], [stderr], [AT_SKIP_PARALLEL_TESTS],
  1322. [AT_CHECK([test -f micro-suite.log], [1])
  1323. touch micro-suite.log # shut up AT_CAPTURE_FILE.
  1324. AT_CHECK([grep "should not be run" stdout], [1])
  1325. AT_CHECK([grep "[[12]] .* inhibited subsequent" stderr], [], [ignore])],
  1326. [-j2 --errexit])
  1327. AT_SETUP([parallel autotest and signal handling])
  1328. AT_SKIP_PARALLEL_TESTS
  1329. # Goals:
  1330. # (1) interrupt `./testsuite -jN'
  1331. # (2) interrupt `make check TESTSUITEFLAGS=-jN'
  1332. # (3) no trailing verbose/trace output
  1333. # (4) exit status should be 128+signal
  1334. AT_DATA([atlocal],
  1335. [[suite_pid=$$
  1336. export suite_pid
  1337. ]])
  1338. AT_CHECK_AT_PREP([micro-suite],
  1339. [[AT_INIT([suite to test parallel execution])
  1340. AT_SETUP([test number 1])
  1341. AT_CHECK([sleep 2])
  1342. AT_CLEANUP
  1343. AT_SETUP([test number 2])
  1344. AT_CHECK([sleep 1])
  1345. AT_CLEANUP
  1346. AT_SETUP([test number 3])
  1347. AT_CHECK([sleep 1])
  1348. AT_CLEANUP
  1349. AT_SETUP([killer test])
  1350. AT_CHECK([kill -$signal $suite_pid])
  1351. AT_CLEANUP
  1352. m4_for([count], [5], [7], [],
  1353. [AT_SETUP([test number count])
  1354. AT_CHECK([sleep 1])
  1355. AT_CLEANUP
  1356. ])
  1357. ]])
  1358. AT_DATA([Makefile.in],
  1359. [[@SET_MAKE@
  1360. SHELL = @SHELL@
  1361. TESTSUITE = ./micro-suite
  1362. check:
  1363. $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
  1364. .PHONY: check
  1365. ]])
  1366. AT_CHECK([$CONFIG_SHELL $abs_top_builddir/config.status --file=Makefile:Makefile.in],
  1367. [], [ignore])
  1368. # Test INT and TERM.
  1369. for signal in 2 15; do
  1370. export signal
  1371. AS_VAR_ARITH([expected_status], [128 + $signal])
  1372. # Sequential case.
  1373. AT_CHECK([$CONFIG_SHELL ./micro-suite], [$expected_status],
  1374. [ignore], [stderr])
  1375. # Both stderr and the log should contain the notification about the signal.
  1376. AT_CHECK([grep 'bailing out' stderr], [], [ignore])
  1377. AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
  1378. # There should be no junk job status output.
  1379. AT_CHECK([[grep '[iI]nterrupt[ ]' stderr]], [1])
  1380. # Parallel case.
  1381. AT_CHECK([$CONFIG_SHELL ./micro-suite --jobs=3], [$expected_status],
  1382. [ignore], [stderr])
  1383. AT_CHECK([grep 'bailing out' stderr], [], [ignore])
  1384. AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
  1385. # We'd like to check this here, too, but some shells do not allow to
  1386. # turn off job control.
  1387. # AT_CHECK([[grep '[iI]nterrupt[ ]' stderr]], [1])
  1388. # Ditto with `make' in the loop.
  1389. : "${MAKE=make}"
  1390. unset MAKEFLAGS
  1391. # Need to eliminate outer TESTSUITEFLAGS here.
  1392. # Need to normalize exit status here: some make implementations
  1393. # exit 1 (BSD make), some exit 2 (GNU make).
  1394. AT_CHECK([$MAKE check TESTSUITEFLAGS=; ]dnl
  1395. [case $? in 1|2) exit 1;; *) exit $?;; esac],
  1396. [1], [ignore], [stderr])
  1397. AT_CHECK([grep 'bailing out' stderr], [], [ignore])
  1398. AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
  1399. # Ditto, parallel case.
  1400. AT_CHECK([$MAKE check TESTSUITEFLAGS=--jobs=3; ]dnl
  1401. [case $? in 1|2) exit 1;; *) exit $?;; esac],
  1402. [1], [ignore], [stderr])
  1403. AT_CHECK([grep 'bailing out' stderr], [], [ignore])
  1404. AT_CHECK([grep 'bailing out' micro-suite.log], [], [ignore])
  1405. done
  1406. # Test PIPE.
  1407. # The most important part here is that things should not hang, nor
  1408. # get out of hand. OTOH, if the shell sets the default handler to
  1409. # ignore PIPE (pdksh, dash), there is little we can do about having the
  1410. # test run; it's only the output that won't be there. So all we check
  1411. # for is that, if test 7 didn't run serially, then it shouldn't be
  1412. # run in the parallel case either; the intermediate tests serve as
  1413. # parallel barrier.
  1414. # Note that stderr may contain "Broken pipe" errors.
  1415. AT_CHECK([($CONFIG_SHELL ./micro-suite -d -3 5-; echo $? >status) | sed 5q],
  1416. [], [stdout], [stderr])
  1417. AT_CHECK([grep '5.*ok' stdout], [1])
  1418. # Apparently some shells don't get around to creating 'status' any more.
  1419. # And ksh93 on FreeBSD uses 256 + 13 instead of 128 + 13
  1420. AT_CHECK([test ! -s status || grep 141 status || grep 269 status],
  1421. [], [ignore])
  1422. AT_CHECK([if test -f micro-suite.dir/7/micro-suite.log; then ]dnl
  1423. [ echo "shell ignores SIGPIPE" > sigpipe-stamp ]dnl
  1424. [else :; fi])
  1425. AT_CHECK([$CONFIG_SHELL ./micro-suite -d -3 5- --jobs=2 | sed 5q], [], [stdout], [ignore])
  1426. AT_CHECK([grep '5.*ok' stdout], [1])
  1427. AT_CHECK([test -s sigpipe-stamp || test ! -f micro-suite.dir/7/micro-suite.log], [0])
  1428. AT_CLEANUP
  1429. # Avoid running into a regression when mkfifo does not work.
  1430. AT_CHECK_AT_TEST([parallel args but non-working mkfifo],
  1431. [AT_CHECK([:])
  1432. AT_CLEANUP
  1433. AT_SETUP([second test])
  1434. AT_CHECK([:])
  1435. ],
  1436. [], [], [stdout], [stderr],
  1437. [AT_SKIP_PARALLEL_TESTS
  1438. mkdir bin
  1439. cat >bin/mkfifo <<\EOF
  1440. #! /bin/sh
  1441. exit 1
  1442. EOF
  1443. chmod +x bin/mkfifo
  1444. PATH=`pwd`/bin:$PATH
  1445. export PATH
  1446. ],
  1447. [AT_CHECK([grep 'second test' stdout], [], [ignore])
  1448. ], [--jobs])
  1449. # --color
  1450. AT_CHECK_AT_TEST([colored test results],
  1451. [AT_CHECK([:])
  1452. AT_CLEANUP
  1453. AT_SETUP([fail])
  1454. AT_CHECK([exit 1])
  1455. AT_CLEANUP
  1456. AT_SETUP([xpass])
  1457. AT_XFAIL_IF([:])
  1458. AT_CHECK([:])
  1459. AT_CLEANUP
  1460. AT_SETUP([xfail])
  1461. AT_XFAIL_IF([:])
  1462. AT_CHECK([exit 1])
  1463. AT_CLEANUP
  1464. AT_SETUP([skip])
  1465. AT_CHECK([exit 77])
  1466. AT_CLEANUP
  1467. AT_SETUP([hardfail])
  1468. AT_XFAIL_IF([:])
  1469. AT_CHECK([exit 99])
  1470. ], [], [], [], [], [], [
  1471. TERM=ansi
  1472. export TERM
  1473. red=`printf '\033@<:@0;31m'`
  1474. grn=`printf '\033@<:@0;32m'`
  1475. lgn=`printf '\033@<:@1;32m'`
  1476. blu=`printf '\033@<:@1;34m'`
  1477. std=`printf '\033@<:@m'`
  1478. # Check that grep can parse nonprinting characters.
  1479. # BSD 'grep' works from a pipe, but not a seekable file.
  1480. # GNU or BSD 'grep -a' works on files, but is not portable.
  1481. AT_CHECK([case `echo "$std" | grep .` in #'' restore font-lock
  1482. $std) :;;
  1483. *) exit 77;;
  1484. esac], [], [ignore], [],
  1485. [echo "grep can't parse nonprinting characters" >&2])
  1486. if echo 'ab*c' | grep -F 'ab*c' >/dev/null 2>&1; then
  1487. FGREP="grep -F"
  1488. else
  1489. FGREP=fgrep
  1490. fi
  1491. # No color.
  1492. AT_CHECK([$CONFIG_SHELL ./micro-suite], [1], [stdout], [stderr])
  1493. for color in "$red" "$grn" "$lgn" "$blu"; do
  1494. AT_CHECK([cat stdout stderr | $FGREP "$color"], [1])
  1495. done
  1496. # Color of test group results.
  1497. AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always], [1], [stdout], [stderr])
  1498. AT_CHECK([cat stdout | grep " only " | $FGREP "$grn"], [], [ignore])
  1499. AT_CHECK([cat stdout | grep " fail " | $FGREP "$red"], [], [ignore])
  1500. AT_CHECK([cat stdout | grep " xfail " | $FGREP "$lgn"], [], [ignore])
  1501. AT_CHECK([cat stdout | grep " xpass " | $FGREP "$red"], [], [ignore])
  1502. AT_CHECK([cat stdout | grep " skip " | $FGREP "$blu"], [], [ignore])
  1503. AT_CHECK([cat stdout | grep " hardfail " | $FGREP "$red"], [], [ignore])
  1504. AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
  1505. # The summary is green if all tests were successful, light green if all
  1506. # behaved as expected, and red otherwise.
  1507. AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always 1 -k skip],
  1508. [0], [stdout])
  1509. AT_CHECK([cat stdout | grep 'test.*successful' | $FGREP "$grn"],
  1510. [], [ignore])
  1511. AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always 1 -k xfail -k skip],
  1512. [0], [stdout])
  1513. AT_CHECK([cat stdout | grep 'as expected' | $FGREP "$lgn"], [], [ignore])
  1514. AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k fail],
  1515. [1], [ignore], [stderr])
  1516. AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
  1517. AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k xpass],
  1518. [1], [ignore], [stderr])
  1519. AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
  1520. AT_CHECK([$CONFIG_SHELL ./micro-suite --color=always -k hardfail],
  1521. [1], [ignore], [stderr])
  1522. AT_CHECK([cat stderr | grep ERROR | $FGREP "$red"], [], [ignore])
  1523. # Reset color on verbose output.
  1524. printf %s\\n "$std"
  1525. ], [1])
  1526. ## ------------------- ##
  1527. ## srcdir propagation. ##
  1528. ## ------------------- ##
  1529. AT_SETUP([srcdir propagation])
  1530. mkdir pkg vpath-outside vpath-abs
  1531. mkdir pkg/t pkg/vpath-inside
  1532. AT_DATA([pkg/a])
  1533. AT_DATA([pkg/t/b])
  1534. AT_DATA([pkg/configure.ac], [[AC_INIT
  1535. AC_CONFIG_TESTDIR([t])
  1536. AC_OUTPUT
  1537. ]])
  1538. cp "$abs_top_srcdir/build-aux/install-sh" pkg
  1539. cd pkg
  1540. AT_CHECK_AUTOCONF
  1541. cd ..
  1542. AT_CHECK_AT_PREP([suite],
  1543. [[AT_INIT([suite to check srcdir])
  1544. AT_SETUP([my only test])
  1545. AT_CHECK([test -f "$top_srcdir"/a && test -f "$srcdir"/b])
  1546. AT_CLEANUP
  1547. ]], [], [], [], [pkg/t])
  1548. rm -f pkg/t/atconfig
  1549. # Build directory totally outside source directory.
  1550. cd vpath-outside
  1551. AT_CHECK([../pkg/configure $configure_options], [0], [ignore])
  1552. cd t
  1553. AT_CHECK([../../pkg/t/suite], [0], [ignore])
  1554. AT_CHECK([../../pkg/t/suite -v], [0], [stdout])
  1555. AT_CHECK([grep '^\.\./\.\./pkg/t/suite.at' stdout], [0], [ignore])
  1556. cd ../..
  1557. # Build directory totally outside source directory (absolute).
  1558. my_srcdir=`pwd`/pkg
  1559. cd vpath-abs
  1560. AT_CHECK(["$my_srcdir"/configure $configure_options], [0], [ignore])
  1561. cd t
  1562. AT_CHECK(["$my_srcdir"/t/suite], [0], [ignore])
  1563. AT_CHECK(["$my_srcdir"/t/suite -v], [0], [stdout])
  1564. AT_CHECK([grep '..*/t/suite.at' stdout], [0], [ignore])
  1565. cd ../..
  1566. # Build directory as subdirectory of source directory.
  1567. cd pkg/vpath-inside
  1568. AT_CHECK([../configure $configure_options], [0], [ignore])
  1569. cd t
  1570. AT_CHECK([../../t/suite], [0], [ignore])
  1571. AT_CHECK([../../t/suite -v], [0], [stdout])
  1572. AT_CHECK([grep '^\.\./\.\./t/suite.at' stdout], [0], [ignore])
  1573. cd ../../..
  1574. # Build directory as parent of source directory.
  1575. AT_CHECK([pkg/configure $configure_options], [0], [ignore])
  1576. cd t
  1577. AT_CHECK([../pkg/t/suite], [0], [ignore])
  1578. AT_CHECK([../pkg/t/suite -v], [0], [stdout])
  1579. AT_CHECK([grep '^\.\./pkg/t/suite.at' stdout], [0], [ignore])
  1580. cd ..
  1581. # Build directory as source directory.
  1582. cd pkg
  1583. AT_CHECK_CONFIGURE
  1584. cd t
  1585. AT_CHECK([./suite], [0], [ignore])
  1586. AT_CHECK([./suite -v], [0], [stdout])
  1587. AT_CHECK([grep '^\./suite.at' stdout], [0], [ignore])
  1588. cd ../..
  1589. AT_CLEANUP
  1590. ## ------------------------------ ##
  1591. ## whitespace in absolute testdir ##
  1592. ## ------------------------------ ##
  1593. AT_SETUP([whitespace in absolute testdir])
  1594. dir='dir with whitespace'
  1595. mkdir "$dir"
  1596. cd "$dir"
  1597. wd=`pwd`
  1598. AT_DATA([a])
  1599. AT_CHECK_AT_PREP([suite],
  1600. [[AT_INIT([suite to check srcdir])
  1601. AT_SETUP([my only test])
  1602. AT_CHECK([test -f "$top_srcdir"/a])
  1603. AT_CLEANUP
  1604. ]])
  1605. AT_CHECK([top_srcdir=$wd ./suite], [0], [ignore])
  1606. AT_CHECK([top_srcdir=$wd ./suite -d], [0], [ignore])
  1607. AT_CHECK([cd suite.dir/1 && ./run top_srcdir="$wd"], [0], [ignore], [ignore])
  1608. AT_CLEANUP
  1609. ## ------------------ ##
  1610. ## unusual file names ##
  1611. ## ------------------ ##
  1612. AT_SETUP([unusual file names])
  1613. AT_DATA_AUTOTEST([d@&t@nl.at],
  1614. [[AT_SETUP([test one])
  1615. m4_pattern_allow([^dnl$])
  1616. AT_CHECK([test "]m4_dquote(AT_LINE)[" = dn[]l.at:3])
  1617. AT_CLEANUP
  1618. ]])
  1619. mkdir sub
  1620. AT_DATA_AUTOTEST([sub/"two spaces".at],
  1621. [[AT_SETUP([test two])
  1622. AT_CHECK([test "]m4_dquote(AT_LINE)[" = "two spaces.at:2"])
  1623. AT_CLEANUP
  1624. ]])
  1625. AT_CHECK_AT_PREP([suite],
  1626. [[AT_INIT([suite to check included file names])
  1627. m4_include([d][nl.at])
  1628. m4_include([sub/two spaces.at])
  1629. ]])
  1630. AT_CHECK([$CONFIG_SHELL ./suite], [0], [stdout])
  1631. AT_CHECK([grep 'two spaces' suite.log], [1])
  1632. AT_CLEANUP
  1633. ## ------------------------- ##
  1634. ## Erlang EUnit unit tests. ##
  1635. ## ------------------------- ##
  1636. AT_SETUP([Erlang Eunit unit tests])
  1637. AT_KEYWORDS([Erlang])
  1638. mkdir s t
  1639. AT_DATA([configure.ac], [[AC_INIT
  1640. AC_ERLANG_PATH_ERL([no])
  1641. AC_ERLANG_PATH_ERLC([no])
  1642. if test "$ERL" = "no" || test "$ERLC" = "no"; then
  1643. HAVE_ERLANG=no
  1644. HAVE_EUNIT=no
  1645. else
  1646. HAVE_ERLANG=yes
  1647. AC_ERLANG_CHECK_LIB([eunit], [HAVE_EUNIT=yes], [HAVE_EUNIT=no])
  1648. fi
  1649. AC_SUBST([HAVE_ERLANG])
  1650. AC_SUBST([HAVE_EUNIT])
  1651. AC_CONFIG_TESTDIR([t])
  1652. AC_CONFIG_FILES([s/compile], [chmod +x s/compile])
  1653. AC_CONFIG_FILES([erlang.conf])
  1654. AC_OUTPUT
  1655. ]])
  1656. # File to pass info back to us
  1657. AT_DATA([erlang.conf.in],
  1658. [[HAVE_ERLANG=@HAVE_ERLANG@
  1659. HAVE_EUNIT=@HAVE_EUNIT@
  1660. ]])
  1661. # Erlang module to test:
  1662. AT_DATA([s/testme.erl],
  1663. [[-module(testme).
  1664. -export([foo/1]).
  1665. foo(1) -> one;
  1666. foo(2) -> two;
  1667. foo(_) -> other.
  1668. ]])
  1669. # Corresponding Eunit unit test module:
  1670. AT_DATA([s/testme_tests.erl],
  1671. [[-module(testme_tests).
  1672. -include_lib("eunit/include/eunit.hrl").
  1673. foo_one_test() -> ?assertEqual(one, testme:foo(1)).
  1674. foo_two_test() -> ?assertEqual(two, testme:foo(2)).
  1675. foo_other_test() -> ?assertEqual(other, testme:foo(42)).
  1676. ]])
  1677. # Compilation script:
  1678. AT_DATA([s/compile.in],
  1679. [["@ERLC@" -b beam testme.erl testme_tests.erl
  1680. ]])
  1681. AT_CHECK_AT_PREP([suite],
  1682. [[AT_INIT([suite to check EUnit integration])
  1683. AT_SETUP([my only test])
  1684. AT_CHECK_EUNIT([my_testsuite], [{module, testme}],
  1685. [-pa "${abs_top_builddir}/s"])
  1686. AT_CLEANUP
  1687. ]], [], [], [], [t])
  1688. AT_CHECK_AUTOCONF
  1689. AT_CHECK_CONFIGURE
  1690. . ./erlang.conf
  1691. AT_CHECK([grep '^ERL='\''.*'\' t/atconfig], [], [ignore])
  1692. AT_CHECK([grep '^ERLC='\''.*'\' t/atconfig], [], [ignore])
  1693. AT_CHECK([grep '^ERLCFLAGS='\''.*'\' t/atconfig], [], [ignore])
  1694. if test "$HAVE_ERLANG" = yes && test "$HAVE_EUNIT" = yes; then
  1695. AT_CHECK([cd s && $CONFIG_SHELL ./compile])
  1696. fi
  1697. AT_CHECK([cd t && $CONFIG_SHELL ./suite], [], [ignore])
  1698. if test "$HAVE_EUNIT" = yes; then
  1699. AT_CHECK([grep 1.*successful t/suite.log], [], [ignore])
  1700. AT_CHECK([grep skipped t/suite.log], [1], [ignore])
  1701. else
  1702. AT_CHECK([grep 1.*skipped t/suite.log], [], [ignore])
  1703. AT_CHECK([grep 0.*successful t/suite.log], [], [ignore])
  1704. fi
  1705. AT_CLEANUP