m4sh.at 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  1. # -*- Autotest -*-
  2. AT_BANNER([M4sh.])
  3. # Copyright (C) 2000-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. ## --------------------------- ##
  18. ## Re-exec with CONFIG_SHELL. ##
  19. ## --------------------------- ##
  20. AT_SETUP([No extra re-exec with CONFIG_SHELL])
  21. AT_KEYWORDS([CONFIG_SHELL])
  22. AT_DATA_M4SH([script.as],
  23. [[
  24. dnl We have to muck with internal details to goad the script into
  25. dnl thinking that the default shell is always good enough.
  26. m4_define([_AS_DETECT_REQUIRED_BODY], [])dnl
  27. m4_define([_AS_DETECT_SUGGESTED_BODY], [])dnl
  28. AS_INIT
  29. echo foo > ok
  30. ]])
  31. AT_CHECK_M4SH
  32. AT_CHECK([CONFIG_SHELL=/bin/false ./script], [0], [], [])
  33. AT_CHECK([test -f ok], [0])
  34. rm -f ok
  35. AT_CLEANUP
  36. AT_SETUP([Forced re-exec with CONFIG_SHELL])
  37. AT_KEYWORDS([CONFIG_SHELL])
  38. AT_DATA_M4SH([script.as],
  39. [[m4_define([_AS_FORCE_REEXEC_WITH_CONFIG_SHELL], [yes])
  40. AS_INIT
  41. echo foo > sentinel
  42. ]])
  43. AT_CHECK_M4SH
  44. # Calling the script simply 'script' could cause problems with
  45. # Solaris /usr/xpg4/bin/sh in the invocation 'sh script' below.
  46. mv -f script script2
  47. AT_DATA([fake-shell],
  48. [[#!/bin/sh
  49. echo 'Fake shell executed.'
  50. shift # fake shell
  51. echo "nargs = @S|@#"
  52. for i
  53. do
  54. printf ' :%s:\n' "$i"
  55. done
  56. ]])
  57. chmod a+x fake-shell
  58. AT_CHECK([CONFIG_SHELL=./fake-shell ./script2 1 2 4 8], [0],
  59. [Fake shell executed.
  60. nargs = 4
  61. :1:
  62. :2:
  63. :4:
  64. :8:
  65. ], [])
  66. AT_CHECK([test ! -f sentinel], [0])
  67. test ! -f sentinel || rm -f sentinel # Cleanup for next test.
  68. AT_CHECK(
  69. [CONFIG_SHELL=`pwd`/fake-shell sh script2 a 'b c' ' d e '],
  70. [0],
  71. [Fake shell executed.
  72. nargs = 3
  73. :a:
  74. :b c:
  75. : d e :
  76. ], [])
  77. AT_CHECK([test ! -f sentinel], [0])
  78. test ! -f sentinel || rm -f sentinel # Cleanup for next test.
  79. AT_CHECK([(PATH=`pwd`:$PATH; export PATH;
  80. CONFIG_SHELL=fake-shell script2 '' '&' '!;*' '<($[]@%:@)>,' 'x
  81. y z
  82. 1 2 3')], [0],
  83. [Fake shell executed.
  84. nargs = 5
  85. ::
  86. :&:
  87. :!;*:
  88. :<($[]@%:@)>,:
  89. :x
  90. y z
  91. 1 2 3:
  92. ], [])
  93. AT_CHECK([test ! -f sentinel], [0])
  94. test ! -f sentinel || rm -f sentinel # Cleanup for next test.
  95. AT_CLEANUP
  96. AT_SETUP([Configure re-execs self with CONFIG_SHELL])
  97. AT_DATA([configure.ac],
  98. [[AC_INIT
  99. echo foobar >> quux
  100. ]])
  101. AT_CHECK_AUTOCONF
  102. AT_DATA([cfg-sh],
  103. [[#!/bin/sh
  104. : > cfg-sh-has-run
  105. exec sh "@S|@@"
  106. ]])
  107. chmod a+x cfg-sh
  108. AT_CAPTURE_FILE([config.log])
  109. # Export CONFIG_SITE to /dev/null to avoid spurious diffs in expected
  110. # stdout/stderr.
  111. AT_CHECK([env CONFIG_SITE=/dev/null CONFIG_SHELL=./cfg-sh ./configure],
  112. [0], [], [])
  113. # ./configure re-executed itself.
  114. AT_CHECK([test -f cfg-sh-has-run], [0])
  115. # And did that not to cause extra execution of later commands.
  116. AT_CHECK([cat quux], [0], [foobar
  117. ], [])
  118. rm -f quux cfg-sh*
  119. AT_CLEANUP
  120. ## ------------------- ##
  121. ## AS_WARN, AS_ERROR. ##
  122. ## ------------------- ##
  123. AT_SETUP([AS@&t@_WARN and AS@&t@_ERROR])
  124. AT_KEYWORDS([m4sh])
  125. dnl without logging
  126. AT_DATA_M4SH([script.as],
  127. [[AS_INIT
  128. AS_WARN([*watch out*])dnl
  129. if test x"$die" != x; then
  130. AS_ERROR([you're dead])dnl
  131. AS_ERROR([really])dnl
  132. fi
  133. echo got here
  134. ]])
  135. AT_CHECK_M4SH
  136. AT_CHECK([$CONFIG_SHELL ./script], [],
  137. [[got here
  138. ]], [[script: WARNING: *watch out*
  139. ]])
  140. AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
  141. [], [[script: WARNING: *watch out*
  142. script: error: you're dead
  143. ]])
  144. dnl with logging
  145. rm script
  146. AT_DATA_M4SH([script.as],
  147. [[AS_INIT
  148. m4_define([gone], [AS_ERROR([really])])
  149. m4_define([AS_MESSAGE_LOG_FD], [5])
  150. exec AS_MESSAGE_LOG_FD>log.txt
  151. AS_WARN([*watch out*])dnl
  152. if test x"$die" != x; then
  153. AS_ERROR([you're dead])dnl
  154. AS_ERROR([really])dnl
  155. fi
  156. echo got here
  157. exec AS_MESSAGE_LOG_FD>&-
  158. ]])
  159. AT_CHECK_M4SH
  160. AT_CHECK([$CONFIG_SHELL ./script], [],
  161. [[got here
  162. ]], [[script: WARNING: *watch out*
  163. ]])
  164. AT_CHECK([[grep 'script:[0-9]*: WARNING: \*watch out\*' log.txt]], [], [ignore])
  165. AT_CHECK([die=: $CONFIG_SHELL ./script], [1],
  166. [], [[script: WARNING: *watch out*
  167. script: error: you're dead
  168. ]])
  169. AT_CHECK([[grep 'script:[0-9]*: WARNING: \*watch out\*' log.txt]], [], [ignore])
  170. AT_CHECK([[grep 'script:[0-9]*: error: you'\''re dead' log.txt]], [], [ignore])
  171. AT_CLEANUP
  172. ## ---------------- ##
  173. ## LINENO support. ##
  174. ## ---------------- ##
  175. AT_SETUP([LINENO])
  176. AT_KEYWORDS([m4sh])
  177. # We cannot unset LINENO with Zsh, yet this test case relies on
  178. # unsetting LINENO to compare its result when (i) LINENO is supported
  179. # and when (ii) it is not.
  180. # So just skip if the shell is ZSH.
  181. AT_CHECK([test -n "${ZSH_VERSION+set}" && exit 77], ignore)
  182. # AT_DATA_LINENO(FILE-NAME,
  183. # UNSET-LINENO = true | false, COUNTER, COUNTER-RE)
  184. # ----------------------------------------------------------------
  185. # Produce the FILE-NAME M4sh script which uses the COUNTER LINENO or
  186. # _oline_, which we can recognized via COUNTER-RE. Unset LINENO is
  187. # UNSET-LINENO.
  188. #
  189. # Use COUNTER, COUNTER-RE = [__LINENO__], [LINENO]
  190. # or = [__OLINE__], [_oline__]
  191. #
  192. # instead of the obvious $LINENO and __oline__, because they would
  193. # be replaced in the test suite itself, even before creating these
  194. # scripts. For the same reason, grep for LINENO and _oline__ (sic).
  195. #
  196. # UNSET-LINENO is a shell condition to make sure the scripts have the
  197. # same number of lines in the output, so that their outputs be identical.
  198. m4_define([AT_DATA_LINENO],
  199. [AT_DATA([$1.tas],
  200. [[AS@&t@_INIT
  201. m4@&t@_divert_text([], [
  202. if $2; then
  203. AS@&t@_UNSET([LINENO])
  204. fi
  205. ])
  206. AS@&t@_LINENO_PREPARE
  207. echo "Line: $3"
  208. grep 'Line: .*$4' "$[0]" >/dev/null ||
  209. AS@&t@_ERROR([cannot find original script])
  210. exit 0
  211. ]])
  212. # If occurrences of $LINENO or __@&t@oline__ were wanted, create them.
  213. sed 's/__LINENO__/$''LINENO/g;s/__OLINE__/__''oline__/g' $1.tas >$1.as
  214. AT_CHECK([autom4te -l m4sh $1.as -o $1])
  215. ])# AT_DATA_LINENO
  216. # `_oline_', once processed and ran, produces our reference.
  217. # We check that we find ourselves by looking at a string which is
  218. # available only in the original script: `_oline_'.
  219. AT_DATA_LINENO([reference], [false], [__OLINE__], [_oline__])
  220. AT_CHECK([./reference], 0, [stdout])
  221. # The reference:
  222. mv stdout expout
  223. # Now using a maybe-functioning LINENO, with different call conventions.
  224. # Be sure to be out of the PATH.
  225. AT_CHECK([mkdir test || exit 77])
  226. AT_DATA_LINENO([test/test-1], [false], [__LINENO__], [LINENO])
  227. AT_CHECK([./test/test-1], 0, [expout])
  228. AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-1)],
  229. 0, [expout])
  230. AT_CHECK([sh ./test/test-1], 0, [expout])
  231. # Now using a disabled LINENO, with different call conventions.
  232. AT_DATA_LINENO([test/test-2], [true], [__LINENO__], [LINENO])
  233. AT_CHECK([./test/test-2], 0, [expout])
  234. AT_CHECK([(PATH=test$PATH_SEPARATOR$PATH; export PATH; exec test-2)],
  235. 0, [expout])
  236. AT_CHECK([sh ./test/test-2], 0, [expout])
  237. AT_CLEANUP
  238. ## ---------------------- ##
  239. ## LINENO stack support. ##
  240. ## ---------------------- ##
  241. AT_SETUP([LINENO stack])
  242. AT_KEYWORDS([m4sh])
  243. AT_DATA_M4SH([script.as],
  244. [[AS_INIT
  245. AS_LINENO_PUSH([9999])
  246. test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
  247. AS_LINENO_PUSH([8888])
  248. test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 2])
  249. AS_LINENO_POP
  250. test $as_lineno = 9999 || AS_ERROR([bad as_lineno at depth 1])
  251. AS_LINENO_POP
  252. test x${as_lineno+set} = xset && AS_ERROR([as_lineno set at depth 0])
  253. AS_EXIT([0])
  254. ]])
  255. AT_CHECK_M4SH
  256. AT_CHECK([$CONFIG_SHELL ./script])
  257. AT_CLEANUP
  258. ## -------- ##
  259. ## AS_BOX. ##
  260. ## -------- ##
  261. # Output a framed one-line message.
  262. AT_SETUP([AS@&t@_BOX])
  263. AT_KEYWORDS([m4sh])
  264. AT_DATA_M4SH([script.as],
  265. [[AS_INIT
  266. echo
  267. AS_BOX([Send a simple message, to foobar@example.com])
  268. AS_BOX([Send a simple message, to foobar@example.com], [$])
  269. m4_define([msg], [$complex])
  270. complex='Not quite as simple |$[1]'
  271. AS_BOX([msg])
  272. AS_BOX([msg], [,])
  273. AS_EXIT(0)
  274. ]])
  275. AT_CHECK_M4SH
  276. AT_CHECK([sed -n '/ -\{44\} /,/ -\{44\} /p' script ]dnl
  277. [| sed '1 s/.*## -/## -/; 3 s/- ##.*/- ##/'], [],
  278. [[## -------------------------------------------- ##
  279. ## Send a simple message, to foobar@example.com ##
  280. ## -------------------------------------------- ##
  281. ]])
  282. AT_CHECK([$CONFIG_SHELL ./script], [], [[
  283. ## -------------------------------------------- ##
  284. ## Send a simple message, to foobar@example.com ##
  285. ## -------------------------------------------- ##
  286. ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
  287. ## Send a simple message, to foobar@example.com ##
  288. ## $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ ##
  289. ## ----------------------- ##
  290. ## Not quite as simple |$1 ##
  291. ## ----------------------- ##
  292. ## ,,,,,,,,,,,,,,,,,,,,,,, ##
  293. ## Not quite as simple |$1 ##
  294. ## ,,,,,,,,,,,,,,,,,,,,,,, ##
  295. ]])
  296. AT_CLEANUP
  297. # Strip path from file.
  298. AT_SETUP([AS@&t@_BASENAME])
  299. AT_KEYWORDS([m4sh])
  300. AT_DATA_M4SH([script.as],
  301. [[AS_INIT
  302. m4_define([BASENAME_TEST],
  303. [base=`AS_BASENAME([$1])`
  304. test "$base" = "$2" ||
  305. echo "basename($1) = $base instead of $2" >&2
  306. base=`_AS_BASENAME_SED([$1])`
  307. test "$base" = "$2" ||
  308. echo "basename_sed($1) = $base instead of $2" >&2])
  309. BASENAME_TEST([//1], [1])
  310. BASENAME_TEST([/1], [1])
  311. BASENAME_TEST([./1], [1])
  312. BASENAME_TEST([../../2], [2])
  313. BASENAME_TEST([//1/], [1])
  314. BASENAME_TEST([/1/], [1])
  315. BASENAME_TEST([./1/], [1])
  316. BASENAME_TEST([../../2], [2])
  317. BASENAME_TEST([//1/3], [3])
  318. BASENAME_TEST([/1/3], [3])
  319. BASENAME_TEST([./1/3], [3])
  320. BASENAME_TEST([../../2/3], [3])
  321. BASENAME_TEST([//1/3///], [3])
  322. BASENAME_TEST([/1/3///], [3])
  323. BASENAME_TEST([./1/3///], [3])
  324. BASENAME_TEST([../../2/3///], [3])
  325. BASENAME_TEST([//1//3/], [3])
  326. BASENAME_TEST([/1//3/], [3])
  327. BASENAME_TEST([./1//3/], [3])
  328. BASENAME_TEST([a.c], [a.c])
  329. BASENAME_TEST([a.c/], [a.c])
  330. BASENAME_TEST([/a.c/], [a.c])
  331. BASENAME_TEST([/1/a.c], [a.c])
  332. BASENAME_TEST([/1/a.c/], [a.c])
  333. BASENAME_TEST([/1/../a.c], [a.c])
  334. BASENAME_TEST([/1/../a.c/], [a.c])
  335. BASENAME_TEST([./1/a.c], [a.c])
  336. BASENAME_TEST([./1/a.c/], [a.c])
  337. AS_EXIT(0)
  338. ]])
  339. AT_CHECK_M4SH
  340. AT_CHECK([$CONFIG_SHELL ./script])
  341. AT_CLEANUP
  342. ## ------------ ##
  343. ## AS_DIRNAME. ##
  344. ## ------------ ##
  345. # Strip filename component.
  346. AT_SETUP([AS@&t@_DIRNAME])
  347. AT_KEYWORDS([m4sh])
  348. AT_DATA_M4SH([script.as],
  349. [[AS_INIT
  350. # The EXPR variant is allowed to fail if `expr' was considered as too
  351. # weak for us, in which case `as_expr=false'.
  352. m4_define([DIRNAME_TEST],
  353. [dir=`AS_DIRNAME([$1])`
  354. test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
  355. echo "dirname($1) = $dir instead of $2" >&2
  356. if test "$as_expr" != false; then
  357. dir=`_AS_DIRNAME_EXPR([$1])`
  358. test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
  359. echo "dirname_expr($1) = $dir instead of $2" >&2
  360. fi
  361. dir=`_AS_DIRNAME_SED([$1])`
  362. test "$dir" = "$2" || (test -n "$3" && test "$dir" = "$3") ||
  363. echo "dirname_sed($1) = $dir instead of $2" >&2])
  364. DIRNAME_TEST([/], [/])
  365. DIRNAME_TEST([//], [//], [/])
  366. DIRNAME_TEST([///], [/])
  367. DIRNAME_TEST([//1], [//], [/])
  368. DIRNAME_TEST([/1], [/])
  369. DIRNAME_TEST([./1], [.])
  370. DIRNAME_TEST([../../2], [../..])
  371. DIRNAME_TEST([//1/], [//], [/])
  372. DIRNAME_TEST([/1/], [/])
  373. DIRNAME_TEST([./1/], [.])
  374. DIRNAME_TEST([../../2], [../..])
  375. DIRNAME_TEST([//1/3], [//1])
  376. DIRNAME_TEST([/1/3], [/1])
  377. DIRNAME_TEST([./1/3], [./1])
  378. DIRNAME_TEST([../../2/3], [../../2])
  379. DIRNAME_TEST([//1/3///], [//1])
  380. DIRNAME_TEST([/1/3///], [/1])
  381. DIRNAME_TEST([./1/3///], [./1])
  382. DIRNAME_TEST([../../2/3///], [../../2])
  383. DIRNAME_TEST([//1//3/], [//1])
  384. DIRNAME_TEST([/1//3/], [/1])
  385. DIRNAME_TEST([./1//3/], [./1])
  386. DIRNAME_TEST([../../2//3/], [../../2])
  387. AS_EXIT(0)
  388. ]])
  389. AT_CHECK_M4SH
  390. AT_CHECK([$CONFIG_SHELL ./script])
  391. AT_CLEANUP
  392. ## ---------------- ##
  393. ## AS_SET_CATFILE. ##
  394. ## ---------------- ##
  395. AT_SETUP([AS@&t@_SET_CATFILE])
  396. AT_KEYWORDS([m4sh])
  397. AT_DATA_M4SH([script.as],
  398. [[AS_INIT
  399. # CATFILE_TEST(DIR, FILE, EXPECTED)
  400. m4_define([CATFILE_TEST],
  401. [# AS_SET_CATFILE works and can be used in a compound list.
  402. if AS_SET_CATFILE([var], [$1], [$2]) \
  403. && test "$var" = $3; then :; else
  404. echo "catfile($1, $2) = $var != $3" >&2
  405. fi
  406. # AS_SET_CATFILE can use non-literals in its arguments.
  407. varname=var2
  408. dirpart=$1
  409. filepart=$2
  410. if AS_SET_CATFILE([$varname], [$dirpart], [$filepart]) \
  411. && test "$var2" = $3; then :; else
  412. echo "catfile($dirpart, $filepart) = $var2 != $3" >&2
  413. fi
  414. ])
  415. CATFILE_TEST([dir], [file], [dir/file])
  416. CATFILE_TEST([.], [file], [file])
  417. CATFILE_TEST([dir], [.], [dir])
  418. CATFILE_TEST([dir], [/abs/file], [/abs/file])
  419. CATFILE_TEST([dir], [C:/abs/file], [C:/abs/file])
  420. CATFILE_TEST(["dir name"], ['file name'], ['dir name/file name'])
  421. AS_EXIT(0)
  422. ]])
  423. AT_CHECK_M4SH
  424. AT_CHECK([$CONFIG_SHELL ./script])
  425. AT_CLEANUP
  426. ## --------- ##
  427. ## AS_ECHO. ##
  428. ## --------- ##
  429. # Print literal strings, with/without newline.
  430. AT_SETUP([AS@&t@_ECHO and AS@&t@_ECHO_N])
  431. AT_KEYWORDS([m4sh])
  432. AT_DATA_M4SH([script.as],
  433. [[AS_INIT
  434. m4_define([ECHO_TEST],
  435. [echo=`AS_ECHO(['$1'])`
  436. test "X$echo" = 'X$1' ||
  437. echo "AS@&t@_ECHO('"'$1'"') outputs '$echo'" >&2
  438. echo=`AS_ECHO_N(['$1'])`
  439. test "X$echo" = 'X$1' ||
  440. echo "AS@&t@_ECHO_N('"'$1'"') outputs '$echo'" >&2])
  441. ECHO_TEST([-])
  442. ECHO_TEST([--])
  443. ECHO_TEST([---...---])
  444. ECHO_TEST([ ])
  445. ECHO_TEST([-e])
  446. ECHO_TEST([-E])
  447. ECHO_TEST([-n])
  448. ECHO_TEST([-n -n])
  449. ECHO_TEST([-e -n])
  450. ECHO_TEST([ab\ncd])
  451. ECHO_TEST([abcd\c])
  452. ECHO_TEST([\a\b\c\f\n\r\t\v\"\])
  453. ECHO_TEST([ab
  454. cd
  455. e])
  456. ECHO_TEST([
  457. ])
  458. ECHO_TEST([
  459. \c])
  460. AS_EXIT(0)
  461. ]])
  462. AT_CHECK_M4SH
  463. AT_CHECK([$CONFIG_SHELL ./script])
  464. AT_CLEANUP
  465. ## ----------------- ##
  466. ## AS_EXECUTABLE_P. ##
  467. ## ----------------- ##
  468. # Check for executable regular files.
  469. AT_SETUP([AS@&t@_EXECUTABLE_P])
  470. AT_KEYWORDS([m4sh])
  471. AT_DATA_M4SH([script.as],
  472. [[AS_INIT
  473. if AS_EXECUTABLE_P([/]); then
  474. echo fail
  475. else
  476. echo 1
  477. fi
  478. cat > foo.sh <<\EOF || AS_EXIT([1])
  479. #!/bin/sh
  480. exit 0
  481. EOF
  482. # File systems like FAT tend to fake executable permissions on all files.
  483. # At this point, foo.sh should be executable iff permissions are faked.
  484. AS_EXECUTABLE_P([foo.sh])
  485. st1=$?
  486. (./foo.sh) >/dev/null 2>&1
  487. st2=$?
  488. case $st1:$st2 in
  489. *[[1-9]]*:*[[1-9]]* | 0:0 ) echo 2 ;;
  490. *) echo "fail ($st1:$st2)" ;;
  491. esac
  492. # Now things better be executable
  493. chmod a+x foo.sh || AS_EXIT([2])
  494. mkdir 'two spaces' || AS_EXIT([3])
  495. 'two spaces'/../foo.sh || AS_EXIT([4])
  496. if AS_EXECUTABLE_P(["two spaces/../foo.sh"]); then
  497. echo 3
  498. else
  499. echo fail
  500. fi
  501. ]])
  502. AT_CHECK_M4SH
  503. AT_CHECK([$CONFIG_SHELL ./script], [],
  504. [[1
  505. 2
  506. 3
  507. ]])
  508. AT_CLEANUP
  509. ## --------- ##
  510. ## AS_EXIT. ##
  511. ## --------- ##
  512. # Exit scripts with given status.
  513. AT_SETUP([AS@&t@_EXIT])
  514. AT_KEYWORDS([m4sh AS@&t@_SET_STATUS])
  515. AT_DATA_M4SH([script.as],
  516. [[AS_INIT
  517. test x${1} = xa && AS_EXIT
  518. test x${1} = xb && AS_EXIT([${2}])
  519. test x${1} = xc && { AS_SET_STATUS([${2}]); AS_EXIT; }
  520. test x${1} = xd && trap 's=$?; echo $s; AS_EXIT([$s])' 0
  521. test x${2} = xe && set -e
  522. test $[#] -gt 0 || AS_EXIT
  523. AS_SET_STATUS([3])
  524. dnl Solaris /bin/sh 'set -e' doesn't react to failed function calls
  525. test x${2} = xe \
  526. && { echo 'skipping rest of test: set -e support is lousy'; exit 77; }
  527. AS_SET_STATUS([4])
  528. ]])
  529. AT_CHECK_M4SH
  530. AT_CHECK([$CONFIG_SHELL ./script], [1])
  531. AT_CHECK([$CONFIG_SHELL ./script ''], [4])
  532. AT_CHECK([$CONFIG_SHELL ./script a], [0])
  533. AT_CHECK([$CONFIG_SHELL ./script b], [0])
  534. AT_CHECK([$CONFIG_SHELL ./script b 0], [0])
  535. AT_CHECK([$CONFIG_SHELL ./script b 2], [2])
  536. AT_CHECK([$CONFIG_SHELL ./script c 0], [0])
  537. AT_CHECK([$CONFIG_SHELL ./script c 2], [2])
  538. AT_CHECK([$CONFIG_SHELL ./script d], [4], [[4
  539. ]])
  540. dnl If we got to this point without a FAIL, then AS_EXIT at least works.
  541. dnl The rest of this test relies on semi-decent 'set -e' support, even
  542. dnl though m4sh in general should not try to rely on it because of
  543. dnl portability nightmares on what constructs are considered errors across
  544. dnl various shells; therefore, an overall SKIP result is desirable on
  545. dnl broken shells like Solaris /bin/sh.
  546. AT_CHECK([$CONFIG_SHELL ./script '' e], [3])
  547. AT_CHECK([$CONFIG_SHELL ./script d e], [3], [stdout])
  548. dnl NetBSD sh fails to output on stderr here.
  549. AT_CHECK([grep 3 stdout || exit 77], [], [ignore])
  550. AT_CLEANUP
  551. ## ------------ ##
  552. ## AS_MKDIR_P. ##
  553. ## ------------ ##
  554. # Build nested dirs.
  555. AT_SETUP([AS@&t@_MKDIR_P])
  556. AT_KEYWORDS([m4sh])
  557. AT_DATA_M4SH([script.as],
  558. [[AS_INIT
  559. pwd=`pwd`
  560. set -e
  561. # Absolute
  562. AS_MKDIR_P(["$pwd/1/2/3/4/5/6"])
  563. test -d "$pwd/1/2/3/4/5/6" ||
  564. AS_ERROR([$pwd/1/2/3/4/5/6 has not been properly created])
  565. # Relative
  566. AS_MKDIR_P(["a/b/c/d/e/f"])
  567. test -d a/b/c/d/e/f ||
  568. AS_ERROR([a/b/c/d/e/f has not been properly created])
  569. AS_EXIT(0)
  570. ]])
  571. AT_CHECK_M4SH
  572. AT_CHECK([$CONFIG_SHELL ./script])
  573. AT_CLEANUP
  574. ## -------------------- ##
  575. ## AS_VERSION_COMPARE. ##
  576. ## -------------------- ##
  577. # Three-way version comparison.
  578. AT_SETUP([AS@&t@_VERSION_COMPARE])
  579. AT_KEYWORDS([m4sh])
  580. AT_DATA_M4SH([script.as],
  581. [[AS_INIT
  582. m4_define([VERSION_COMPARE_TEST],
  583. [AS_VERSION_COMPARE([$1], [$3], [result='<'], [result='='], [result='>'])
  584. test "X$result" = "X$2" ||
  585. AS_ERROR([version $1 $result $3; should be $1 $2 $3])
  586. m4_if([$1], <,
  587. [AS_VERSION_COMPARE([$3], [$1], [result='<'], [result='='], [result='>'])
  588. test "X$result" = "X>" ||
  589. AS_ERROR([version $3 $result $1; should be $3 > $1])])])
  590. VERSION_COMPARE_TEST([], =, [])
  591. VERSION_COMPARE_TEST([1.0], =, [1.0])
  592. VERSION_COMPARE_TEST([alpha-1.0], =, [alpha-1.0])
  593. # These tests are taken from libc/string/tst-svc.expect.
  594. tst_svc_expect='
  595. 000 001 00 00a 01 01a 0 0a 2.8 2.8-0.4 20 21 22 212 CP037 CP345 CP1257
  596. foo foo-0.4 foo-0.4a foo-0.4b foo-0.5 foo-0.10.5 foo-3.01 foo-3.0
  597. foo-3.0.0 foo-3.0.1 foo-3.2 foo-3.10 foo00 foo0
  598. '
  599. test1=''
  600. for test2 in $tst_svc_expect; do
  601. VERSION_COMPARE_TEST([$test1], <, [$test2])
  602. test1=$test2
  603. done
  604. AS_EXIT(0)
  605. ]])
  606. AT_CHECK_M4SH
  607. AT_CHECK([$CONFIG_SHELL ./script])
  608. AT_CLEANUP
  609. ## ------- ##
  610. ## as_me. ##
  611. ## ------- ##
  612. AT_SETUP([as_me])
  613. AT_KEYWORDS([m4sh])
  614. AT_DATA_M4SH([script.as],
  615. [[AS_INIT
  616. AS_ME_PREPARE
  617. test "$as_me" = script || AS_ECHO([["incorrect value of \$as_me: $as_me"]])
  618. ]])
  619. AT_CHECK_M4SH
  620. AT_CHECK([$CONFIG_SHELL ./script])
  621. AT_CLEANUP
  622. ## ----------------------------- ##
  623. ## Negated classes in globbing. ##
  624. ## ----------------------------- ##
  625. # According to http://www.in-ulm.de/~mascheck/bourne/, all shells with
  626. # functions also support `[!...]'. But `[^...]' is not universally supported.
  627. AT_SETUP([Negated classes in globbing])
  628. AT_KEYWORDS([m4sh])
  629. AT_DATA_M4SH([script.as],
  630. [[AS_INIT
  631. case 'with!two!bangs' in
  632. *[[!a-z]]*) ;;
  633. *) AS_ERROR([[`*[!a-z]*' didn't match `with!two!bangs']]);;
  634. esac
  635. case without in
  636. *[[!a-z]]*) AS_ERROR([[`*[!a-z]*' matched `without']]);;
  637. esac
  638. ]])
  639. AT_CHECK_M4SH
  640. AT_CHECK([$CONFIG_SHELL ./script])
  641. AT_CLEANUP
  642. ## ---------------------------- ##
  643. ## Null variable substitution. ##
  644. ## ---------------------------- ##
  645. # According to http://www.in-ulm.de/~mascheck/bourne/, all shells with
  646. # functions also support `${a:-b}'.
  647. AT_SETUP([Null variable substitution])
  648. AT_KEYWORDS([m4sh])
  649. AT_DATA_M4SH([script.as],
  650. [[AS_INIT
  651. AS_UNSET([a])
  652. b=
  653. c=.
  654. case ${a:-x}${b:-y}${c:-z} in
  655. xy.) ;;
  656. *) exit 1 ;;
  657. esac
  658. case ${a-x}${b-y}${c-z} in
  659. x.) ;;
  660. *) exit 2 ;;
  661. esac
  662. case ${a+x}${b+y}${c+z} in
  663. yz) ;;
  664. *) exit 3 ;;
  665. esac
  666. case ${a:+x}${b:+y}${c:+z} in
  667. z) ;;
  668. *) exit 4 ;;
  669. esac
  670. case ${a=x}${b=y}${c=z} in
  671. x.) ;;
  672. *) exit 5 ;;
  673. esac
  674. AS_UNSET([a])
  675. case ${a:=x}${b:=y}${c:=z} in
  676. xy.) ;;
  677. *) exit 6 ;;
  678. esac
  679. case $a$b$c in
  680. xy.) ;;
  681. *) exit 7 ;;
  682. esac
  683. AS_UNSET([a])
  684. b=
  685. (: ${a?oops}; echo fail) 2>err && exit 8
  686. grep oops err >/dev/null || exit 9
  687. test "${b?oops}" = '' || exit 10
  688. test "${c?oops}" = . || exit 11
  689. (: ${a:?oops}; echo fail) 2>err && exit 12
  690. grep oops err >/dev/null || exit 13
  691. (: ${b:?oops}; echo fail) 2>err && exit 14
  692. grep oops err >/dev/null || exit 15
  693. test "${c:?oops}" = . || exit 16
  694. ]])
  695. AT_CHECK_M4SH
  696. AT_CHECK([$CONFIG_SHELL ./script])
  697. AT_CLEANUP
  698. ## ------------------- ##
  699. ## Functions Support. ##
  700. ## ------------------- ##
  701. # All m4sh scripts require function support.
  702. AT_SETUP([Functions Support])
  703. AT_KEYWORDS([m4sh])
  704. AT_DATA_M4SH([script.as],
  705. [[AS_INIT
  706. AS_LINENO_PREPARE
  707. func_return () {
  708. (exit $1)
  709. }
  710. func_success () {
  711. func_return 0
  712. }
  713. func_failure () {
  714. func_return 1
  715. }
  716. if func_success; then
  717. if func_failure; then
  718. AS_ERROR([func_failure passed])
  719. fi
  720. else
  721. AS_ERROR([func_success failed])
  722. fi
  723. ]])
  724. AT_CHECK_M4SH
  725. AT_CHECK([$CONFIG_SHELL ./script])
  726. AT_CLEANUP
  727. ## ------------------------------ ##
  728. ## Functions and return Support. ##
  729. ## ------------------------------ ##
  730. # All m4sh scripts require working return within functions.
  731. AT_SETUP([Functions and return Support])
  732. AT_KEYWORDS([m4sh])
  733. AT_DATA_M4SH([script.as],
  734. [[AS_INIT
  735. AS_LINENO_PREPARE
  736. func_success () {
  737. return 0
  738. }
  739. func_failure () {
  740. return 1
  741. }
  742. if func_success; then
  743. if func_failure; then
  744. AS_ERROR([func_failure passed])
  745. fi
  746. else
  747. AS_ERROR([func_success failed])
  748. fi
  749. ]])
  750. AT_CHECK_M4SH
  751. AT_CHECK([$CONFIG_SHELL ./script])
  752. AT_CLEANUP
  753. ## --------------------------- ##
  754. ## Nested AS_REQUIRE_SHELL_FN. ##
  755. ## --------------------------- ##
  756. # Hypothesis: M4sh expands nested AS_REQUIRE_SHELL_FN
  757. # separately.
  758. AT_SETUP([Nested AS@&t@_REQUIRE_SHELL_FN])
  759. AT_KEYWORDS([m4sh])
  760. AT_DATA_M4SH([script.as], [[dnl
  761. m4_define([INIT], [oops])dnl
  762. AS_INIT
  763. m4_defun([TEST_FUNC2_BODY], [
  764. :
  765. ])
  766. m4_defun([TEST_FUNC1_BODY], [
  767. AS_REQUIRE_SHELL_FN([test_func2], [], [TEST_FUNC2_BODY])
  768. :
  769. ])
  770. AS_REQUIRE_SHELL_FN([test_func1], [], [TEST_FUNC1_BODY])
  771. test_func2
  772. ]])
  773. AT_CHECK_M4SH
  774. AT_CHECK([$CONFIG_SHELL ./script])
  775. AT_CLEANUP
  776. ## ------------------- ##
  777. ## Nested AS_REQUIRE. ##
  778. ## ------------------- ##
  779. # Hypothesis: M4sh expands the requirements of AS_REQUIRE in the
  780. # requested diversion, even if other AS_REQUIREs are interleaved.
  781. AT_SETUP([Nested AS@&t@_REQUIRE])
  782. AT_KEYWORDS([m4sh])
  783. AT_DATA_M4SH([script.as], [[dnl
  784. AS_INIT
  785. m4_defun([in_fn_diversion], still_in_m4sh_init_fn=yes)
  786. m4_defun([not_in_fn_diversion], still_in_m4sh_init_fn=no)
  787. m4_defun([NESTED], [nested_require_in_fn_diversion=$still_in_m4sh_init_fn])
  788. m4_defun([OUTER], [AS_REQUIRE([NESTED])dnl
  789. outer_require_in_fn_diversion=$still_in_m4sh_init_fn])
  790. m4_defun([test_init], [
  791. AS_REQUIRE([in_fn_diversion], , [M4SH-INIT-FN])
  792. AS_REQUIRE([OUTER], , [M4SH-INIT-FN])
  793. AS_REQUIRE([not_in_fn_diversion], , [M4SH-INIT-FN])
  794. ])
  795. test_init
  796. if test $outer_require_in_fn_diversion != yes; then AS_EXIT([1]); fi
  797. if test $nested_require_in_fn_diversion != no; then AS_EXIT([1]); fi
  798. ]])
  799. AT_CHECK_M4SH
  800. AT_CHECK([$CONFIG_SHELL ./script])
  801. AT_CLEANUP
  802. ## ------------------------------------ ##
  803. ## AS_REQUIRE_SHELL_FN and m4_require. ##
  804. ## ------------------------------------ ##
  805. # Hypothesis: M4sh expands the requirements of AS_REQUIRE_SHELL_FN
  806. # in M4SH-INIT-FN. This changed after Autoconf 2.63.
  807. AT_SETUP([AS@&t@_REQUIRE_SHELL_FN and m4@&t@_require])
  808. AT_KEYWORDS([m4sh])
  809. AT_DATA_M4SH([script.as], [[dnl
  810. AS_INIT
  811. m4_defun([in_m4_sh_init], still_in_m4sh_init=yes)
  812. m4_defun([not_in_m4_sh_init], still_in_m4sh_init=no)
  813. m4_defun([error_if_emitted_in_m4sh_init], [
  814. if test x$still_in_m4sh_init = xyes; then
  815. AS_ERROR([requirement emitted in M4SH-INIT])
  816. fi
  817. ])
  818. m4_defun([TEST_FUNC_BODY], [
  819. m4_require([error_if_emitted_in_m4sh_init])
  820. : echo in shell function, with parameter = [$]1
  821. ])
  822. m4_defun([test_init], [
  823. AS_REQUIRE([in_m4_sh_init], , [M4SH-INIT-FN])
  824. AS_REQUIRE_SHELL_FN([test_func], [], [TEST_FUNC_BODY])
  825. AS_REQUIRE([not_in_m4_sh_init])
  826. ])
  827. test_init
  828. test_func parameter1
  829. ]])
  830. AT_CHECK_M4SH
  831. AT_CHECK([$CONFIG_SHELL ./script])
  832. AT_CLEANUP
  833. ## -------------- ##
  834. ## AS_HELP_STRING ##
  835. ## -------------- ##
  836. AT_SETUP([AS@&t@_HELP_STRING])
  837. AT_KEYWORDS([m4sh m4@&t@_text_wrap m4@&t@_expand])
  838. AT_DATA_M4SH([script.as],
  839. [[AS_INIT
  840. echo "AS_HELP_STRING([--an-option],[some text])"
  841. echo "AS_HELP_STRING([--another-much-longer-option],
  842. [some other text which should wrap at our default of 80 characters.])"
  843. echo "AS_HELP_STRING([--fooT=barT], [foo bar])"
  844. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@], [foo bar])"
  845. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789], [foo bar])"
  846. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890], [foo bar])"
  847. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901], [foo bar])"
  848. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012], [foo bar])"
  849. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123], [foo bar])"
  850. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
  851. [some other text which should wrap at our default of 80 characters.])"
  852. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
  853. [some other text which should wrap at our default of 80 characters.])"
  854. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
  855. [some other text which should wrap at our default of 80 characters.])"
  856. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
  857. [some other text which should wrap at our default of 80 characters.])"
  858. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
  859. [some other text which should wrap at our default of 80 characters.])"
  860. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
  861. [some other text which should wrap at our default of 80 characters.])"
  862. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@],
  863. [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
  864. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789],
  865. [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
  866. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890],
  867. [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
  868. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@12345678901],
  869. [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
  870. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@123456789012],
  871. [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
  872. echo "AS_HELP_STRING([--foo@<][:@=bar@:][>@1234567890123],
  873. [some other @<][:@ex@:][>@ which should wrap at our default of 80 characters.])"
  874. echo "AS_HELP_STRING([[--foo[=bar]]],
  875. [some other t[]t which should wrap at our default of 80 characters.])"
  876. echo "AS_HELP_STRING([[--foo[=bar]123456789]],
  877. [some other t[]t which should wrap at our default of 80 characters.])"
  878. echo "AS_HELP_STRING([[--foo[=bar]1234567890]],
  879. [some other t[]t which should wrap at our default of 80 characters.])"
  880. echo "AS_HELP_STRING([[--foo[=bar]12345678901]],
  881. [some other t[]t which should wrap at our default of 80 characters.])"
  882. echo "AS_HELP_STRING([[--foo[=bar]123456789012]],
  883. [some other t[]t which should wrap at our default of 80 characters.])"
  884. echo "AS_HELP_STRING([[--foo[=bar]1234567890123]],
  885. [some other t[]t which should wrap at our default of 80 characters.])"
  886. m4_define([mac], [MACRO])dnl
  887. echo "AS_HELP_STRING([--mac], [mac])"
  888. echo "AS_HELP_STRING([--o1, --o2], [two
  889. options, one description])"
  890. echo "AS_HELP_STRING([[[--o3, --o4]]], [comma inside literal quoting])"
  891. echo "AS_HELP_STRING([--tune1], [check out the tuned formatting],
  892. [ ])"
  893. echo "AS_HELP_STRING([--tune2], [check out the tuned formatting],
  894. [12])"
  895. echo "AS_HELP_STRING([--tune3], [check out the tuned formatting],
  896. [], [40])"
  897. echo "AS_HELP_STRING([--tune4], [check out the tuned formatting],
  898. [12], [40])"
  899. ]])
  900. AT_CHECK_M4SH
  901. AT_CHECK([$CONFIG_SHELL ./script], [0],
  902. [[ --an-option some text
  903. --another-much-longer-option
  904. some other text which should wrap at our default of
  905. 80 characters.
  906. --fooT=barT foo bar
  907. --foo[=bar] foo bar
  908. --foo[=bar]123456789 foo bar
  909. --foo[=bar]1234567890 foo bar
  910. --foo[=bar]12345678901 foo bar
  911. --foo[=bar]123456789012 foo bar
  912. --foo[=bar]1234567890123
  913. foo bar
  914. --foo[=bar] some other text which should wrap at our default of
  915. 80 characters.
  916. --foo[=bar]123456789 some other text which should wrap at our default of
  917. 80 characters.
  918. --foo[=bar]1234567890 some other text which should wrap at our default of
  919. 80 characters.
  920. --foo[=bar]12345678901 some other text which should wrap at our default of
  921. 80 characters.
  922. --foo[=bar]123456789012 some other text which should wrap at our default of
  923. 80 characters.
  924. --foo[=bar]1234567890123
  925. some other text which should wrap at our default of
  926. 80 characters.
  927. --foo[=bar] some other [ex] which should wrap at our default of
  928. 80 characters.
  929. --foo[=bar]123456789 some other [ex] which should wrap at our default of
  930. 80 characters.
  931. --foo[=bar]1234567890 some other [ex] which should wrap at our default of
  932. 80 characters.
  933. --foo[=bar]12345678901 some other [ex] which should wrap at our default of
  934. 80 characters.
  935. --foo[=bar]123456789012 some other [ex] which should wrap at our default of
  936. 80 characters.
  937. --foo[=bar]1234567890123
  938. some other [ex] which should wrap at our default of
  939. 80 characters.
  940. --foo[=bar] some other t[]t which should wrap at our default of
  941. 80 characters.
  942. --foo[=bar]123456789 some other t[]t which should wrap at our default of
  943. 80 characters.
  944. --foo[=bar]1234567890 some other t[]t which should wrap at our default of
  945. 80 characters.
  946. --foo[=bar]12345678901 some other t[]t which should wrap at our default of
  947. 80 characters.
  948. --foo[=bar]123456789012 some other t[]t which should wrap at our default of
  949. 80 characters.
  950. --foo[=bar]1234567890123
  951. some other t[]t which should wrap at our default of
  952. 80 characters.
  953. --MACRO mac
  954. --o1, --o2 two options, one description
  955. [--o3, --o4] comma inside literal quoting
  956. --tune1 check out the tuned formatting
  957. --tune2 check out the tuned formatting
  958. --tune3 check out the
  959. tuned
  960. formatting
  961. --tune4 check out the tuned
  962. formatting
  963. ]])
  964. AT_CLEANUP
  965. ## ------------------- ##
  966. ## AS_IF and AS_CASE. ##
  967. ## ------------------- ##
  968. AT_SETUP([AS@&t@_IF and AS@&t@_CASE])
  969. AT_KEYWORDS([m4sh m4@&t@_map_args_pair])
  970. AT_DATA_M4SH([script.as], [[dnl
  971. AS_INIT
  972. # Syntax checks: cope with empty arguments.
  973. AS_IF([:], [], [echo wrong])
  974. AS_IF([:], [echo one], [echo wrong])
  975. AS_IF([false], [echo wrong], [echo two])
  976. AS_IF([false], [echo wrong])
  977. # n-ary version
  978. AS_IF([false], [echo wrong],
  979. [:], [echo three])
  980. AS_IF([false], [echo wrong],
  981. [:], [echo four],
  982. [echo wrong])
  983. AS_IF([false], [echo wrong],
  984. [false], [echo wrong])
  985. AS_IF([false], [echo wrong],
  986. [false], [echo wrong],
  987. [echo five])
  988. AS_IF([false], [echo wrong],
  989. [false], [echo wrong],
  990. [:], [echo six],
  991. [echo wrong])
  992. AS_CASE([foo])
  993. AS_CASE([foo], [echo seven])
  994. AS_CASE([foo],
  995. [foo], [echo eight],
  996. [echo wrong])
  997. AS_CASE([foo],
  998. [foo], [echo nine],
  999. [*], [echo wrong])
  1000. AS_CASE([foo],
  1001. [bar], [echo wrong],
  1002. [foo], [echo ten],
  1003. [*], [echo wrong])
  1004. # check for nesting, lists, and side effects, and quoting robustness
  1005. empty=
  1006. AS_IF([AS_IF([$empty], [echo eleven])]) && AS_CASE([foo]) && echo twelve
  1007. rm -f file
  1008. AS_IF([touch file; false]) && echo thirteen
  1009. test -f file && echo fourteen
  1010. rm -f file
  1011. AS_CASE([`touch file; false`]) && test -f file && echo fifteen
  1012. dnl The next line is badly underquoted; don't intentionally copy this style.
  1013. AS_CASE([foo], [foo], m4_do(AS_CASE([bar], [bar], [echo sixteen])))
  1014. dnl Handle blank arguments.
  1015. AS_IF([false], [:], [ ]) && AS_CASE([foo], [foo], []
  1016. ) && echo seventeen
  1017. m4_define([empty])AS_IF([:], [empty]
  1018. ) && AS_CASE([foo], [foo], [empty]) && echo eighteen
  1019. dnl We can't handle AS_IF([false], [:], [empty]) unless m4_expand is
  1020. dnl taught how to handle m4_require. The user is responsible for
  1021. dnl avoiding the syntax error in that case.
  1022. # check that require works correctly
  1023. m4_for([n], 1, 9, [],
  1024. [m4_defun([FOO]n, [foo]n[=]n)dnl
  1025. m4_defun([BAR]n,
  1026. [m4_require([FOO]]n[)dnl
  1027. bar]n[=]n)[]dnl
  1028. ])
  1029. AS_IF([:], [BAR1])
  1030. echo "foo1=$foo1 bar1=$bar1"
  1031. AS_IF([:], [], [BAR2])
  1032. echo "foo2=$foo2 bar2=$bar2"
  1033. AS_IF([false], [BAR3])
  1034. echo "foo3=$foo3 bar3=$bar3"
  1035. AS_IF([false], [], [BAR4])
  1036. echo "foo4=$foo4 bar4=$bar4"
  1037. AS_CASE([x], [x], [BAR5])
  1038. echo "foo5=$foo5 bar5=$bar5"
  1039. AS_CASE([x], [y], [BAR6])
  1040. echo "foo6=$foo6 bar6=$bar6"
  1041. AS_CASE([x],
  1042. [x], [:],
  1043. [BAR7])
  1044. echo "foo7=$foo7 bar7=$bar7"
  1045. AS_CASE([x],
  1046. [y], [:],
  1047. [BAR8])
  1048. echo "foo8=$foo8 bar8=$bar8"
  1049. AS_CASE([x],
  1050. [y], [:],
  1051. [x], [BAR9])
  1052. echo "foo9=$foo9 bar9=$bar9"
  1053. ]])
  1054. AT_CHECK_M4SH
  1055. AT_CHECK([$CONFIG_SHELL ./script], [0], [[one
  1056. two
  1057. three
  1058. four
  1059. five
  1060. six
  1061. seven
  1062. eight
  1063. nine
  1064. ten
  1065. eleven
  1066. twelve
  1067. thirteen
  1068. fourteen
  1069. fifteen
  1070. sixteen
  1071. seventeen
  1072. eighteen
  1073. foo1=1 bar1=1
  1074. foo2=2 bar2=
  1075. foo3=3 bar3=
  1076. foo4=4 bar4=4
  1077. foo5=5 bar5=5
  1078. foo6=6 bar6=
  1079. foo7=7 bar7=
  1080. foo8=8 bar8=8
  1081. foo9=9 bar9=9
  1082. ]])
  1083. dnl stress test for large number of conditionals
  1084. dnl too large, and we start tickling shell bugs
  1085. m4_pushdef([limit], [1000])dnl
  1086. AT_DATA_M4SH([script.as], [[dnl
  1087. AS_INIT
  1088. AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])))
  1089. AS_IF(m4_shift(m4_for([i], [1], ]limit[, [], [, test $[1] = i, echo i])),
  1090. [echo default])
  1091. AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]))
  1092. AS_CASE([$[1]]m4_for([i], [1], ]limit[, [], [, i, echo i]), [echo default])
  1093. ]])
  1094. dnl Add --force so autom4te doesn't think `script' is still up to date.
  1095. AT_CHECK_M4SH([--force])
  1096. AT_CHECK([$CONFIG_SHELL ./script 1], [0], [[1
  1097. 1
  1098. 1
  1099. 1
  1100. ]])
  1101. AT_CHECK([$CONFIG_SHELL ./script limit], [0], [limit
  1102. limit
  1103. limit
  1104. limit
  1105. ])
  1106. AT_CHECK([$CONFIG_SHELL ./script default], [0], [[default
  1107. default
  1108. ]])
  1109. m4_popdef([limit])
  1110. AT_CLEANUP
  1111. ## -------- ##
  1112. ## AS_FOR. ##
  1113. ## -------- ##
  1114. AT_SETUP([AS@&t@_FOR])
  1115. AT_KEYWORDS([m4sh])
  1116. AT_DATA_M4SH([script.as], [[dnl
  1117. AS_INIT
  1118. # Simple checks.
  1119. AS_FOR([m4var], [shvar], [a],
  1120. [echo "m4var $shvar"])
  1121. AS_FOR([m4var], [shvar], [b c],
  1122. [echo "m4var $shvar"])
  1123. list='d e'
  1124. AS_FOR([m4var], [shvar], [$list],
  1125. [echo "m4var $shvar"])
  1126. AS_FOR([m4var], [shvar], ["$list"],
  1127. [echo "m4var $shvar"])
  1128. AS_FOR([m4var], [shvar], ['$list'],
  1129. [echo "m4var $shvar"])
  1130. AS_FOR([m4var], [shvar], [\'],
  1131. [echo "m4var $shvar"])
  1132. # Syntax checks: cope with empty/blank arguments.
  1133. set f g
  1134. AS_FOR([], [shvar], [],
  1135. [echo "m4_defn([]) $shvar"])
  1136. rm -f file
  1137. AS_FOR([], [shvar], [`touch file`])
  1138. test -f file || exit 1
  1139. AS_FOR([], [shvar], [], [ ])
  1140. m4_define([empty])AS_FOR([], [shvar], [], [empty])
  1141. # Check that break works.
  1142. while :
  1143. do
  1144. AS_FOR([m4var], [shvar], [h i],
  1145. [echo "m4var"; break 2])
  1146. exit 1
  1147. done
  1148. while :
  1149. do
  1150. AS_FOR([m4var], [shvar], [j],
  1151. [echo "m4var"; break 2])
  1152. exit 1
  1153. done
  1154. ]])
  1155. AT_CHECK_M4SH
  1156. AT_CHECK([$CONFIG_SHELL ./script], [0], [[a a
  1157. b b
  1158. c c
  1159. d d
  1160. e e
  1161. d e d e
  1162. $list $list
  1163. ' '
  1164. f f
  1165. g g
  1166. h
  1167. j
  1168. ]])
  1169. AT_CLEANUP
  1170. ## --------------- ##
  1171. ## AS_LITERAL_IF. ##
  1172. ## --------------- ##
  1173. AT_SETUP([AS@&t@_LITERAL_IF])
  1174. AT_KEYWORDS([m4sh AS@&t@_LITERAL_WORD_IF AS@&t@_LITERAL_HEREDOC_IF])
  1175. AT_DATA_M4SH([script.as], [[dnl
  1176. AS_INIT
  1177. echo AS_LITERAL_IF([lit], [ok], [ERR]) 1
  1178. echo AS_LITERAL_IF([l-/.it], [ok], [ERR]) 2
  1179. echo AS_LITERAL_IF([l''it], [ERR], [ok]) 3
  1180. echo AS_LITERAL_IF([l$it], [ERR], [ok]) 4
  1181. echo AS_LITERAL_IF([l$it], [ERR1], [ERR2], [ok]) 5
  1182. echo AS_LITERAL_IF([l${it}], [ERR1], [ERR2], [ok]) 6
  1183. echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR], [ok]) 7
  1184. echo AS_LITERAL_IF([l`case a in b) ;; esac`it], [ERR1], [ok], [ERR2]) 8
  1185. m4_define([mac], [l-/.it])
  1186. echo AS_LITERAL_IF([mac], [ok], [ERR]) 9
  1187. echo AS_LITERAL_IF([mac($, ``)], [ok], [ERR]) 10
  1188. m4_define([mac], [l$it])
  1189. echo AS_LITERAL_IF([mac], [ERR], [ok]) 11
  1190. echo AS_LITERAL_IF([mac], [ERR1], [ERR2], [ok]) 12
  1191. m4_define([mac], [l``it])
  1192. echo AS_LITERAL_IF([mac], [ERR], [ok]) 13
  1193. echo AS_LITERAL_IF([mac], [ERR1], [ok], [ERR2]) 14
  1194. echo AS_LITERAL_IF([ a ][
  1195. b], [ok], [ERR]) 15
  1196. echo AS_LITERAL_WORD_IF([ a ][
  1197. b], [ERR], [ok]) 16
  1198. echo AS_LITERAL_HEREDOC_IF([ a ][
  1199. b], [ok], [ERR]) 17
  1200. echo AS_LITERAL_IF([(a)], [ERR], [ok]) 18
  1201. echo AS_LITERAL_WORD_IF([(a)], [ERR], [ok]) 19
  1202. echo AS_LITERAL_HEREDOC_IF([(a)], [ok], [ERR]) 20
  1203. echo AS_LITERAL_IF([@S|@a], [ERR], [ok]) 21
  1204. echo AS_LITERAL_WORD_IF([@S|@a], [ERR], [ok]) 22
  1205. echo AS_LITERAL_HEREDOC_IF([@S|@a], [ERR], [ok]) 23
  1206. echo AS_LITERAL_IF([${a+b}], [ERR1], [ok], [ERR2]) 24
  1207. echo AS_LITERAL_IF([${a=b}], [ERR1], [ok], [ERR2]) 25
  1208. echo AS_LITERAL_IF([a+b], [ok], [ERR1], [ERR2]) 26
  1209. echo AS_LITERAL_IF([a=b], [ok], [ERR1], [ERR2]) 27
  1210. ]])
  1211. AT_CHECK_M4SH
  1212. AT_CHECK([$CONFIG_SHELL ./script], [],
  1213. [[ok 1
  1214. ok 2
  1215. ok 3
  1216. ok 4
  1217. ok 5
  1218. ok 6
  1219. ok 7
  1220. ok 8
  1221. ok 9
  1222. ok 10
  1223. ok 11
  1224. ok 12
  1225. ok 13
  1226. ok 14
  1227. ok 15
  1228. ok 16
  1229. ok 17
  1230. ok 18
  1231. ok 19
  1232. ok 20
  1233. ok 21
  1234. ok 22
  1235. ok 23
  1236. ok 24
  1237. ok 25
  1238. ok 26
  1239. ok 27
  1240. ]])
  1241. AT_CLEANUP
  1242. ## --------------------- ##
  1243. ## AS_TR_SH, AS_TR_CPP. ##
  1244. ## --------------------- ##
  1245. AT_SETUP([AS@&t@_TR_SH and AS@&t@_TR_CPP])
  1246. AT_DATA_M4SH([script.as], [[dnl
  1247. AS_INIT
  1248. m4_define([abc], [hI])m4_define([ABC], [Hi])
  1249. m4_define([hi], [oops])m4_define([HI], [OOPS])
  1250. echo AS_TR_SH(abc) AS_TR_SH(aBc) AS_TR_SH(ABC)
  1251. echo AS_TR_SH([abc]) AS_TR_SH([aBc]) AS_TR_SH([ABC])
  1252. echo AS_TR_SH([[abc]]) AS_TR_SH([[aBc]]) AS_TR_SH([[ABC]])
  1253. echo AS_TR_CPP(abc) AS_TR_CPP(aBc) AS_TR_CPP(ABC)
  1254. echo AS_TR_CPP([abc]) AS_TR_CPP([aBc]) AS_TR_CPP([ABC])
  1255. echo AS_TR_CPP([[abc]]) AS_TR_CPP([[aBc]]) AS_TR_CPP([[ABC]])
  1256. echo ===
  1257. [var=abc vAr=aBc VAR=ABC]
  1258. echo AS_TR_SH($var) AS_TR_SH($vAr) AS_TR_SH($VAR)
  1259. echo AS_TR_SH([$var]) AS_TR_SH([$vAr]) AS_TR_SH([$VAR])
  1260. echo AS_TR_SH([[$var]]) AS_TR_SH([[$vAr]]) AS_TR_SH([[$VAR]])
  1261. echo AS_TR_CPP($var) AS_TR_CPP($vAr) AS_TR_CPP($VAR)
  1262. echo AS_TR_CPP([$var]) AS_TR_CPP([$vAr]) AS_TR_CPP([$VAR])
  1263. echo AS_TR_CPP([[$var]]) AS_TR_CPP([[$vAr]]) AS_TR_CPP([[$VAR]])
  1264. echo ===
  1265. echo AS_TR_SH(`echo abc`) AS_TR_SH(`echo aBc`) AS_TR_SH(`echo ABC`)
  1266. echo AS_TR_SH([`echo abc`]) AS_TR_SH([`echo aBc`]) AS_TR_SH([`echo ABC`])
  1267. echo AS_TR_SH([[`echo abc`]]) AS_TR_SH([[`echo aBc`]]) AS_TR_SH([[`echo ABC`]])
  1268. echo AS_TR_CPP(`echo abc`) AS_TR_CPP(`echo aBc`) AS_TR_CPP(`echo ABC`)
  1269. echo AS_TR_CPP([`echo abc`]) AS_TR_CPP([`echo aBc`]) AS_TR_CPP([`echo ABC`])
  1270. echo AS_TR_CPP([[`echo abc`]]) AS_TR_CPP([[`echo aBc`]]) AS_TR_CPP([[`echo ABC`]])
  1271. echo ===
  1272. # start here
  1273. echo AS_TR_SH([a.b/c+*-=])
  1274. echo AS_TR_CPP([a.b/c+*-=])
  1275. var=a.b/c+*-=
  1276. echo AS_TR_SH([$var])
  1277. echo AS_TR_CPP([$var])
  1278. m4_define([macro], [a.b/c+*-=])
  1279. echo AS_TR_SH([macro])
  1280. echo AS_TR_CPP([macro])
  1281. ]])
  1282. AT_CHECK_M4SH
  1283. AT_CHECK([$CONFIG_SHELL ./script], [],
  1284. [[hI aBc Hi
  1285. hI aBc Hi
  1286. abc aBc ABC
  1287. HI ABC HI
  1288. HI ABC HI
  1289. ABC ABC ABC
  1290. ===
  1291. abc aBc ABC
  1292. abc aBc ABC
  1293. abc aBc ABC
  1294. ABC ABC ABC
  1295. ABC ABC ABC
  1296. ABC ABC ABC
  1297. ===
  1298. hI aBc Hi
  1299. hI aBc Hi
  1300. abc aBc ABC
  1301. HI ABC HI
  1302. HI ABC HI
  1303. ABC ABC ABC
  1304. ===
  1305. a_b_cpp__
  1306. A_B_C_P__
  1307. a_b_cpp__
  1308. A_B_C_P__
  1309. a_b_cpp__
  1310. A_B_C_P__
  1311. ]])
  1312. dnl Check that of the last 6 macros, only 2 needed command substitution.
  1313. dnl This test abuses our knowledge of m4sh internals a bit; oh well.
  1314. AT_CHECK([tab=' ' # a single ASCII tab character
  1315. sed -n '/start here/,$ {
  1316. /`.*`/p
  1317. }' script | wc -l | sed "s/[[ $tab]]//g" ], [], [[2
  1318. ]])
  1319. AT_CLEANUP
  1320. ## ---------- ##
  1321. ## AS_VAR_*. ##
  1322. ## ---------- ##
  1323. AT_SETUP([AS@&t@_VAR basics])
  1324. AT_KEYWORDS([m4sh AS@&t@_VAR_COPY AS@&t@_VAR_SET AS@&t@_VAR_GET])
  1325. AT_KEYWORDS([AS@&t@_VAR_TEST_SET AS@&t@_VAR_SET_IF AS@&t@_VAR_IF])
  1326. AT_KEYWORDS([AS@&t@_VAR_PUSHDEF AS@&t@_VAR_POPDEF])
  1327. AT_DATA_M4SH([script.as], [[dnl
  1328. AS_INIT
  1329. m4_define([with], [WITH])
  1330. # Literals.
  1331. dnl AS_VAR_SET_IF also covers AS_VAR_TEST_SET
  1332. AS_VAR_SET_IF([foo], [echo oops]) && echo ok
  1333. AS_VAR_IF([foo], [], [echo ok], [echo oops])
  1334. foo=
  1335. AS_VAR_SET_IF([foo], [echo ok])
  1336. AS_VAR_SET([foo], ['\a "weird" `value` with; $fun '\''characters
  1337. ']) # 'font-lock
  1338. AS_VAR_COPY([bar], [foo])
  1339. AS_ECHO(["$bar-"])
  1340. AS_ECHO(["AS_VAR_GET([foo])-"])
  1341. AS_VAR_SET_IF([foo], [echo ok], [echo oops])
  1342. AS_VAR_IF([foo], [string], [echo oops]) && echo ok
  1343. AS_VAR_PUSHDEF([tmp], [foo])
  1344. AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
  1345. '], [echo ok], [echo oops]) # 'font-lock
  1346. AS_VAR_POPDEF([tmp])
  1347. m4_ifdef([tmp], [echo oops])
  1348. # Indirects via shell vars.
  1349. echo '===='
  1350. num=1
  1351. AS_VAR_SET_IF([foo$num], [echo oops]) && echo ok
  1352. AS_VAR_IF([foo$num], [], [echo ok], [echo oops])
  1353. foo1=
  1354. AS_VAR_SET_IF([foo$num], [echo ok])
  1355. AS_VAR_SET([foo$num], ['\a "weird" `value` with; $fun '\''characters
  1356. ']) # 'font-lock
  1357. AS_VAR_COPY([bar], [foo$num])
  1358. num=2
  1359. AS_VAR_COPY([foo$num], [bar])
  1360. AS_ECHO(["$foo2-"])
  1361. AS_ECHO(["AS_VAR_GET([foo$num])-"])
  1362. AS_VAR_SET_IF([foo$num], [echo ok], [echo oops])
  1363. AS_VAR_IF([foo$num], [string], [echo oops]) && echo ok
  1364. AS_VAR_PUSHDEF([tmp], [foo$num])
  1365. AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
  1366. '], [echo ok], [echo oops]) # 'font-lock
  1367. AS_VAR_POPDEF([tmp])
  1368. m4_ifdef([tmp], [echo oops])
  1369. # Indirects via command substitution.
  1370. echo '===='
  1371. AS_VAR_SET_IF([`echo foo3`], [echo oops]) && echo ok
  1372. AS_VAR_IF([`echo foo3`], [], [echo ok], [echo oops])
  1373. foo3=
  1374. AS_VAR_SET_IF([`echo foo3`], [echo ok])
  1375. AS_VAR_SET([`echo foo3`], ['\a "weird" `value` with; $fun '\''characters
  1376. ']) # 'font-lock
  1377. AS_VAR_COPY([bar], [`echo foo3`])
  1378. num=2
  1379. AS_VAR_COPY([`echo foo4`], [bar])
  1380. AS_ECHO(["$foo4-"])
  1381. AS_ECHO(["AS_VAR_GET([`echo foo4`])-"])
  1382. AS_VAR_SET_IF([`echo foo4`], [echo ok], [echo oops])
  1383. AS_VAR_IF([`echo foo4`], [string], [echo oops]) && echo ok
  1384. AS_VAR_PUSHDEF([tmp], [`echo foo4`])
  1385. AS_VAR_IF([tmp], ['\a "weird" `value` with; $fun '\''characters
  1386. '], [echo ok], [echo oops]) # 'font-lock
  1387. AS_VAR_POPDEF([tmp])
  1388. m4_ifdef([tmp], [echo oops])
  1389. :
  1390. ]])
  1391. AT_CHECK_M4SH
  1392. AT_CHECK([$CONFIG_SHELL ./script], [], [[ok
  1393. ok
  1394. ok
  1395. \a "weird" `value` WITH; $fun 'characters
  1396. -
  1397. \a "weird" `value` WITH; $fun 'characters
  1398. -
  1399. ok
  1400. ok
  1401. ok
  1402. ====
  1403. ok
  1404. ok
  1405. ok
  1406. \a "weird" `value` WITH; $fun 'characters
  1407. -
  1408. \a "weird" `value` WITH; $fun 'characters-
  1409. ok
  1410. ok
  1411. ok
  1412. ====
  1413. ok
  1414. ok
  1415. ok
  1416. \a "weird" `value` WITH; $fun 'characters
  1417. -
  1418. \a "weird" `value` WITH; $fun 'characters-
  1419. ok
  1420. ok
  1421. ok
  1422. ]])
  1423. AT_CLEANUP
  1424. ## --------------- ##
  1425. ## AS_VAR_APPEND. ##
  1426. ## --------------- ##
  1427. AT_SETUP([AS@&t@_VAR_APPEND])
  1428. AT_KEYWORDS([m4sh AS@&t@_VAR])
  1429. AT_DATA_M4SH([script.as], [[dnl
  1430. AS_INIT
  1431. # Literals.
  1432. AS_VAR_APPEND([foo], ["hello, "])
  1433. AS_VAR_APPEND([foo], [world])
  1434. echo "$foo"
  1435. # Indirects via shell vars.
  1436. num=1
  1437. AS_VAR_APPEND([foo$num], ['hello, '])
  1438. AS_VAR_APPEND([foo$num], [`echo "world"`])
  1439. echo "$foo1"
  1440. # Indirects via command substitution.
  1441. h=hello w=', world'
  1442. AS_VAR_APPEND([`echo foo2`], [${h}])
  1443. AS_VAR_APPEND([`echo foo2`], ["$w"])
  1444. echo "$foo2"
  1445. ]])
  1446. AT_CHECK_M4SH
  1447. AT_CHECK([$CONFIG_SHELL ./script], [],
  1448. [[hello, world
  1449. hello, world
  1450. hello, world
  1451. ]])
  1452. AT_CLEANUP
  1453. ## -------------- ##
  1454. ## AS_VAR_ARITH. ##
  1455. ## -------------- ##
  1456. AT_SETUP([AS@&t@_VAR_ARITH])
  1457. AT_KEYWORDS([m4sh AS@&t@_VAR])
  1458. AT_DATA_M4SH([script.as], [[dnl
  1459. AS_INIT
  1460. # Literals.
  1461. AS_VAR_ARITH([foo], [1 + 1])
  1462. echo "$foo"
  1463. # Indirects via shell vars.
  1464. num=1
  1465. AS_VAR_ARITH([foo$num], [\( 2 + 3 \) \* 4])
  1466. echo "$foo1"
  1467. # Indirects via command substitution.
  1468. AS_VAR_ARITH([`echo foo2`], [0 + -2 + $foo1 / 2])
  1469. echo "$foo2"
  1470. ]])
  1471. AT_CHECK_M4SH
  1472. AT_CHECK([$CONFIG_SHELL ./script], [],
  1473. [[2
  1474. 20
  1475. 8
  1476. ]])
  1477. AT_CLEANUP
  1478. ## ----------------- ##
  1479. ## AS_INIT cleanup. ##
  1480. ## ----------------- ##
  1481. AT_SETUP([AS@&t@_INIT cleanup])
  1482. AT_KEYWORDS([m4sh m4@&t@_wrap m4@&t@_wrap_lifo])
  1483. AT_DATA_M4SH([script.as], [[dnl
  1484. dnl Registered before AS_INIT's cleanups
  1485. m4_wrap([echo cleanup 1
  1486. ])
  1487. m4_pushdef([_AS_SHELL_FN_SPY])dnl neutralize the spy, we don't care about it
  1488. AS_INIT
  1489. dnl Registered after AS_INIT's cleanups, thus goes to KILL diversion
  1490. m4_wrap([echo cleanup 2
  1491. dnl However, nested wraps and diversions can still be used
  1492. dnl Also, test wrapping text that looks like parameter reference
  1493. m4_wrap([echo cleanup 3
  1494. m4_divert_text([M4SH-INIT], [m4_define([foo], [$1])dnl
  1495. echo prep foo([4])
  1496. ])])])
  1497. dnl Registered before AS_INIT's cleanups
  1498. m4_wrap_lifo([echo cleanup 5
  1499. ])
  1500. echo body
  1501. ]])
  1502. AT_CHECK_M4SH
  1503. AT_CHECK([$CONFIG_SHELL ./script], [], [[prep 4
  1504. body
  1505. cleanup 5
  1506. cleanup 1
  1507. ]])
  1508. AT_CLEANUP
  1509. ## ------------------- ##
  1510. ## AS_INIT_GENERATED. ##
  1511. ## ------------------- ##
  1512. AT_SETUP([AS@&t@_INIT_GENERATED])
  1513. AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD])
  1514. dnl First run, no logging, tests shell selection
  1515. AT_DATA_M4SH([script.as], [[dnl
  1516. AS_INIT
  1517. AS_INIT_GENERATED([child], [echo hello from child])
  1518. cat >>child <<\EOF
  1519. AS_ECHO(["SHELL=$SHELL"])
  1520. EOF
  1521. echo hello from parent
  1522. AS_ECHO(["SHELL=$SHELL"])
  1523. ]])
  1524. AT_CHECK_M4SH
  1525. AT_CHECK([$CONFIG_SHELL ./script], [0], [stdout])
  1526. AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
  1527. sed s/parent/child/ <stdout >expout
  1528. AT_CHECK([./child], [0], [expout])
  1529. SHELL=/bogus
  1530. export SHELL
  1531. cp stdout expout
  1532. mv child child.bak
  1533. AT_CHECK([$CONFIG_SHELL ./script], [0], [expout])
  1534. AT_CHECK([cmp child child.bak])
  1535. AT_CHECK([grep 'SHELL=.' stdout], [0], [ignore])
  1536. sed s/parent/child/ <stdout >expout
  1537. AT_CHECK([./child], [0], [expout])
  1538. dnl Second run, with logging from parent and child, tests fd handling
  1539. AT_DATA_M4SH([script.as], [[dnl
  1540. AS_INIT
  1541. child=${1-child}
  1542. m4_define([AS_MESSAGE_LOG_FD], [5])
  1543. exec AS_MESSAGE_LOG_FD>log
  1544. AS_INIT_GENERATED([$child], [echo hello1 from $child]) || AS_EXIT([1])
  1545. cat >>$child <<\EOF
  1546. m4_pushdef([AS_MESSAGE_LOG_FD])
  1547. AS_MESSAGE([hello2 from ${child}child])
  1548. m4_popdef([AS_MESSAGE_LOG_FD])
  1549. exec AS_MESSAGE_LOG_FD>>log
  1550. AS_MESSAGE([hello3 from child])
  1551. EOF
  1552. AS_MESSAGE([hello from parent])
  1553. dnl close log in parent before spawning child, for mingw
  1554. exec AS_MESSAGE_LOG_FD>&-
  1555. ./$child
  1556. ]])
  1557. rm -f script
  1558. AT_CHECK_M4SH
  1559. AT_CHECK([$CONFIG_SHELL ./script], [0], [[script: hello from parent
  1560. hello1 from child
  1561. child: hello2 from child
  1562. child: hello3 from child
  1563. ]])
  1564. AT_CHECK([[sed 's,:[0-9][0-9]*:,:0:,' log]], [0],
  1565. [[script:0: hello from parent
  1566. child:0: hello3 from child
  1567. ]])
  1568. # Force write error creating a file on stdout
  1569. if test -w /dev/full && test -c /dev/full; then
  1570. AT_CHECK([$CONFIG_SHELL ./script /dev/full], [1], [ignore], [ignore])
  1571. fi
  1572. AT_CLEANUP
  1573. ## --------------- ##
  1574. ## AS_MESSAGE_FD. ##
  1575. ## --------------- ##
  1576. AT_SETUP([AS@&t@_MESSAGE_FD])
  1577. AT_KEYWORDS([AS@&t@_MESSAGE AS@&t@_MESSAGE_LOG_FD AS@&t_ORIGINAL_STDIN_FD])
  1578. AT_KEYWORDS([AS@&t@_LINENO_PUSH])
  1579. AT_DATA_M4SH([script.as], [[dnl
  1580. AS_INIT
  1581. m4_define([AS_ORIGINAL_STDIN_FD], [5])
  1582. m4_define([AS_MESSAGE_LOG_FD], [6])
  1583. m4_define([AS_MESSAGE_FD], [7])
  1584. exec AS_ORIGINAL_STDIN_FD<&0 </dev/null AS_MESSAGE_LOG_FD>log
  1585. if test $[#] -gt 0; then
  1586. exec AS_MESSAGE_FD>/dev/null
  1587. else
  1588. exec AS_MESSAGE_FD>&1
  1589. fi
  1590. AS_LINENO_PUSH([100])
  1591. cat # tests that stdin is neutralized
  1592. AS_MESSAGE([hello world])
  1593. cat <&AS_ORIGINAL_STDIN_FD
  1594. ]])
  1595. AT_CHECK_M4SH
  1596. AT_CHECK([echo goodbye | $CONFIG_SHELL ./script], [0],
  1597. [[script: hello world
  1598. goodbye
  1599. ]])
  1600. AT_CHECK([cat log], [0],
  1601. [[script:100: hello world
  1602. ]])
  1603. rm log
  1604. AT_CHECK([echo goodbye | $CONFIG_SHELL ./script silent], [0],
  1605. [[goodbye
  1606. ]])
  1607. AT_CHECK([cat log], [0],
  1608. [[script:100: hello world
  1609. ]])
  1610. AT_CLEANUP
  1611. ## --------------- ##
  1612. ## _AS_CLEAN_DIR. ##
  1613. ## --------------- ##
  1614. AT_SETUP([_AS@&t@_CLEAN_DIR])
  1615. dnl ensure that we can erase all files in a directory. Note that
  1616. dnl _AS_CLEAN_DIR needs three globs to catch all these files.
  1617. AT_DATA_M4SH([script.as], [[dnl
  1618. AS_INIT
  1619. # Unwritable subdirectories are common during 'make distcheck'.
  1620. mkdir sub sub/unwritable || AS_ERROR([failed to mkdir])
  1621. touch sub/unwritable/file || AS_ERROR([failed to touch])
  1622. chmod a-wx sub/unwritable || AS_ERROR([failed to chmod])
  1623. # Cygwin 1.5 can't touch 'sub/...', so make that file optional.
  1624. touch sub/a sub/aa sub/aaa sub/.a sub/..a sub/.aa \
  1625. || AS_ERROR([failed to touch])
  1626. touch sub/... 2>/dev/null
  1627. _AS_CLEAN_DIR([sub]) || AS_ERROR([failed to clean])
  1628. # rmdir instead of 'rm -fr' here proves that we emptied sub.
  1629. rmdir sub || AS_ERROR([failed to rmdir])
  1630. ]])
  1631. AT_CHECK_M4SH
  1632. AT_CHECK([$CONFIG_SHELL ./script])
  1633. AT_CLEANUP
  1634. ## -------- ##
  1635. ## ECHO_C. ##
  1636. ## -------- ##
  1637. AT_SETUP([ECHO_C])
  1638. AT_DATA_M4SH([script.as], [[dnl
  1639. AS_INIT
  1640. _AS_PREPARE
  1641. foo=`echo foobar`
  1642. echo "$foo"
  1643. ]])
  1644. AT_CHECK_M4SH
  1645. AT_CHECK([$CONFIG_SHELL ./script], [], [foobar
  1646. ])
  1647. AT_CLEANUP