m4sugar.at 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140
  1. # -*- Autotest -*-
  2. AT_BANNER([M4sugar.])
  3. # Copyright (C) 2000-2002, 2005-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_CHECK_M4SUGAR_TEXT(CODE, STDOUT, STDERR)
  18. # -------------------------------------------
  19. # Check that m4sugar CODE expands to STDOUT and emits STDERR.
  20. m4_define([AT_CHECK_M4SUGAR_TEXT],
  21. [
  22. AT_DATA_M4SUGAR([script.4s],
  23. [[m4_init
  24. m4_divert_push([])[]dnl
  25. ]$1[[]dnl
  26. m4_divert_pop([])
  27. ]])
  28. AT_CHECK_M4SUGAR([-o-],, [$2], [$3])
  29. ])# AT_CHECK_M4SUGAR_TEXT
  30. ## ------------------ ##
  31. ## m4_stack_foreach. ##
  32. ## ------------------ ##
  33. AT_SETUP([m4@&t@_stack])
  34. AT_KEYWORDS([m4@&t@_stack_foreach m4@&t@_stack_foreach_lifo])
  35. AT_KEYWORDS([m4@&t@_stack_foreach_sep m4@&t@_stack_foreach_sep_lifo])
  36. AT_KEYWORDS([m4@&t@_copy m4@&t@_n])
  37. # Test the semantics of macros to walk stacked macro definitions.
  38. AT_CHECK_M4SUGAR_TEXT([[dnl
  39. m4_pushdef([abc], [def])dnl
  40. m4_pushdef([abc], [ghi])dnl
  41. m4_pushdef([abc], [jkl])dnl
  42. m4_stack_foreach([abc], [m4_n])
  43. abc
  44. m4_stack_foreach_lifo([abc], [m4_n])
  45. m4_stack_foreach([abc], [m4_n])
  46. m4_copy([abc], [foo])dnl
  47. m4_stack_foreach([foo], [m4_n])
  48. m4_stack_foreach_lifo([foo], [m4_n])
  49. m4_stack_foreach_sep([abc], [ m4_index([abcdefghijkl],], [)])
  50. m4_define([colon], [:])m4_define([lt], [<])m4_define([gt], [>])dnl
  51. m4_stack_foreach_sep_lifo([abc], [lt], [gt], [colon])
  52. m4_pushdef([xyz], [123])dnl
  53. m4_pushdef([xyz], [456])dnl
  54. m4_define([doit], [[$1](m4_stack_foreach_sep([xyz], [m4_dquote(], [)], [,]))
  55. ])dnl
  56. m4_stack_foreach([abc], [doit])]],
  57. [[def
  58. ghi
  59. jkl
  60. jkl
  61. jkl
  62. ghi
  63. def
  64. def
  65. ghi
  66. jkl
  67. def
  68. ghi
  69. jkl
  70. jkl
  71. ghi
  72. def
  73. 3 6 9
  74. <jkl>:<ghi>:<def>
  75. def([123],[456])
  76. ghi([123],[456])
  77. jkl([123],[456])
  78. ]])
  79. AT_CLEANUP
  80. ## --------- ##
  81. ## m4_defn. ##
  82. ## --------- ##
  83. AT_SETUP([m4@&t@_defn])
  84. AT_KEYWORDS([m4@&t@_popdef m4@&t@_undefine m4@&t@_copy m4@&t@_rename
  85. m4@&t@_copy_force m4@&t@_rename_force])
  86. # Ensure that m4sugar dies when dereferencing undefined macros, whether
  87. # this is provided by m4 natively or faked by wrappers in m4sugar.
  88. AT_DATA_M4SUGAR([script.4s],
  89. [[m4_define([good])
  90. m4_defn([good], [oops])
  91. ]])
  92. AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
  93. AT_CHECK([grep good stderr], [1])
  94. AT_CHECK([grep 'm4@&t@_defn: undefined.*oops' stderr], [0], [ignore])
  95. AT_DATA_M4SUGAR([script.4s],
  96. [[m4_define([good])
  97. m4_popdef([good], [oops])
  98. ]])
  99. AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
  100. AT_CHECK([grep good stderr], [1])
  101. AT_CHECK([grep 'm4@&t@_popdef: undefined.*oops' stderr], [0], [ignore])
  102. AT_DATA_M4SUGAR([script.4s],
  103. [[m4_define([good])
  104. m4_undefine([good], [oops])
  105. ]])
  106. AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
  107. AT_CHECK([grep good stderr], [1])
  108. AT_CHECK([grep 'm4@&t@_undefine: undefined.*oops' stderr], [0], [ignore])
  109. # Cannot rename an undefined macro.
  110. AT_DATA_M4SUGAR([script.4s],
  111. [[m4_rename([oops], [good])
  112. ]])
  113. AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
  114. AT_CHECK([grep 'm4@&t@_undefine: undefined.*oops' stderr], [0], [ignore])
  115. # Check that pushdef stacks can be renamed.
  116. AT_CHECK_M4SUGAR_TEXT([[m4_pushdef([a], [1])dnl
  117. m4_pushdef([a], [2])dnl
  118. m4_pushdef([a], m4_defn([m4_divnum]))dnl
  119. a b c
  120. m4_rename([a], [b])dnl
  121. a b c
  122. m4_copy([b], [c])dnl
  123. a b c
  124. m4_popdef([b], [c])dnl
  125. a b c
  126. m4_popdef([b], [c])dnl
  127. a b c
  128. m4_popdef([b], [c])dnl
  129. a b c
  130. dnl m4_copy is intentionally a no-op on undefined source
  131. m4_copy([oops], [dummy])m4_ifdef([dummy], [[oops]])dnl
  132. dnl allow forceful overwrites
  133. m4_define([d], [4])m4_define([e], [5])m4_define([f], [6])dnl
  134. m4_copy_force([d], [e])dnl
  135. m4_rename_force([d], [f])dnl
  136. d e f
  137. m4_popdef([e], [f])dnl
  138. d e f
  139. ]], [[0 b c
  140. a 0 c
  141. a 0 0
  142. a 2 2
  143. a 1 1
  144. a b c
  145. d 4 4
  146. d e f
  147. ]])
  148. AT_CLEANUP
  149. ## ------------ ##
  150. ## m4_dumpdef. ##
  151. ## ------------ ##
  152. AT_SETUP([m4@&t@_dumpdef])
  153. AT_KEYWORDS([m4@&t@_dumpdefs])
  154. # Ensure that m4sugar dies when dereferencing undefined macros.
  155. AT_DATA_M4SUGAR([script.4s],
  156. [[m4_define([good], [yep])
  157. m4_dumpdef([good], [oops])
  158. ]])
  159. AT_CHECK_M4SUGAR([-o-], 1, [], [stderr])
  160. AT_CHECK([grep '^good: \[[yep\]]$' stderr], [0], [ignore])
  161. AT_CHECK([grep 'm4@&t@_dumpdef: undefined.*oops' stderr], [0], [ignore])
  162. # Check that pushdef stacks can be dumped.
  163. AT_CHECK_M4SUGAR_TEXT([[m4_divert_push([KILL])
  164. m4_pushdef([a], [1])
  165. m4_pushdef([a], [2])
  166. m4_dumpdef([a])
  167. m4_dumpdefs([oops], [a])
  168. m4_divert_pop([KILL])dnl
  169. ]], [],
  170. [[a: [2]
  171. a: [2]
  172. a: [1]
  173. ]])
  174. # Check behavior when dumping builtins. Unfortunately, when using M4 1.4.x
  175. # (or more precisely, when __m4_version__ is undefined), builtins get
  176. # flattened to an empty string. It takes M4 1.6 to work around this.
  177. AT_DATA_M4SUGAR([script.4s],
  178. [[m4_ifdef([__m4_version__], [_m4_undefine([__m4_version__])])
  179. m4_init
  180. m4_dumpdef([m4_define])
  181. ]])
  182. AT_CHECK_M4SUGAR([-o-], [0], [],
  183. [[m4_define: []
  184. ]])
  185. AT_DATA_M4SUGAR([script.4s],
  186. [[m4_init
  187. m4_ifdef([__m4_version__],
  188. [m4_dumpdef([m4_define])],
  189. [m4_errprintn([m4_define: <define>])])
  190. ]])
  191. AT_CHECK_M4SUGAR([-o-], [0], [],
  192. [[m4_define: <define>
  193. ]])
  194. AT_CLEANUP
  195. ## --------- ##
  196. ## m4_warn. ##
  197. ## --------- ##
  198. AT_SETUP([m4@&t@_warn])
  199. AT_DATA_M4SUGAR([script.4s],
  200. [[m4_init
  201. m4_defun([cross_warning], [m4_warn([cross], [cross])])
  202. m4_divert([0])dnl
  203. m4_warn([obsolete], [obsolete])dnl
  204. cross_warning[]dnl
  205. m4_warn([syntax], [syntax])dnl
  206. cross_warning[]dnl
  207. m4_warn([syntax], [syntax])dnl
  208. ]])
  209. AT_CHECK_M4SUGAR([-o-], 0, [],
  210. [script.4s:4: warning: prefer named diversions
  211. script.4s:7: warning: syntax
  212. script.4s:9: warning: syntax
  213. ])
  214. AT_CHECK_M4SUGAR([-o- -Wall], 0, [],
  215. [script.4s:4: warning: prefer named diversions
  216. script.4s:5: warning: obsolete
  217. script.4s:6: warning: cross
  218. script.4s:2: cross_warning is expanded from...
  219. script.4s:6: the top level
  220. script.4s:7: warning: syntax
  221. script.4s:8: warning: cross
  222. script.4s:2: cross_warning is expanded from...
  223. script.4s:8: the top level
  224. script.4s:9: warning: syntax
  225. ])
  226. AT_CHECK_M4SUGAR([-o- -Wnone,cross], 0, [],
  227. [script.4s:6: warning: cross
  228. script.4s:2: cross_warning is expanded from...
  229. script.4s:6: the top level
  230. script.4s:8: warning: cross
  231. script.4s:2: cross_warning is expanded from...
  232. script.4s:8: the top level
  233. ])
  234. AT_CHECK_M4SUGAR([-o- -Wnone,cross,error], 1, [],
  235. [[script.4s:6: warning: cross
  236. script.4s:2: cross_warning is expanded from...
  237. script.4s:6: the top level
  238. script.4s:8: warning: cross
  239. script.4s:2: cross_warning is expanded from...
  240. script.4s:8: the top level
  241. ]])
  242. AT_CLEANUP
  243. ## ----------------- ##
  244. ## m4_divert_stack. ##
  245. ## ----------------- ##
  246. AT_SETUP([m4@&t@_divert_stack])
  247. AT_KEYWORDS([m4@&t@_divert m4@&t@_divert_push m4@&t@_divert_pop
  248. m4@&t@_undivert m4@&t@_cleardivert m4@&t@_divert_text])
  249. dnl This test names some diversions to avoid a warning.
  250. AT_CHECK_M4SUGAR_TEXT([[m4_define([_m4_divert(ten)], [10])dnl
  251. m4_define([_m4_divert(twenty)], [20])dnl
  252. m4_define([_m4_divert(thirty)], [30])dnl
  253. 1.m4_divert_stack
  254. m4_divert_push([ten])2.m4_divert_stack
  255. m4_divert_text([twenty], [3.m4_divert_stack])dnl
  256. m4_divert([thirty])4.m4_divert_stack
  257. m4_divert_pop([thirty])dnl
  258. 5.m4_undivert([twenty], [thirty])
  259. m4_pattern_allow([^m4_divert])dnl
  260. ]], [[1.script.4s:2: m4@&t@_divert_push:
  261. script.4s:1: m4@&t@_divert: KILL
  262. 5.3.script.4s:8: m4@&t@_divert_push: twenty
  263. script.4s:7: m4@&t@_divert_push: ten
  264. script.4s:2: m4@&t@_divert_push:
  265. script.4s:1: m4@&t@_divert: KILL
  266. 4.script.4s:9: m4@&t@_divert: thirty
  267. script.4s:2: m4@&t@_divert_push:
  268. script.4s:1: m4@&t@_divert: KILL
  269. 2.script.4s:7: m4@&t@_divert_push: ten
  270. script.4s:2: m4@&t@_divert_push:
  271. script.4s:1: m4@&t@_divert: KILL
  272. ]])
  273. AT_CHECK_M4SUGAR_TEXT([[dnl
  274. m4_divert_text([3], [three])dnl
  275. m4_divert_text([4], [four])dnl
  276. m4_divert_text([1], [one])dnl
  277. m4_divert_text([2], [two])dnl
  278. m4_cleardivert([2], [3])dnl
  279. ]],
  280. [[one
  281. four
  282. ]],
  283. [[script.4s:4: warning: prefer named diversions
  284. script.4s:5: warning: prefer named diversions
  285. script.4s:6: warning: prefer named diversions
  286. script.4s:7: warning: prefer named diversions
  287. script.4s:8: warning: prefer named diversions
  288. ]])
  289. AT_DATA_M4SUGAR([script.4s],
  290. [[m4_divert_pop
  291. ]])
  292. AT_CHECK_M4SUGAR([-o-], [1], [],
  293. [[script.4s:1: error: too many m4@&t@_divert_pop
  294. script.4s:1: the top level
  295. autom4te: m4 failed with exit status: 1
  296. ]])
  297. AT_DATA_M4SUGAR([script.4s],
  298. [[m4_init
  299. m4_divert_push([1])
  300. m4_divert_pop([2])
  301. ]])
  302. AT_CHECK_M4SUGAR([-o-], [1], [],
  303. [[script.4s:3: error: m4@&t@_divert_pop(2): diversion mismatch:
  304. script.4s:2: m4@&t@_divert_push: 1
  305. script.4s:1: m4@&t@_divert: KILL
  306. script.4s:3: the top level
  307. autom4te: m4 failed with exit status: 1
  308. ]])
  309. AT_DATA_M4SUGAR([script.4s],
  310. [[m4_divert([1])
  311. m4_init
  312. m4_divert_push([2])
  313. ]])
  314. AT_CHECK_M4SUGAR([-o-], [1], [],
  315. [[script.4s:2: error: m4@&t@_init: unbalanced m4@&t@_divert_push:
  316. script.4s:3: m4@&t@_divert_push: 2
  317. script.4s:2: m4@&t@_divert: KILL
  318. script.4s:2: the top level
  319. autom4te: m4 failed with exit status: 1
  320. ]])
  321. AT_CLEANUP
  322. ## -------------------- ##
  323. ## m4_expansion_stack. ##
  324. ## -------------------- ##
  325. AT_SETUP([m4@&t@_expansion_stack])
  326. AT_CHECK_M4SUGAR_TEXT([[1.m4_expansion_stack
  327. m4_defun([a], [b])dnl
  328. m4_define([c], [d])dnl
  329. m4_defun([d], [2.m4_expansion_stack])dnl
  330. m4_defun([b], [c])dnl
  331. a
  332. 3.m4_ifdef([_m4_expansion_stack], [m4_expansion_stack])
  333. ]], [[1.script.4s:3: the top level
  334. 2.script.4s:6: d is expanded from...
  335. script.4s:7: b is expanded from...
  336. script.4s:4: a is expanded from...
  337. script.4s:8: the top level
  338. 3.
  339. ]])
  340. AT_CLEANUP
  341. ## --------------------------- ##
  342. ## m4_require: error message. ##
  343. ## --------------------------- ##
  344. AT_SETUP([m4@&t@_require: error message])
  345. AT_KEYWORDS([m4@&t@_require])
  346. AT_DATA_M4SUGAR([script.4s],
  347. [[m4_defun([foo], [FOO])
  348. m4_require([foo])
  349. ]])
  350. AT_CHECK_M4SUGAR([], 1, [],
  351. [[script.4s:2: error: m4@&t@_require(foo): cannot be used outside of an m4_defun'd macro
  352. script.4s:2: the top level
  353. autom4te: m4 failed with exit status: 1
  354. ]])
  355. AT_CLEANUP
  356. ## ----------------------------------- ##
  357. ## m4_require: circular dependencies. ##
  358. ## ----------------------------------- ##
  359. AT_SETUP([m4@&t@_require: circular dependencies])
  360. AT_KEYWORDS([m4@&t@_require])
  361. AT_DATA_M4SUGAR([script.4s],
  362. [[m4_defun([foo], [m4_require([bar])])
  363. m4_defun([bar], [m4_require([foo])])
  364. m4_defun([baz], [m4_require([foo])])
  365. m4_init
  366. m4_divert([0])dnl
  367. baz
  368. ]])
  369. AT_CHECK_M4SUGAR([], 1, [],
  370. [[script.4s:9: error: m4@&t@_require: circular dependency of foo
  371. script.4s:3: bar is expanded from...
  372. script.4s:1: foo is expanded from...
  373. script.4s:5: baz is expanded from...
  374. script.4s:9: the top level
  375. autom4te: m4 failed with exit status: 1
  376. ]])
  377. AT_CLEANUP
  378. ## ---------------------- ##
  379. ## m4_require: one-shot. ##
  380. ## ---------------------- ##
  381. AT_SETUP([m4@&t@_require: one-shot initialization])
  382. AT_KEYWORDS([m4@&t@_require])
  383. AT_KEYWORDS([m4@&t@_defun_init m4@&t@_copy m4@&t@_defun_once])
  384. dnl check out m4_defun_init, m4_copy, and odd macro names
  385. AT_CHECK_M4SUGAR_TEXT([[
  386. m4_define([t], [text])dnl
  387. m4_defun_init([a], [[init a
  388. ]], [[common a] t])dnl
  389. m4_defun([b], [[b]m4_require([a])])dnl
  390. m4_defun([c], [[c]m4_require([a])])dnl
  391. b
  392. c
  393. a()dnl
  394. m4_defun_init([-], [hello, ], [m4_if([$#], [0], [world], [[$1]])])dnl
  395. m4_copy([-], [.])dnl
  396. m4_indir([.])
  397. m4_indir([.], [goodbye])
  398. m4_indir([-], [again])
  399. ]], [[
  400. init a
  401. common a text
  402. b
  403. c
  404. common a text
  405. hello, world
  406. goodbye
  407. hello, again
  408. ]])
  409. dnl Check m4_defun_once behavior
  410. AT_CHECK_M4SUGAR_TEXT([[
  411. m4_defun_once([a], [[a]])dnl
  412. m4_defun([b], [[b]m4_require([a])])dnl
  413. m4_defun([c], [[c]a[]m4_require([b])])dnl
  414. c
  415. a
  416. m4_defun_once([d], [[d]m4_require([a])])dnl
  417. d
  418. m4_defun_once([e], [[e]])dnl
  419. m4_defun([f], [[f]m4_require([e])e])dnl
  420. f
  421. ]], [[
  422. a
  423. b
  424. c
  425. d
  426. e
  427. f
  428. ]])
  429. AT_CLEANUP
  430. ## -------------------- ##
  431. ## m4_require: nested. ##
  432. ## -------------------- ##
  433. AT_SETUP([m4@&t@_require: nested])
  434. AT_KEYWORDS([m4@&t@_require m4@&t@_defun])
  435. dnl From the m4sugar.m4 discourse: Require chains, top level
  436. AT_CHECK_M4SUGAR_TEXT([[dnl
  437. m4_defun([a], [[a]])dnl aka TEST2a
  438. m4_defun([b], [[b]m4_require([a])])dnl aka TEST3
  439. m4_defun([c], [[c]m4_require([b])])dnl aka TEST2b
  440. m4_defun([d], [[d]m4_require([a])m4_require([c])])dnl aka TEST1
  441. pre
  442. d
  443. d
  444. post
  445. ]],
  446. [[pre
  447. a
  448. b
  449. c
  450. d
  451. d
  452. post
  453. ]])
  454. dnl From the m4sugar.m4 discourse: Require chains, nested
  455. AT_CHECK_M4SUGAR_TEXT([[dnl
  456. m4_defun([a], [[a]])dnl aka TEST2a
  457. m4_defun([b], [[b]m4_require([a])])dnl aka TEST3
  458. m4_defun([c], [[c]m4_require([b])])dnl aka TEST2b
  459. m4_defun([d], [[d]m4_require([a])m4_require([c])])dnl aka TEST1
  460. m4_defun([wrap],
  461. [pre
  462. d
  463. d
  464. post])dnl
  465. wrap
  466. ]],
  467. [[a
  468. b
  469. c
  470. pre
  471. d
  472. d
  473. post
  474. ]])
  475. dnl Direct invocation, nested requires, top level
  476. AT_CHECK_M4SUGAR_TEXT([[dnl
  477. m4_defun([a], [[a]])dnl
  478. m4_defun([b], [[b]m4_require([a])])dnl
  479. m4_defun([c], [[c]m4_require([b])])dnl
  480. pre
  481. a
  482. c
  483. a
  484. c
  485. post
  486. ]],
  487. [[pre
  488. a
  489. b
  490. c
  491. a
  492. c
  493. post
  494. ]])
  495. dnl Direct invocation, nested requires, nested defun. This is an example
  496. dnl of expansion before requirement, such that b occurs before its
  497. dnl prerequisite a. This indicates a bug in the macros (but not in
  498. dnl autoconf), so we should be emitting a warning.
  499. AT_CHECK_M4SUGAR_TEXT([[dnl
  500. m4_defun([a], [[a]])dnl
  501. m4_defun([b], [[b]m4_require([a])])dnl
  502. m4_defun([c], [[c]m4_require([b])])dnl
  503. dnl the extra macro layer works around line number differences in older m4
  504. m4_define([foo], [m4_defun([outer],
  505. [pre
  506. a
  507. c
  508. a
  509. c
  510. post])])foo[]dnl
  511. outer
  512. ]],
  513. [[a
  514. b
  515. pre
  516. a
  517. c
  518. a
  519. c
  520. post
  521. ]],
  522. [[script.4s:15: warning: m4@&t@_require: `a' was expanded before it was required
  523. script.4s:15: http://www.gnu.org/software/autoconf/manual/autoconf.html#Expanded-Before-Required
  524. script.4s:5: b is expanded from...
  525. script.4s:6: c is expanded from...
  526. script.4s:14: outer is expanded from...
  527. script.4s:15: the top level
  528. ]])
  529. dnl Direct invocation, expand-before-require but no nested require. As this
  530. dnl is common in real life, but does not result in out-of-order expansion,
  531. dnl we silently permit this.
  532. AT_CHECK_M4SUGAR_TEXT([[dnl
  533. m4_defun([a], [[a]])dnl
  534. m4_defun([b], [[b]m4_require([a])])dnl
  535. m4_defun([c], [[c]])dnl
  536. m4_defun([d], [[d]m4_require([c])])dnl
  537. pre1
  538. a
  539. b
  540. a
  541. b
  542. post1
  543. m4_defun([outer],
  544. [pre2
  545. c
  546. d
  547. c
  548. d
  549. post2])dnl
  550. outer
  551. m4_defun([e], [[e]])dnl
  552. m4_defun([f], [[f]m4_require([e])])dnl
  553. m4_defun([g], [[g]
  554. e
  555. f])dnl
  556. m4_defun([h], [[h]m4_require([g])])dnl
  557. h
  558. m4_defun([i], [[i]])dnl
  559. m4_defun([j], [[j]
  560. i])dnl
  561. m4_defun([k], [[k]m4_require([i])])dnl
  562. m4_defun([l], [[l]m4_require([k])])dnl
  563. m4_defun([m], [[m]m4_require([j])m4_require([l])])dnl
  564. m
  565. ]],
  566. [[pre1
  567. a
  568. b
  569. a
  570. b
  571. post1
  572. pre2
  573. c
  574. d
  575. c
  576. d
  577. post2
  578. g
  579. e
  580. f
  581. h
  582. j
  583. i
  584. k
  585. l
  586. m
  587. ]])
  588. AT_CLEANUP
  589. ## ------------------------------------------------- ##
  590. ## m4_ifval, m4_ifblank, m4_ifset, m4_default, etc. ##
  591. ## ------------------------------------------------- ##
  592. AT_SETUP([m4sugar shorthand conditionals])
  593. AT_KEYWORDS([m4@&t@_ifval m4@&t@_ifblank m4@&t@_ifnblank m4@&t@_ifset
  594. m4@&t@_default m4@&t@_default_quoted m4@&t@_default_nblank
  595. m4@&t@_default_nblank_quoted])
  596. AT_CHECK_M4SUGAR_TEXT([[m4_define([active], [ACTIVE])m4_define([empty])
  597. m4_ifval([active], [yes], [no])
  598. m4_ifval([empty], [yes], [no])
  599. m4_ifval([ ], [yes], [no])
  600. m4_ifval([], [yes], [no])
  601. m4_ifblank([active], [yes], [no])
  602. m4_ifblank([empty], [yes], [no])
  603. m4_ifblank([ ], [yes], [no])
  604. m4_ifblank([], [yes], [no])
  605. m4_ifnblank([active], [yes], [no])
  606. m4_ifnblank([empty], [yes], [no])
  607. m4_ifnblank([ ], [yes], [no])
  608. m4_ifnblank([], [yes], [no])
  609. m4_ifset([active], [yes], [no])
  610. m4_ifset([empty], [yes], [no])
  611. m4_ifset([ ], [yes], [no])
  612. m4_ifset([], [yes], [no])
  613. ---
  614. m4_define([demo1], [m4_default([$1], [$2])])dnl
  615. m4_define([demo2], [m4_default_quoted([$1], [$2])])dnl
  616. m4_define([demo3], [m4_default_nblank([$1], [$2])])dnl
  617. m4_define([demo4], [m4_default_nblank_quoted([$1], [$2])])dnl
  618. demo1([active], [default])
  619. demo1([], [active])
  620. demo1([empty], [text])
  621. -demo1([ ], [active])-
  622. demo2([active], [default])
  623. demo2([], [active])
  624. demo2([empty], [text])
  625. -demo2([ ], [active])-
  626. demo3([active], [default])
  627. demo3([], [active])
  628. demo3([empty], [text])
  629. -demo3([ ], [active])-
  630. demo4([active], [default])
  631. demo4([], [active])
  632. demo4([empty], [text])
  633. -demo4([ ], [active])-
  634. ]], [[
  635. yes
  636. yes
  637. yes
  638. no
  639. no
  640. no
  641. yes
  642. yes
  643. yes
  644. yes
  645. no
  646. no
  647. yes
  648. no
  649. no
  650. no
  651. ---
  652. ACTIVE
  653. ACTIVE
  654. - -
  655. active
  656. active
  657. empty
  658. - -
  659. ACTIVE
  660. ACTIVE
  661. -ACTIVE-
  662. active
  663. active
  664. empty
  665. -active-
  666. ]])
  667. AT_CLEANUP
  668. ## --------- ##
  669. ## m4_cond. ##
  670. ## --------- ##
  671. AT_SETUP([m4@&t@_cond])
  672. AT_CHECK_M4SUGAR_TEXT([[m4_define([side], [m4_errprintn([$1])$1])
  673. m4_cond([side(1)], [1], [a],
  674. [side(1)], [1], [b],
  675. [side(1)], [2], [c])
  676. m4_cond([side(2)], [1], [a],
  677. [side(2)], [1], [b],
  678. [side(2)], [2], [c],
  679. [side(2)])
  680. m4_cond([side(3)], [1], [a],
  681. [side(3)], [1], [b],
  682. [side(3)], [2], [c],
  683. [side(3)])
  684. m4_cond([a,a], [a,a], [yes], [no])
  685. m4_cond([[a,a]], [a,a], [yes])
  686. m4_cond([a,a], [a,b], [yes], [no])
  687. m4_cond([a,a], [a,b], [yes])
  688. m4_cond([m4_eval([0xa])])
  689. m4_define([ab], [AB])dnl
  690. m4_cond([a])b
  691. m4_cond([1], [1], [a])b
  692. m4_cond([1], [2], [3], [a])b
  693. ]], [[
  694. a
  695. c
  696. 3
  697. yes
  698. yes
  699. no
  700. 10
  701. AB
  702. AB
  703. AB
  704. ]], [[1
  705. 2
  706. 2
  707. 2
  708. 3
  709. 3
  710. 3
  711. 3
  712. ]])
  713. AT_CLEANUP
  714. ## ---------- ##
  715. ## m4 lists. ##
  716. ## ---------- ##
  717. AT_SETUP([m4 lists])
  718. AT_KEYWORDS([m4@&t@_car m4@&t@_cdr m4@&t@_argn _m4@&t_cdr])
  719. AT_CHECK_M4SUGAR_TEXT([[dnl
  720. m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])
  721. m4_argn([1], [a], [b], [c])
  722. m4_argn([2], [a], [b], [c])
  723. m4_argn([3], [a], [b], [c])
  724. m4_argn([4], [a], [b], [c])
  725. m4_car([a], [b], [c])
  726. m4_cdr([a], [b], [c])
  727. m4_cdr([a], [b])
  728. m4_cdr([a])
  729. _m4_cdr([a], [b], [c])
  730. _m4_cdr([a], [b])
  731. _m4_cdr([a])
  732. m4_if(m4_cdr([], []), [[]], [good], [bad])
  733. m4_if(m4_cdr([]), [], [good], [bad])
  734. ]], [[
  735. a
  736. b
  737. c
  738. a
  739. [b],[c]
  740. [b]
  741. , [b],[c]
  742. , [b]
  743. good
  744. good
  745. ]])
  746. AT_DATA_M4SUGAR([script.4s],
  747. [[m4_init
  748. m4_argn([0], [a], [b], [c])
  749. ]])
  750. AT_CHECK_M4SUGAR([-o-], [1], [],
  751. [[script.4s:2: error: assert failed: 0 < 0
  752. script.4s:2: the top level
  753. autom4te: m4 failed with exit status: 1
  754. ]])
  755. AT_CLEANUP
  756. ## ---------- ##
  757. ## m4_split. ##
  758. ## ---------- ##
  759. AT_SETUP([m4@&t@_split])
  760. AT_CHECK_M4SUGAR_TEXT(
  761. [[m4_define([active], [ACT, IVE])m4_define([bd], [oops])
  762. m4_split
  763. m4_split([[]])
  764. m4_split([ ])
  765. m4_split([active])
  766. m4_split([ active active ])end
  767. m4_split([ ], [ ])
  768. m4_split([active], [ ])
  769. m4_split([ active active ], [ ])end
  770. m4_split([abcde], [bd])
  771. m4_split([abcde], [[bd]])
  772. m4_split([foo=`` bar=''])
  773. m4_split([foo='' bar=``])
  774. dnl these next two are from the manual; keep this in sync if the internal
  775. dnl quoting strings in m4_split are changed
  776. m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
  777. m4_split([a )}>=- b -=<{( c])
  778. m4_split([a )}@&t@>=- b -=<@&t@{( c])
  779. ]],
  780. [[
  781. [[]]
  782. [], []
  783. [active]
  784. [], [active], [active], []end
  785. [], []
  786. [active]
  787. [], [active active], []end
  788. [abcde]
  789. [a], [c], [e]
  790. [foo=``], [bar='']
  791. [foo=''], [bar=``]
  792. [a], [], [B], [], [c]
  793. [a], [)}>=@&t@-], [b], [-@&t@=<{(], [c]
  794. ]])
  795. AT_CLEANUP
  796. ## ------- ##
  797. ## m4_do. ##
  798. ## ------- ##
  799. AT_SETUP([m4@&t@_do])
  800. AT_CHECK_M4SUGAR_TEXT(
  801. [[m4_define([ab], [1])m4_define([bc], [2])m4_define([abc], [3])dnl
  802. m4_define([AB], [4])m4_define([BC], [5])m4_define([ABC], [6])dnl
  803. m4_do
  804. m4_do([a])
  805. m4_do([a], [b])c
  806. m4_unquote(m4_join([], [a], [b]))c
  807. m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
  808. m4_do([a], [b])c
  809. m4_unquote(m4_join([], [a], [b]))c
  810. ]],
  811. [[
  812. a
  813. abc
  814. 3
  815. ABC
  816. 3
  817. ]])
  818. AT_CLEANUP
  819. ## ----------- ##
  820. ## m4_append. ##
  821. ## ----------- ##
  822. AT_SETUP([m4@&t@_append])
  823. AT_KEYWORDS([m4@&t@_append_uniq m4@&t@_append_uniq_w])
  824. AT_CHECK_M4SUGAR_TEXT(
  825. [[m4_define([active], [ACTIVE])dnl
  826. m4_append([sentence], [This is an])dnl
  827. m4_append([sentence], [ active ])dnl
  828. m4_append([sentence], [symbol.])dnl
  829. sentence
  830. m4_undefine([active])dnl
  831. sentence
  832. m4_define([active], [ACTIVE])dnl
  833. m4_append([hooks], [m4_define([act1], [act2])])dnl
  834. m4_append([hooks], [m4_define([act2], [active])])dnl
  835. m4_undefine([active])dnl
  836. act1
  837. hooks
  838. act1
  839. dnl Test for bug fixed in 2.62 when separator is active.
  840. m4_define([a], [A])dnl
  841. m4_append_uniq([foo], [-], [a])dnl
  842. m4_append_uniq([foo], [-], [a])dnl
  843. m4_append_uniq([bar], [-], [a])dnl
  844. m4_append_uniq([bar], [~], [a])dnl
  845. m4_append_uniq([bar], [-], [a])dnl
  846. m4_defn([foo])
  847. m4_defn([bar])
  848. foo
  849. bar
  850. m4_append_uniq([blah], [one], [, ], [new], [existing])
  851. m4_append_uniq([blah], [two], [, ], [new], [existing])
  852. m4_append_uniq([blah], [two], [, ], [new], [existing])
  853. m4_append_uniq([blah], [three], [, ], [new], [existing])
  854. m4_append([blah], [two], [, ])dnl
  855. blah
  856. m4_dquote(blah)
  857. m4_append([list], [one], [[, ]])dnl
  858. m4_append([list], [two], [[, ]])dnl
  859. m4_append([list], [three], [[, ]])dnl
  860. list
  861. m4_dquote(list)
  862. m4_append_uniq_w([numbers], [1 1 2])dnl
  863. m4_append_uniq_w([numbers], [ 2 3 ])dnl
  864. numbers
  865. ]],
  866. [[This is an ACTIVE symbol.
  867. This is an active symbol.
  868. act1
  869. active
  870. -
  871. -a~
  872. -
  873. -A~
  874. new
  875. new
  876. existing
  877. new
  878. one, two, three, two
  879. [one],[two],[three],[two]
  880. one, two, three
  881. [one, two, three]
  882. 1 2 3
  883. ]])
  884. AT_DATA_M4SUGAR([script.4s],
  885. [[m4_init[]dnl
  886. m4_append_uniq([str], [a], [ ])
  887. m4_append_uniq([str], [a b], [ ])
  888. m4_divert([])dnl
  889. str
  890. ]])
  891. AT_CHECK_M4SUGAR([-o-], 0, [[a a b
  892. ]], [[script.4s:3: warning: m4@&t@_append_uniq: `a b' contains ` '
  893. ]])
  894. AT_CLEANUP
  895. ## --------- ##
  896. ## m4_join. ##
  897. ## --------- ##
  898. AT_SETUP([m4@&t@_join])
  899. AT_KEYWORDS([m4@&t@_joinall])
  900. AT_CHECK_M4SUGAR_TEXT(
  901. [[m4_define([active], [ACTIVE])
  902. m4_join
  903. m4_join([|])
  904. m4_join([, ], [one], [two])
  905. m4_dquote(m4_join([, ], [one], [two]))
  906. m4_join([|], [active], [active])
  907. m4_join([|], ,,,[one])
  908. m4_join([|], [one],,,)
  909. m4_join([], ,,,[two])
  910. m4_join([], [two],,,)
  911. m4_join([ active ], [one], , [two])
  912. m4_join([], [one], [two])
  913. m4_joinall([-], [one], [], [two])
  914. m4_joinall([-], [], [], [three], [], [])
  915. m4_joinall([], [one], [], [two])
  916. m4_joinall
  917. m4_joinall([-])
  918. m4_joinall([-], [one])
  919. ]],
  920. [[
  921. one, two
  922. [one, two]
  923. active|active
  924. one
  925. one
  926. two
  927. two
  928. one active two
  929. onetwo
  930. one--two
  931. --three--
  932. onetwo
  933. one
  934. ]])
  935. AT_CLEANUP
  936. ## ----------- ##
  937. ## m4_expand. ##
  938. ## ----------- ##
  939. AT_SETUP([m4@&t@_expand])
  940. AT_CHECK_M4SUGAR_TEXT(
  941. [[m4_define([active], [ACTIVE])dnl
  942. m4_expand([#active
  943. active])
  944. m4_expand([[active]])
  945. dnl properly quoted case statements
  946. m4_expand([case a in @%:@(
  947. *) echo active, ;;
  948. esac
  949. case b in
  950. *[)] echo active, ;;
  951. esac])
  952. dnl unbalanced underquoted `)', but we manage anyway (gasp!)
  953. m4_expand([case c in #(
  954. *) echo active, ;;
  955. esac
  956. case d in
  957. *) echo active, ;;
  958. esac])
  959. dnl unterminated comment/dnl
  960. m4_expand([active # active])
  961. m4_expand([a
  962. dnl])
  963. m4_expand([a
  964. -dnl])
  965. ]],
  966. [[#active
  967. ACTIVE
  968. active
  969. case a in #(
  970. *) echo ACTIVE, ;;
  971. esac
  972. case b in
  973. *) echo ACTIVE, ;;
  974. esac
  975. case c in #(
  976. *) echo ACTIVE, ;;
  977. esac
  978. case d in
  979. *) echo ACTIVE, ;;
  980. esac
  981. ACTIVE # active
  982. a
  983. a
  984. -
  985. ]])
  986. AT_CLEANUP
  987. ## ------------- ##
  988. ## m4_text_box. ##
  989. ## ------------- ##
  990. AT_SETUP([m4@&t@_text_box])
  991. AT_CHECK_M4SUGAR_TEXT([[
  992. m4_text_box([a $1 @&t@b])
  993. m4_text_box([a $1 @&t@b], [$])
  994. m4_text_box([a $1 @&t@b], [,])
  995. ]], [[
  996. ## ------ ##
  997. ## a $1 b ##
  998. ## ------ ##
  999. ## $$$$$$ ##
  1000. ## a $1 b ##
  1001. ## $$$$$$ ##
  1002. ## ,,,,,, ##
  1003. ## a $1 b ##
  1004. ## ,,,,,, ##
  1005. ]])
  1006. AT_CLEANUP
  1007. ## -------------- ##
  1008. ## m4_text_wrap. ##
  1009. ## -------------- ##
  1010. AT_SETUP([m4@&t@_text_wrap])
  1011. AT_KEYWORDS([m4@&t@_escape])
  1012. # m4_text_wrap is used to display the help strings. Also, check that
  1013. # commas and $ are not swallowed. This can easily happen because of
  1014. # m4-listification.
  1015. AT_DATA_M4SUGAR([script.4s],
  1016. [[m4_init[]m4_divert([])dnl
  1017. m4_define([a], [OOPS])dnl
  1018. m4_escape([a[b $c#]d])
  1019. m4_if(m4_escape([a[b $c#]d]), [a[b $c#]d], [oops],
  1020. m4_escape([a[b $c#]d]), [a@<:@b @S|@c@%:@@:>@d], [pass], [oops])
  1021. m4_text_wrap([Short string */], [ ], [/* ], 20)
  1022. m4_text_wrap([Much longer string */], [ ], [/* ], 20)
  1023. m4_text_wrap([Short doc.], [ ], [ --short ], 30)
  1024. m4_text_wrap([Short doc.], [ ], [ --too-wide], 30)
  1025. m4_text_wrap([Super long documentation.], [ ], [ --too-wide], 30)
  1026. m4_text_wrap([First, second , third, [,quoted space]])
  1027. m4_define([xfff], [oops])
  1028. m4_text_wrap([Some $1 $2 $3 $4 embedded dollars.], [ $* ], [ $@ ], [0xfff & 20])
  1029. ]])
  1030. AT_DATA([expout],
  1031. [[a[b $c#]d
  1032. pass
  1033. /* Short string */
  1034. /* Much longer
  1035. string */
  1036. --short Short doc.
  1037. --too-wide
  1038. Short doc.
  1039. --too-wide
  1040. Super long
  1041. documentation.
  1042. First, second , third, [,quoted space]
  1043. $@ Some $1 $2 $3
  1044. $* $4 embedded
  1045. $* dollars.
  1046. ]])
  1047. AT_CHECK_M4SUGAR([-o-], 0, [expout])
  1048. AT_CLEANUP
  1049. ## -------------------- ##
  1050. ## m4_version_compare. ##
  1051. ## -------------------- ##
  1052. AT_SETUP([m4@&t@_version_compare])
  1053. AT_KEYWORDS([m4@&t@_list_cmp])
  1054. AT_CHECK_M4SUGAR_TEXT(
  1055. [[m4_version_compare([1.1], [2.0])
  1056. m4_version_compare([2.0b], [2.0a])
  1057. m4_version_compare([2.0z], [2.0y])
  1058. m4_version_compare([1.1.1], [1.1.1a])
  1059. m4_version_compare([1.2], [1.1.1a])
  1060. m4_version_compare([1.0], [1])
  1061. m4_version_compare([1.0a], [1.0a])
  1062. m4_version_compare([1.1a], [1.1a.1])
  1063. m4_version_compare([1.10], [1.1a])
  1064. m4_version_compare([1-1a], [1,1A])
  1065. m4_define([a], [oops])dnl
  1066. m4_version_compare([1.1a], [1.1A])
  1067. m4_version_compare([1z], [1aa])
  1068. m4_version_compare([2.61a], [2.61a-248-dc51])
  1069. m4_version_compare([2.61b], [2.61a-248-dc51])
  1070. m4_version_compare([08], [09])
  1071. m4_version_compare([010], [8])
  1072. dnl Test that side effects to m4_list_cmp occur exactly once
  1073. m4_list_cmp([[0], [0], [0]m4_errprintn([hi])],
  1074. [[0], [0], [0]m4_errprintn([hi])])
  1075. m4_list_cmp([[0], [0], [0]m4_errprintn([hi])],
  1076. [[0], [0], [0]m4_errprintn([bye])])
  1077. ]],
  1078. [[-1
  1079. 1
  1080. 1
  1081. -1
  1082. 1
  1083. 0
  1084. 0
  1085. -1
  1086. 1
  1087. 0
  1088. 0
  1089. -1
  1090. -1
  1091. 1
  1092. -1
  1093. 1
  1094. 0
  1095. 0
  1096. ]], [[hi
  1097. hi
  1098. hi
  1099. bye
  1100. ]])
  1101. AT_CLEANUP
  1102. ## ------------------------------ ##
  1103. ## Standard regular expressions. ##
  1104. ## ------------------------------ ##
  1105. AT_SETUP([Standard regular expressions])
  1106. # AT_CHECK_M4RE(RE-NAME, TEXT, INTENT = `ok' | `')
  1107. # ------------------------------------------------
  1108. # Check whether RE-NAME (a macro whose definition is a regular expression)
  1109. # matches TEXT. INTENT = `ok' if the match should succeed or else empty.
  1110. m4_define([AT_CHECK_M4RE],
  1111. [AT_CHECK_M4SUGAR_TEXT(
  1112. [[m4_bregexp([$2], ^m4_defn([$1])$, [ok])
  1113. ]], [$3
  1114. ])])
  1115. AT_CHECK_M4RE([m4_re_word], [ab9_c], [ok])
  1116. AT_CHECK_M4RE([m4_re_word], [_9abc], [ok])
  1117. AT_CHECK_M4RE([m4_re_word], [9ab_c])
  1118. AT_CHECK_M4RE([m4_re_string], [ab9_c], [ok])
  1119. AT_CHECK_M4RE([m4_re_string], [_9abc], [ok])
  1120. AT_CHECK_M4RE([m4_re_string], [9ab_c], [ok])
  1121. AT_CHECK_M4RE([m4_re_string], [9a@_c])
  1122. AT_CLEANUP
  1123. ## ----------- ##
  1124. ## m4_bmatch. ##
  1125. ## ----------- ##
  1126. AT_SETUP([m4@&t@_bmatch])
  1127. AT_CHECK_M4SUGAR_TEXT(
  1128. [[m4_bmatch([abc], [default\])
  1129. m4_bmatch([abc], [^a], [yes])
  1130. m4_bmatch([abc], [^a], [yes], [no])
  1131. m4_bmatch([abc], [^.a], [yes])
  1132. m4_bmatch([abc], [^.a], [yes], [no\])
  1133. m4_bmatch([abc], [a], [1], [b], [2])
  1134. m4_bmatch([abc], [A], [1], [b], [2])
  1135. m4_define([ab], [AB])dnl
  1136. m4_bmatch([$*], [a])b
  1137. m4_bmatch([$*], [\*], [a])b
  1138. m4_bmatch([$*], [1], [2], [a])b
  1139. ]], [[default\
  1140. yes
  1141. yes
  1142. no\
  1143. 1
  1144. 2
  1145. AB
  1146. AB
  1147. AB
  1148. ]])
  1149. AT_CLEANUP
  1150. ## ------------------------ ##
  1151. ## m4_toupper, m4_tolower. ##
  1152. ## ------------------------ ##
  1153. AT_SETUP([m4@&t@_toupper and m4@&t@_tolower])
  1154. AT_CHECK_M4SUGAR_TEXT(
  1155. [[m4_define([abc], [hI])m4_define([ABC], [Hi])
  1156. m4_toupper(abc aBc ABC)
  1157. m4_tolower(abc aBc ABC)
  1158. m4_toupper([abc aBc ABC])
  1159. m4_tolower([abc aBc ABC])
  1160. m4_echo(m4_toupper(abc aBc ABC))
  1161. m4_echo(m4_tolower(abc aBc ABC))
  1162. m4_echo(m4_toupper([abc aBc ABC]))
  1163. m4_echo(m4_tolower([abc aBc ABC]))
  1164. m4_do(m4_toupper(abc aBc ABC))
  1165. m4_do(m4_tolower(abc aBc ABC))
  1166. m4_do(m4_toupper([abc aBc ABC]))
  1167. m4_do(m4_tolower([abc aBc ABC]))
  1168. ]], [[
  1169. HI ABC HI
  1170. hi abc hi
  1171. ABC ABC ABC
  1172. abc abc abc
  1173. HI ABC HI
  1174. hi abc hi
  1175. ABC ABC ABC
  1176. abc abc abc
  1177. HI Hi HI
  1178. hi hI hi
  1179. Hi Hi Hi
  1180. hI hI hI
  1181. ]])
  1182. AT_CLEANUP
  1183. ## --------------- ##
  1184. ## m4_bpatsubsts. ##
  1185. ## --------------- ##
  1186. AT_SETUP([m4@&t@_bpatsubsts])
  1187. AT_CHECK_M4SUGAR_TEXT(
  1188. [[m4_bpatsubsts([11], [^..$])
  1189. m4_bpatsubsts([11], [\(.\)1], [\12])
  1190. m4_bpatsubsts([11], [^..$], [], [1], [2])
  1191. m4_bpatsubsts([11], [\(.\)1], [\12], [1], [3])
  1192. m4_define([a], [oops])m4_define([c], [oops])dnl
  1193. m4_define([AB], [good])m4_define([bc], [good])dnl
  1194. m4_bpatsubsts([abc], [a], [A], [b], [B], [c])
  1195. m4_bpatsubsts([ab], [a])c
  1196. m4_bpatsubsts([ab], [c], [C], [a])c
  1197. m4_bpatsubsts([$1$*$@], [\$\*], [$#])
  1198. ]], [[11
  1199. 21
  1200. 22
  1201. 23
  1202. good
  1203. good
  1204. good
  1205. $1$#$@
  1206. ]])
  1207. AT_CLEANUP
  1208. ## -------------- ##
  1209. ## m4_esyscmd_s. ##
  1210. ## -------------- ##
  1211. AT_SETUP([m4@&t@_esyscmd_s])
  1212. AT_KEYWORDS([m4@&t@_chomp m4@&t@_chomp_all])
  1213. AT_CHECK_M4SUGAR_TEXT(
  1214. [[m4_define([world], [WORLD])dnl
  1215. m4_chomp([abc])
  1216. m4_chomp([world
  1217. ])
  1218. m4_esyscmd_s([echo hello world])
  1219. m4_esyscmd_s([echo '[goodbye,
  1220. cruel world
  1221. ]'])
  1222. ]], [[abc
  1223. world
  1224. hello WORLD
  1225. goodbye,
  1226. cruel world
  1227. ]])
  1228. AT_CLEANUP
  1229. ## ---------- ##
  1230. ## M4 Loops. ##
  1231. ## ---------- ##
  1232. AT_SETUP([M4 loops])
  1233. AT_KEYWORDS([m4@&t@_for m4@&t@_foreach m4@&t@_foreach_w m4@&t@_map_args_w])
  1234. AT_CHECK_M4SUGAR_TEXT([[dnl
  1235. m4_define([myvar], [outer value])dnl
  1236. m4_for([myvar], 1, 3, 1, [ myvar])
  1237. m4_for([myvar], 1, 3, , [ myvar])
  1238. m4_for([myvar], 3, 1,-1, [ myvar])
  1239. m4_for([myvar], 3, 1, , [ myvar])
  1240. m4_for([myvar], 1, 3, 2, [ myvar])
  1241. m4_for([myvar], 3, 1,-2, [ myvar])
  1242. m4_for([myvar],-1,-3,-2, [ myvar])
  1243. m4_for([myvar],-3,-1, 2, [ myvar])
  1244. dnl Make sure we recalculate the bounds correctly:
  1245. m4_for([myvar], 1, 3, 3, [ myvar])
  1246. m4_for([myvar], 1, 6, 3, [ myvar])
  1247. m4_for([myvar],22,-7,-5, [ myvar])
  1248. m4_for([myvar],-2,-7,-4, [ myvar])
  1249. m4_for([myvar],-7,-2, 4, [ myvar])
  1250. dnl Make sure we are not exposed to division truncation:
  1251. m4_for([myvar], 2, 5, 2, [ myvar])
  1252. m4_for([myvar],-5,-2, 2, [ myvar])
  1253. m4_for([myvar], 5, 2,-2, [ myvar])
  1254. m4_for([myvar],-2,-5,-2, [ myvar])
  1255. dnl Make sure we do not divide by zero:
  1256. m4_for([myvar], 1, 1, , [ myvar])
  1257. m4_for([myvar], 1, 1,+2, [ myvar])
  1258. m4_for([myvar], 1, 1,-2, [ myvar])
  1259. dnl Make sure we do not loop endlessly
  1260. m4_for([myval], 1, 1, 0, [ myval])
  1261. dnl Make sure to properly parenthesize
  1262. m4_for([myvar], 3-5, -2+8, , [ myvar])
  1263. m4_for([myvar], -2+8, 3-5, , [ myvar])
  1264. m4_for([myvar], 8, 16, 3 * 2, [ myvar])
  1265. m4_for([myvar], 8, 16, -3 * -2, [ myvar])
  1266. m4_for([myvar], [2<<2], [2<<3], [-3 * (-2)], [ myvar])
  1267. dnl Modifying var does not affect the number of iterations
  1268. m4_for([myvar], 1, 5, , [ myvar[]m4_define([myvar], 5)])
  1269. dnl Make sure we can do nameless iteration
  1270. m4_for(, 1, 10, , -)
  1271. dnl foreach tests
  1272. m4_foreach([myvar], [[a], [b, c], [d], [e
  1273. ],[f]], [ myvar|])
  1274. m4_foreach_w([myvar], [a b c, d,e f
  1275. g], [ myvar|])
  1276. myvar
  1277. m4_map_args_w([a b c, d,e f
  1278. g], [ ], [|])
  1279. m4_map_args_w([a b], [\1], [/])
  1280. m4_define([dashes], [--])dnl
  1281. m4_map_args_w([a b c], [/], [\1], [dashes])
  1282. dnl only one side effect expansion, prior to visiting list elements
  1283. m4_foreach([i], [[1], [2], [3]m4_errprintn([hi])], [m4_errprintn(i)])dnl
  1284. dnl shifting forms an important part of loops
  1285. m4_shift3:m4_shift3(1,2,3):m4_shift3(1,2,3,4)
  1286. m4_shiftn(3,1,2,3):m4_shiftn(3,1,2,3,4)
  1287. ]],
  1288. [[ 1 2 3
  1289. 1 2 3
  1290. 3 2 1
  1291. 3 2 1
  1292. 1 3
  1293. 3 1
  1294. -1 -3
  1295. -3 -1
  1296. 1
  1297. 1 4
  1298. 22 17 12 7 2 -3
  1299. -2 -6
  1300. -7 -3
  1301. 2 4
  1302. -5 -3
  1303. 5 3
  1304. -2 -4
  1305. 1
  1306. 1
  1307. 1
  1308. 1
  1309. -2 -1 0 1 2 3 4 5 6
  1310. 6 5 4 3 2 1 0 -1 -2
  1311. 8 14
  1312. 8 14
  1313. 8 14
  1314. 1 2 3 4 5
  1315. ----------
  1316. a| b, c| d| e
  1317. | f|
  1318. a| b| c,| d,e| f| g|
  1319. outer value
  1320. a| b| c,| d,e| f| g|
  1321. \1a/\1b/
  1322. /a\1--/b\1--/c\1
  1323. ::4
  1324. :4
  1325. ]], [[hi
  1326. 1
  1327. 2
  1328. 3
  1329. ]])
  1330. dnl bounds checking in m4_for
  1331. AT_DATA_M4SUGAR([script.4s],
  1332. [[m4_init
  1333. m4_divert([0])dnl
  1334. m4_for([myvar], 1, 3,-1, [ myvar])
  1335. ]])
  1336. AT_CHECK_M4SUGAR([], 1, [],
  1337. [[script.4s:3: error: assert failed: -1 > 0
  1338. script.4s:3: the top level
  1339. autom4te: m4 failed with exit status: 1
  1340. ]])
  1341. AT_DATA_M4SUGAR([script.4s],
  1342. [[m4_init
  1343. m4_divert([0])dnl
  1344. m4_for([myvar], 1, 2, 0, [ myvar])
  1345. ]])
  1346. AT_CHECK_M4SUGAR([], 1, [],
  1347. [[script.4s:3: error: assert failed: 0 > 0
  1348. script.4s:3: the top level
  1349. autom4te: m4 failed with exit status: 1
  1350. ]])
  1351. AT_DATA_M4SUGAR([script.4s],
  1352. [[m4_init
  1353. m4_divert([0])dnl
  1354. m4_for([myvar], 2, 1, 0, [ myvar])
  1355. ]])
  1356. AT_CHECK_M4SUGAR([], 1, [],
  1357. [[script.4s:3: error: assert failed: 0 < 0
  1358. script.4s:3: the top level
  1359. autom4te: m4 failed with exit status: 1
  1360. ]])
  1361. dnl m4_shiftn also does bounds checking
  1362. AT_DATA_M4SUGAR([script.4s],
  1363. [[m4_init
  1364. m4_divert([0])dnl
  1365. m4_shiftn(3,1,2)
  1366. ]])
  1367. AT_CHECK_M4SUGAR([], 1, [],
  1368. [[script.4s:3: error: assert failed: 0 < 3 && 3 < 3
  1369. script.4s:3: the top level
  1370. autom4te: m4 failed with exit status: 1
  1371. ]])
  1372. AT_CLEANUP
  1373. ## --------------------- ##
  1374. ## m4_map{,all}{,_sep}. ##
  1375. ## --------------------- ##
  1376. AT_SETUP([m4@&t@_map])
  1377. AT_KEYWORDS([m4@&t@_apply m4@&t@_map_sep m4@&t@_mapall m4@&t@_mapall_sep])
  1378. AT_KEYWORDS([m4@&t@_count])
  1379. AT_CHECK_M4SUGAR_TEXT([[dnl
  1380. m4_map([m4_count], [])
  1381. m4_map([ m4_count], [[],
  1382. [[1]],
  1383. [[1], [2]]])
  1384. m4_mapall([ m4_count], [[],
  1385. [[1]],
  1386. [[1], [2]]])
  1387. m4_map_sep([m4_eval], [,], [[[1+2]],
  1388. [[10], [16]]])
  1389. m4_count(m4_map_sep([m4_echo], [,], [[], [[1]], [[2]]]))
  1390. m4_count(m4_mapall_sep([m4_echo], [,], [[], [[1]], [[2]]]))
  1391. m4_map_sep([m4_eval], [[,]], [[[1+2]],
  1392. [[10], [16]]])
  1393. m4_count(m4_map_sep([m4_echo], [[,]], [[], [[1]], [[2]]]))
  1394. m4_count(m4_mapall_sep([m4_echo], [[,]], [[], [[1]], [[2]]]))
  1395. m4_map([-], [[]])
  1396. m4_mapall([-], [[]])
  1397. m4_map_sep([-], [:], [[]])
  1398. m4_mapall_sep([-], [:], [[]])
  1399. m4_define([a], [m4_if([$#], [0], [oops], [$1], [a], [pass], [oops])])dnl
  1400. m4_define([a1], [oops])dnl
  1401. m4_define([pass1], [oops])dnl
  1402. m4_map([a], [[[a]]])1
  1403. m4_map([m4_unquote([a])], [m4_dquote([a])])
  1404. dnl only one side effect expansion, prior to visiting list elements
  1405. m4_map([m4_errprintn], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
  1406. m4_map_sep([m4_errprintn], [], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
  1407. m4_mapall([m4_errprintn], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
  1408. m4_mapall_sep([m4_errprintn], [], [[[1]], [[2]], [[3]]m4_errprintn([hi])])dnl
  1409. ]],
  1410. [[
  1411. 1 2
  1412. 0 1 2
  1413. 3,a
  1414. 2
  1415. 3
  1416. 3,a
  1417. 1
  1418. 1
  1419. -
  1420. -
  1421. pass1
  1422. pass
  1423. ]], [[hi
  1424. 1
  1425. 2
  1426. 3
  1427. hi
  1428. 1
  1429. 2
  1430. 3
  1431. hi
  1432. 1
  1433. 2
  1434. 3
  1435. hi
  1436. 1
  1437. 2
  1438. 3
  1439. ]])
  1440. AT_CLEANUP
  1441. ## --------------------------------------- ##
  1442. ## m4_map_args{,_sep,_pair} and m4_curry. ##
  1443. ## --------------------------------------- ##
  1444. AT_SETUP([m4@&t@_map_args and m4@&t@_curry])
  1445. AT_KEYWORDS([m4@&t@_map_args_sep m4@&t@_map_args_pair m4@&t@_reverse
  1446. m4@&t@_map])
  1447. dnl First, make sure we can curry in isolation.
  1448. AT_CHECK_M4SUGAR_TEXT(
  1449. [[m4_curry([m4_echo])([1])
  1450. m4_curry([m4_curry], [m4_reverse], [1])([2])([3])
  1451. m4_define([add], [m4_eval(([$1]) + ([$2]))])dnl
  1452. m4_define([add_one], [m4_curry([add], [1])])dnl
  1453. add_one()([4])
  1454. ]],
  1455. [[1
  1456. 3, 2, 1
  1457. 5
  1458. ]])
  1459. dnl Now, check that we can map a list of arguments.
  1460. AT_CHECK_M4SUGAR_TEXT([[m4_define([active], [ACTIVE])dnl
  1461. m4_map_args([ m4_echo])
  1462. m4_map_args([ m4_echo], [plain], [active])
  1463. m4_map_args([m4_unquote], [plain], [active])
  1464. m4_map_args_pair([, m4_reverse], [])
  1465. m4_map_args_pair([, m4_reverse], [], [1])
  1466. m4_map_args_pair([, m4_reverse], [], [1], [2])
  1467. m4_map_args_pair([, m4_reverse], [], [1], [2], [3])
  1468. m4_map_args_pair([, m4_reverse], [], [1], [2], [3], [4])
  1469. m4_map_args_pair([, m4_reverse], [, m4_dquote], [1])
  1470. m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2])
  1471. m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3])
  1472. m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3], [4])
  1473. m4_map_args_sep([<], [>], [:], [1], [2], [3])
  1474. m4_map_args_sep([m4_echo(], [)], [ ], [plain], [active])
  1475. ]],
  1476. [[
  1477. plain active
  1478. plainACTIVE
  1479. , 1
  1480. , 2, 1
  1481. , 2, 1, 3
  1482. , 2, 1, 4, 3
  1483. , [1]
  1484. , 2, 1
  1485. , 2, 1, [3]
  1486. , 2, 1, 4, 3
  1487. <1>:<2>:<3>
  1488. plain active
  1489. ]])
  1490. dnl Finally, put the two concepts together, to show the real power of the API.
  1491. AT_CHECK_M4SUGAR_TEXT(
  1492. [[m4_define([add], [m4_eval(([$1]) + ([$2]))])dnl
  1493. m4_define([list], [[-1], [0], [1]])dnl
  1494. dnl list_add_n(value, arg...)
  1495. dnl add VALUE to each ARG and output the resulting list
  1496. m4_define([list_add_n],
  1497. [m4_shift(m4_map_args([,m4_curry([add], [$1])], m4_shift($@)))])
  1498. list_add_n([1], list)
  1499. list_add_n([2], list)
  1500. ]], [[
  1501. 0,1,2
  1502. 1,2,3
  1503. ]])
  1504. AT_CLEANUP
  1505. ## ------------ ##
  1506. ## m4_combine. ##
  1507. ## ------------ ##
  1508. AT_SETUP([m4@&t@_combine])
  1509. AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
  1510. m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
  1511. m4_combine([, ], [[a], [b]], [-])
  1512. m4_combine([, ], [[a], [b]], [-], [])
  1513. m4_combine([, ], [], [-], [a], [b])
  1514. m4_combine([, ], [[]], [-], [a], [b])
  1515. m4_combine([ a ], [[-], [+]], [a], [-], [+])
  1516. m4_combine([$* ], [[$1], [$2]], [$#], [$@])
  1517. ]],
  1518. [[a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
  1519. a-, b-
  1520. -a, -b
  1521. -a- a -a+ a +a- a +a+
  1522. $1$#$@$* $2$#$@
  1523. ]], [])
  1524. AT_CLEANUP
  1525. ## -------------- ##
  1526. ## m4_{max,min}. ##
  1527. ## -------------- ##
  1528. AT_SETUP([m4@&t@_max and m4@&t@_min])
  1529. AT_DATA_M4SUGAR([script.4s],
  1530. [[m4_max
  1531. ]])
  1532. AT_CHECK_M4SUGAR([], 1, [],
  1533. [[script.4s:1: error: too few arguments to m4@&t@_max
  1534. script.4s:1: the top level
  1535. autom4te: m4 failed with exit status: 1
  1536. ]])
  1537. AT_DATA_M4SUGAR([script.4s],
  1538. [[m4_min
  1539. ]])
  1540. AT_CHECK_M4SUGAR([], 1, [],
  1541. [[script.4s:1: error: too few arguments to m4@&t@_min
  1542. script.4s:1: the top level
  1543. autom4te: m4 failed with exit status: 1
  1544. ]])
  1545. AT_CHECK_M4SUGAR_TEXT([[dnl
  1546. m4_min(0)
  1547. m4_min(0xa)
  1548. m4_min(0, 0)
  1549. m4_min(0, 1)
  1550. m4_min(1, 0)
  1551. m4_min(0+1, 1+1)
  1552. m4_min(0+1, 1+0)
  1553. m4_min(0, 1, 2)
  1554. m4_min(2, 1, 0)
  1555. m4_min(1m4_for([i], 2, 100, , [,i]))
  1556. m4_min(m4_for([i], 100, 2, , [i,])1)
  1557. ----
  1558. m4_max(0)
  1559. m4_max(0xa)
  1560. m4_max(0, 0)
  1561. m4_max(0, 1)
  1562. m4_max(1, 0)
  1563. m4_max(1+0, 1+1)
  1564. m4_max(1+0, 1+0)
  1565. m4_max(0, 1, 2)
  1566. m4_max(2, 1, 0)
  1567. m4_max(1m4_for([i], 2, 100, , [,i]))
  1568. m4_max(m4_for([i], 100, 2, , [i,])1)
  1569. ]],
  1570. [[0
  1571. 10
  1572. 0
  1573. 0
  1574. 0
  1575. 1
  1576. 1
  1577. 0
  1578. 0
  1579. 1
  1580. 1
  1581. ----
  1582. 0
  1583. 10
  1584. 0
  1585. 1
  1586. 1
  1587. 2
  1588. 1
  1589. 2
  1590. 2
  1591. 100
  1592. 100
  1593. ]], [])
  1594. AT_CLEANUP
  1595. ## ----------- ##
  1596. ## Recursion. ##
  1597. ## ----------- ##
  1598. AT_SETUP([recursion])
  1599. AT_KEYWORDS([m4@&t@_foreach m4@&t@_foreach_w m4@&t@_case m4@&t@_cond
  1600. m4@&t@_bpatsubsts m4@&t@_shiftn m4@&t@_do m4@&t@_dquote_elt m4@&t@_reverse
  1601. m4@&t@_map m4@&t@_join m4@&t@_joinall m4@&t@_list_cmp m4@&t@_max m4@&t@_min
  1602. m4@&t@_bmatch m4@&t@_map_args m4@&t@_map_args_pair])
  1603. dnl This test completes in a reasonable time if m4_foreach is linear,
  1604. dnl but thrashes if it is quadratic. If we are testing with m4 1.4.x,
  1605. dnl only the slower foreach.m4 implementation will work. But if we
  1606. dnl are testing with m4 1.6, we can rerun the test with __m4_version__
  1607. dnl undefined to exercise the alternate code path.
  1608. AT_DATA_M4SUGAR([script.4s],
  1609. [[m4_init
  1610. m4_divert_push([])[]dnl
  1611. m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
  1612. m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
  1613. m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
  1614. m4_len(m4_joinall([--], m4_map([, m4_echo],
  1615. m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
  1616. m4_max(m4_min([1]m4_for([i], [2], [10000], [],
  1617. [,i]))m4_for([i], [2], [10000], [], [,i]))
  1618. m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
  1619. m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
  1620. m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
  1621. m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
  1622. m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
  1623. m4_for([i], [1], [10000], [], [m4_define(i)])dnl
  1624. m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
  1625. m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
  1626. m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
  1627. m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
  1628. m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
  1629. m4_count(m4_map_args_pair([,m4_quote], []m4_map_args([,m4_echo]m4_for([i],
  1630. [1], [10000], [], [,i]))))
  1631. m4_divert_pop([])
  1632. ]])
  1633. AT_CHECK_M4SUGAR([-o-], [0], [[48894
  1634. 9999,10000
  1635. 78896
  1636. 58894
  1637. 10000
  1638. end
  1639. 0
  1640. 0
  1641. 0
  1642. A
  1643. ^9998$
  1644. 9990 9990
  1645. 5001
  1646. ]])
  1647. AT_DATA_M4SUGAR([script.4s],
  1648. [[m4_ifdef([__m4_version__],
  1649. [m4_undefine([__m4_version__])],
  1650. [m4_divert_push([])48894
  1651. 9999,10000
  1652. 78896
  1653. 58894
  1654. 10000
  1655. end
  1656. 0
  1657. 0
  1658. 0
  1659. A
  1660. ^9998$
  1661. 9990 9990
  1662. 5001
  1663. m4_exit([0])])
  1664. m4_init
  1665. m4_divert_push([])[]dnl
  1666. m4_len(m4_foreach_w([j], m4_do(m4_for([i], [1], [10000], [], [,i ])), [j ]))
  1667. m4_shiftn(9998m4_for([i], [1], [10000], [], [,i]))
  1668. m4_len(m4_join([--],, m4_dquote_elt(m4_for([i], [1], [10000], [], [,i])),))
  1669. m4_len(m4_joinall([--], m4_map([, m4_echo],
  1670. m4_dquote([1]m4_for([i], [2], [10000], [], [,i])))))
  1671. m4_max(m4_min([1]m4_for([i], [2], [10000], [],
  1672. [,i]))m4_for([i], [2], [10000], [], [,i]))
  1673. m4_case([10000]m4_for([i], [1], [10000], [], [,i]),[end])
  1674. m4_list_cmp(m4_dquote(1m4_for([i], [2], [10000], [], [,i])),
  1675. m4_dquote(m4_reverse(10000m4_for([i], [9999], [1], [], [,i])), [0]))
  1676. m4_list_cmp([0], [0m4_for([i], [1], [10000], [], [,0])])
  1677. m4_list_cmp([0m4_for([i], [1], [10000], [], [,0])], [0])
  1678. m4_for([i], [1], [10000], [], [m4_define(i)])dnl
  1679. m4_undefine(1m4_for([i], [2], [10000], [], [,i]))dnl
  1680. m4_bpatsubsts([a1]m4_for([i], [1], [10000], [], [,i]), [a2], [A])
  1681. m4_bmatch([9997]m4_for([i], [1], [10000], [], [,^i$]))
  1682. m4_define([up], [m4_define([$1], m4_incr($1))$1])m4_define([j], 0)dnl
  1683. m4_cond(m4_for([i], [1], [10000], [], [[up([j])], [9990], i,]) [oops]) j
  1684. m4_count(m4_map_args_pair([,m4_quote], []m4_map_args([,m4_echo]m4_for([i],
  1685. [1], [10000], [], [,i]))))
  1686. m4_divert_pop([])
  1687. ]])
  1688. AT_CHECK_M4SUGAR([-o-], [0], [[48894
  1689. 9999,10000
  1690. 78896
  1691. 58894
  1692. 10000
  1693. end
  1694. 0
  1695. 0
  1696. 0
  1697. A
  1698. ^9998$
  1699. 9990 9990
  1700. 5001
  1701. ]])
  1702. AT_CLEANUP
  1703. ## ---------- ##
  1704. ## m4_set_*. ##
  1705. ## ---------- ##
  1706. AT_SETUP([m4@&t@_set])
  1707. AT_KEYWORDS([m4@&t@_set_add m4@&t@_set_add_all m4@&t@_set_contains
  1708. m4@&t@_set_contents m4@&t@_set_delete m4@&t@_set_difference m4@&t@_set_dump
  1709. m4@&t@_set_empty m4@&t@_set_foreach m4@&t@_set_intersection m4@&t@_set_list
  1710. m4@&t@_set_listc m4@&t@_set_map m4@&t@_set_remove m4@&t@_set_size
  1711. m4@&t@_set_union])
  1712. # Simple tests
  1713. AT_CHECK_M4SUGAR_TEXT([[m4_set_contains([a], [1], [yes], [no])
  1714. m4_set_add([a], [1], [added], [dup])
  1715. m4_set_contains([a], [1], [yes], [no])
  1716. m4_set_add([a], [1], [added], [dup])
  1717. m4_set_contents([a])
  1718. m4_set_remove([a], [1], [removed], [missing])
  1719. m4_set_contains([a], [1], [yes], [no])
  1720. m4_set_remove([a], [1], [removed], [missing])
  1721. m4_set_add([a], [2], [added], [dup])
  1722. m4_set_empty([a], [yes], [no])
  1723. m4_set_delete([a])
  1724. m4_set_empty([a], [yes], [no])
  1725. m4_set_add_all([c], [1], [2], [3])
  1726. m4_set_add_all([a]m4_set_listc([c]))
  1727. m4_set_contents([c], [-])
  1728. m4_set_dump([a], [-])
  1729. m4_set_contents([a])
  1730. m4_set_add_all([a], [1], [2], [3])m4_set_add_all([b], [3], [], [4])
  1731. m4_set_difference([a], [b])
  1732. m4_set_difference([b], [a])
  1733. m4_set_intersection([a], [b])
  1734. m4_set_union([a], [b])
  1735. m4_define([printodd], [m4_if(m4_eval([$1 & 1]), [1], [:$1])])dnl
  1736. m4_set_map([a], [printodd])
  1737. m4_set_foreach([a], [i], [m4_if(m4_eval(i & 1), [1], [m4_set_remove([a], i)])])
  1738. m4_set_list([a])
  1739. m4_set_add([a], [])
  1740. m4_set_list([a])
  1741. m4_set_remove([a], [2])
  1742. m4_dquote(m4_set_list([a]))
  1743. m4_set_listc([a])
  1744. m4_set_size([a])
  1745. m4_set_delete([a])
  1746. m4_dquote(m4_set_list([a]))
  1747. m4_indir([m4_dquote]m4_set_listc([a]))
  1748. m4_set_listc([a])
  1749. m4_set_size([a])
  1750. ]], [[no
  1751. added
  1752. yes
  1753. dup
  1754. 1
  1755. removed
  1756. no
  1757. missing
  1758. added
  1759. no
  1760. yes
  1761. 1-2-3
  1762. 3-2-1
  1763. ,1,2
  1764. ,,4
  1765. ,3
  1766. ,1,2,3,,4
  1767. :1:3
  1768. 2
  1769. 2,
  1770. []
  1771. ,
  1772. 1
  1773. []
  1774. 0
  1775. ]])
  1776. # Stress tests - check for unusual names/values
  1777. AT_CHECK_M4SUGAR_TEXT([[m4_define([a], [oops])dnl
  1778. m4_set_add([a], [a])dnl
  1779. m4_set_remove([a], [oops], [yes], [no])
  1780. m4_set_add([a,b], [c])dnl
  1781. m4_set_add([a,b], [$*[]])dnl
  1782. m4_set_add_all([a], [b,c])dnl
  1783. m4_set_size([a])
  1784. m4_count(m4_set_contents([a], [,]))
  1785. m4_count(m4_set_list([a], [,]))
  1786. m4_set_dump([a], [,])
  1787. m4_set_contents([a,b], [,])
  1788. m4_set_list([a,b])
  1789. m4_set_foreach([$*[]], [$*[]], [oops])
  1790. m4_set_add([$*[]], [])dnl
  1791. m4_set_remove([$*[]], [a], [yes], [no])
  1792. m4_set_add([$*[]], [a])dnl
  1793. m4_set_foreach([$*[]], [$*[]], [-m4_defn([$*[]])m4_indir([$*[]])-])
  1794. m4_set_remove([$*[]], [], [yes], [no])
  1795. m4_set_add([c], [,])dnl
  1796. m4_set_foreach([a,b], [set], [:m4_set_listc(_m4_defn([set])):])
  1797. ]],[[no
  1798. 2
  1799. 1
  1800. 2
  1801. b,c,a
  1802. c,$*[]
  1803. c,$*[]
  1804. no
  1805. ---aoops-
  1806. yes
  1807. :,,::,a:
  1808. ]])
  1809. # Stress tests - check for linear scaling (won't necessarily fail if
  1810. # quadratic, but hopefully users will complain if it appears to hang)
  1811. AT_CHECK_M4SUGAR_TEXT([[dnl
  1812. m4_for([i], [1], [10000], [], [m4_set_add([a], i)])dnl
  1813. m4_set_add_all([b]m4_for([i], [1], [10000], [], [,i]))dnl
  1814. m4_set_remove([a], [1])dnl
  1815. m4_set_remove([b], [10000])dnl
  1816. m4_set_add_all([a]m4_for([i], [1], [10000], [], [,i]))dnl
  1817. m4_for([i], [1], [10000], [], [m4_set_add([b], i)])dnl
  1818. m4_len(m4_set_contents([a]))
  1819. m4_len(m4_set_foreach([b], [b], [m4_if(m4_eval(b & 1), [1],
  1820. [m4_set_remove([b], b, [-])])]))
  1821. m4_set_size([b])
  1822. m4_define([prune3x], [m4_if(m4_eval([$1 % 3]), [0],
  1823. [m4_set_remove([a], [$1], [-])])])dnl
  1824. m4_len(m4_set_map([a], [prune3x]))
  1825. m4_count(m4_shift(m4_set_intersection([a], [b])))
  1826. ]], [[38894
  1827. 5000
  1828. 5000
  1829. 3333
  1830. 3334
  1831. ]])
  1832. AT_CLEANUP
  1833. ## ---------------------- ##
  1834. ## __file__ and __line__. ##
  1835. ## ---------------------- ##
  1836. AT_SETUP([[__file__ and __line__]])
  1837. # Check that __file__ and __line__ work.
  1838. # Check that m4__file__ and m4__line__ are not defined
  1839. # (and get them to pass by the undefined-macro check).
  1840. # Try to not assume too much about AT_CHECK_M4SUGAR_TEXT.
  1841. AT_CHECK_M4SUGAR_TEXT([[dnl
  1842. m4_pattern_allow([m4__file__])dnl
  1843. m4_pattern_allow([m4__line__])dnl
  1844. m4__file__
  1845. m4__line__
  1846. __file__
  1847. m4_define([first], __line__)dnl
  1848. m4_define([second], __line__)dnl
  1849. m4_assert(first + 1 == second)dnl
  1850. ]], [[m4@&t@__@&t@file__
  1851. m4@&t@__@&t@line__
  1852. script.4s
  1853. ]])
  1854. AT_CLEANUP