1 # Hand crafted tests for GNU M4. -*- Autotest -*-
2 # Copyright (C) 2001, 2006-2010, 2013-2014 Free Software Foundation,
5 # This file is part of GNU M4.
7 # GNU M4 is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # GNU M4 is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 AT_BANNER([Torturing builtins.])
27 AT_SETUP([__@&t@file__])
29 dnl Unfortunately, AT_DATA does not make it easy to create files without
30 dnl a trailing newline.
31 [echo $ECHO_N "__line"__:__"file__$ECHO_C"] > nested
38 dnl Make sure line numbers are consistent, even if include file does not
39 dnl end with a newline
40 AT_CHECK_M4([outer], [0],
53 AT_SETUP([__@&t@line__])
55 dnl Unfortunately, AT_DATA does not make it easy to create files without
56 dnl a trailing newline.
57 [echo $ECHO_N "__file"__:__"line__$ECHO_C"] > nested
64 dnl Make sure line numbers are consistent, even if include file does not
65 dnl end with a newline
66 AT_CHECK_M4([outer], [0],
79 AT_SETUP([__m4_@&t@version__])
81 AT_DATA([in], [[defn(`__m4_version__')
83 AT_CHECK_M4([--version], [0], [stdout])
84 AT_CHECK([[$SED -e 's/.*(GNU M4\(.*\)) \([^ ]*\).*/\2\1/;q' < stdout]],
87 AT_CHECK_M4([in], [0], [expout])
89 dnl Prove that __m4_version__ is unquoted, by making '.' an active character.
90 AT_DATA([in], [[changesyntax(`A.')define(`.', `errprint(`hi
94 AT_CHECK_M4([in], [0], [expout], [[hi
106 dnl This was a regression in 1.4.10b.
108 [[define(`s', `builtin(`shift', $@)')dnl
109 define(`loop', `ifelse(`$2', `', `-', `$1$2: $0(`$1', s(s($@)))')')dnl
113 loop(`1', `2', `3', `4')
114 loop(`1', `2', `3', `4', `5')
116 AT_CHECK_M4([in.m4], [0],
131 AT_SETUP([changequote])
134 [[define(`aaaaaaaaaaaaaaaaaaaa', `A')define(`q', `"$@"')
135 changequote(`"', `"')
136 q(q("aaaaaaaaaaaaaaaaaaaa", "a"))
137 changequote`'define(`echo', `$@')dnl
138 changequote(`<<<', `>>')dnl
142 AT_CHECK_M4([in.m4], [0], [[
157 AT_DATA([[debug.m4]],
158 [[define(`countdown', `$1 ifelse(eval($1 > 0), 1, `countdown(decr($1))', `Liftoff')')
172 [[m4trace: -1- countdown ... = `$1 ifelse(eval($1 > 0), 1, `countdown(decr($1))', `Liftoff')'
173 m4trace: -1- countdown(`2') -> `2 ifelse(eval(2 > 0), 1, `countdown(decr(2))', `Liftoff')'
174 m4trace: -1- countdown ... = `$1 ifelse(eval($1 > 0), 1, `countdown(decr($1))', `Liftoff')'
175 m4trace: -1- countdown(`1') -> `1 ifelse(eval(1 > 0), 1, `countdown(decr(1))', `Liftoff')'
176 m4trace: -1- countdown ... = `$1 ifelse(eval($1 > 0), 1, `countdown(decr($1))', `Liftoff')'
177 m4trace: -1- countdown(`0') -> `0 ifelse(eval(0 > 0), 1, `countdown(decr(0))', `Liftoff')'
180 AT_CHECK_M4([debug.m4], 0, expout, experr)
182 dnl Test a regression introduced 2008-05-08, fixed 2008-07-30.
183 AT_DATA([debug.m4], [[debugmode(`e')traceon(`ifelse')dnl
184 define(`e', `ifelse(`$1', `$2', `ifelse(`$1', `$2', `e(shift($@))')', `$2')')
188 AT_CHECK_M4([debug.m4], [0], [[
190 ]], [[m4trace: -1- ifelse -> ifelse(`1', `1', `e(shift(`1',`1',`a'))')
191 m4trace: -1- ifelse -> e(shift(`1',`1',`a'))
192 m4trace: -1- ifelse -> a
204 AT_DATA([[define.m4]],
205 [[undefine(`macro')dnl
206 pushdef(`macro', `base value')dnl
207 pushdef(`macro', `hello, world')dnl
208 pushdef(`macro', `top value')dnl
209 define(`macro', `new value')dnl
217 AT_CHECK_M4([define.m4], 0,
221 ]], [[m4:define.m4:1: warning: undefine: undefined macro 'macro'
224 AT_CHECK_M4([--traditional define.m4], 0,
228 ]], [[m4:define.m4:1: warning: undefine: undefined macro 'macro'
231 dnl check regression present 2008-02-22 to 2008-04-30.
232 AT_DATA([in.m4], [[define(`qq', ``$*;$@'')dnl
233 define(`foo', qq(`a', `b'))dnl
237 AT_CHECK_M4([in.m4], [0], [[a,b;a,b
241 dnl Check hashing performance.
242 AT_DATA([in.m4], [[include(`forloop3.m4')dnl
243 forloop(`i', `1', `10000', `define(`m'i, i)')m10000
244 forloop(`i', `1', `10000', `undefine(`m'i)')m10000
246 AT_CHECK_M4([-I "$abs_top_srcdir/doc/examples" in.m4], [0], [[10000
261 [[define(`e', `$@')define(`q', ``$@'')define(`u', `$*')
262 define(`cmp', `ifelse($1, $2, `yes', `no')')define(`d', defn(`defn'))
263 cmp(`defn(`defn')', `defn(`d')')
264 cmp(`defn(`defn')', ``<defn>'')
265 cmp(`q(defn(`defn'))', `q(defn(`d'))')
266 cmp(`q(defn(`defn'))', `q(`<defn>')')
267 cmp(`q(defn(`defn'))', ``'')
268 cmp(`q(`1', `2', defn(`defn'))', `q(`1', `2', defn(`d'))')
269 cmp(`q(`1', `2', defn(`defn'))', `q(`1', `2', `<defn>')')
270 cmp(`q(`1', `2', defn(`defn'))', ```1',`2',<defn>'')
271 cmp(`q(`1', `2', defn(`defn'))', ```1',`2',`''')
272 define(`cat', `$1`'ifelse(`$@%:@', `1', `', `$0(shift($@))')')
273 cat(`define(`foo',', defn(`divnum'), `)foo')
274 cat(e(`define(`bar',', defn(`divnum'), `)bar'))
275 m4wrap(`u('q(`cat(`define(`baz','', defn(`divnum'), ``)baz')')`)
279 AT_CHECK_M4([in.m4], [0], [[
306 AT_DATA([[divert.m4]],
307 [[divert(1)Text diverted a first time.
308 divert(0)undivert(1)dnl
309 divert(1)Text diverted a second time.
310 divert(0)undivert(1)dnl
313 AT_CHECK_M4([divert.m4], 0,
314 [[Text diverted a first time.
315 Text diverted a second time.
318 dnl Test second divert argument, added for m4 2.0
319 AT_DATA([in.m4], [[define(`echo',`$1')dnl
320 divert(`-1', `discarded without warning')
322 echo(` world'divert(divnum, `hello'))
325 AT_CHECK_M4([-s in.m4], [0], [[#line 4 "in.m4"
329 dnl Test large diversions, which were broken in m4 1.4.8-1.4.10.
330 dnl Hopefully $SED doesn't choke on the over-long second line.
331 AT_CHECK([echo 'divert(1)hi
332 format(%1000000d, 1)' | $M4 | $SED -n 1p], [0], [[hi
335 AT_DATA([in.m4], [M4_ONE_MEG_DEFN[divert(`2')f`'dnl
340 dnl Rather than open-code the 1 megabyte expected output, we reduce the
341 dnl size of testsuite by constructing it.
344 cat expout expout > expout2
345 cat expout2 expout2 > expout
346 cat expout expout > expout2
347 cat expout2 expout2 > expout
348 cat expout expout > expout2
349 cat expout2 expout2 > expout
350 cat expout expout > expout2
351 cat expout2 expout2 > expout
352 cat expout expout > expout2
353 cat expout2 expout2 > expout
354 cat expout expout > expout2
355 cat expout2 expout2 > expout
356 cat expout expout > expout2
357 cat expout2 expout2 > expout
358 cat expout expout > expout2
359 cat expout2 expout2 > expout
360 cat expout expout > expout2
361 cat expout2 expout2 > expout
362 cat expout expout > expout2 # 512 kilobytes
364 cat expout2 expout2 >> expout # 1 megabyte
365 echo goodbye >> expout
368 AT_CHECK_M4([in.m4], [0], [expout])
370 dnl Avoid quadratic copying time when transferring diversions; test
371 dnl both in-memory and diversions spilled to a file.
372 AT_DATA([in.m4], [[include(`forloop2.m4')dnl
373 divert(`1')format(`%10000s', `')dnl
374 forloop(`i', `1', `10000',
375 `divert(incr(i))undivert(i)')dnl
376 divert(`9001')format(`%1000000s', `')dnl
377 forloop(`i', `9001', `10000',
378 `divert(incr(i))undivert(i)')dnl
382 AT_CHECK_M4([-I "$abs_top_srcdir/doc/examples" in.m4])
393 dnl Unfortunately, AT_DATA does not make it easy to create files without
394 dnl a trailing newline.
395 [echo $ECHO_N "__file"__:__"line__ d""nl ignored$ECHO_C"] > nested
398 include(`nested') still ignored
401 __file__:__line__ include(`nested') ignored
407 dnl Make sure line numbers are consistent, even if include file does not
408 dnl end with a newline
409 AT_CHECK_M4([outer], [0],
412 outer:7 nested:1 outer:8
424 dnl Make sure that stderr and stdout are properly interleaved when directed
425 dnl to the same file.
426 AT_DATA([in], [[1dumpdef(`defn')3
428 AT_CHECK_M4([in], [0], [[13
431 AT_CHECK_M4([in 2>&1], [0], [[1defn: <defn>
444 dnl Make sure that stderr and stdout are properly interleaved when directed
445 dnl to the same file.
446 AT_DATA([in], [[1errprint(`2')3errprint(`
449 AT_CHECK_M4([in], [0], [[13
452 AT_CHECK_M4([in 2>&1], [0], [[123
465 AT_DATA([[esyscmd.m4]],
466 [[# Cannot use real hostname program because test would fail
467 define(`hostname', esyscmd(`echo www.gnu.org'))dnl
468 `hostname = >>'hostname`<<'
470 pushdef(`_tmp', `$1')_tmp(translit(esyscmd(`echo www.gnu.org'), `.', `,'))`'popdef(`_tmp'))dnl
471 `hostname = >>'hostname`<<'
474 AT_CHECK_M4([esyscmd.m4], 0,
475 [[# Cannot use real hostname program because test would fail
476 hostname = >>www.gnu.org
481 dnl Ensure that esyscmd does not inherit any unnecessary fds from trace.
482 AT_DATA([in.m4], [[esyscmd(`echo hi >&3')ifelse(sysval,
483 `0', `skipping: sh cannot detect closed fds
486 AT_CHECK_M4([3>&-], [0], [], [stderr], [in.m4])
488 AT_CHECK_M4([--debugfile=trace -tdnl 3>&-], [0], [], [experr], [in.m4])
489 AT_CHECK([cat trace], [0], [[m4trace: -1- dnl -> `'
492 dnl Ensure that esyscmd does not inherit any unnecessary fds from diversions.
493 AT_DATA([in.m4], [M4_ONE_MEG_DEFN[divert(`1')f
495 esyscmd(`echo hi >&3')divert
498 AT_CHECK_M4([3>&-], [0], [stdout-nolog], [experr], [in.m4])
499 AT_CHECK([$SED -ne '/./p' stdout], [0], [[hello
503 dnl Ensure that esyscmd does not inherit any unnecessary fds from input files.
504 AT_DATA([in.m4], [[hello esyscmd(`cat <&3')dnl
505 dnl this line should not be read by cat
508 AT_CHECK_M4([3>&-], [0], [[hello world
509 ]], [stderr], [in.m4])
511 AT_CHECK_M4([in.m4 3>&-], [0], [[hello world
522 dnl ensure that comparisons work regardless of reference chains in the middle
523 [[define(`e', `$@')define(`long', `01234567890123456789')
525 ifelse(long, `01234567890123456789', `yes', `no')
526 ifelse(`01234567890123456789', long, `yes', `no')
527 ifelse(long, `01234567890123456789-', `yes', `no')
528 ifelse(`01234567890123456789-', long, `yes', `no')
529 dnl through macro expansion
530 ifelse(e(long), `01234567890123456789', `yes', `no')
531 ifelse(`01234567890123456789', e(long), `yes', `no')
532 ifelse(e(long), `01234567890123456789-', `yes', `no')
533 ifelse(`01234567890123456789-', e(long), `yes', `no')
534 dnl concatenate macro expansion with unquoted characters
535 ifelse(-e(long), `-01234567890123456789', `yes', `no')
536 ifelse(-`01234567890123456789', -e(long), `yes', `no')
537 ifelse(-e(long), `-01234567890123456789-', `yes', `no')
538 ifelse(`-01234567890123456789-', -e(long), `yes', `no')
539 ifelse(-e(long)-, `-01234567890123456789-', `yes', `no')
540 ifelse(-`01234567890123456789-', -e(long)-, `yes', `no')
541 ifelse(-e(long)-, `-01234567890123456789', `yes', `no')
542 ifelse(`-01234567890123456789', -e(long)-, `yes', `no')
543 dnl concatenate macro expansion with quoted characters
544 ifelse(`-'e(long), `-01234567890123456789', `yes', `no')
545 ifelse(-`01234567890123456789', `-'e(long), `yes', `no')
546 ifelse(`-'e(long), `-01234567890123456789-', `yes', `no')
547 ifelse(`-01234567890123456789-', `-'e(long), `yes', `no')
548 ifelse(`-'e(long)`-', `-01234567890123456789-', `yes', `no')
549 ifelse(-`01234567890123456789-', `-'e(long)`-', `yes', `no')
550 ifelse(`-'e(long)`-', `-01234567890123456789', `yes', `no')
551 ifelse(`-01234567890123456789', `-'e(long)`-', `yes', `no')
586 AT_DATA([[include.m4]],
590 include(`incl-test.m4')
596 AT_DATA([[incl-test.m4]],
615 [[m4:include.m4:2: include: cannot open file 'NOFILE': No such file or directory
616 m4:include.m4:6: include: cannot open file 'NOFILE': No such file or directory
619 AT_CHECK_M4([include.m4], 1, expout, experr)
621 dnl make sure files are handled correctly even via builtin
624 AT_DATA([in], [[builtin(`include', `foo')dnl
627 AT_CHECK_M4([in], [0], [[bar
640 dnl This used to be quadratic, taking millions of comparisons,
641 dnl but should now operate in linear time with only several thousand checks.
642 AT_DATA([in], [M4_ONE_MEG_DEFN[dnl
643 index(substr(f, `0', `500000')-, substr(f, `0', `100000')-)
645 AT_CHECK_M4([in], [0], [[400000
648 dnl This validates that index is 8-bit safe.
649 AT_DATA([in], [[index(`1«2', `»')
654 AT_CHECK_M4([in], [0], [[-1
670 AT_DATA([[indir.m4]],
671 [[define(`%%$$##', `>>>$0<<< cnt $#')
673 # indir(`%%$$##', nonsense, nonsense)
674 indir(`%%$$##', nonsense, nonsense)
676 # indir(`indir', `%%$$##', nonsense)
677 indir(`indir', `%%$$##', nonsense)
679 # indir(`indir', `indir', `indir', `indir', `%%$$##')
680 indir(`indir', `indir', `indir', `indir', `%%$$##')
686 # indir(`%%$$##', nonsense, nonsense)
689 # indir(`indir', `%%$$##', nonsense)
692 # indir(`indir', `indir', `indir', `indir', `%%$$##')
696 AT_CHECK_M4([indir.m4], 0, expout)
707 dnl Ensure that spilled diversions are gracefully cleaned up
708 AT_DATA([in.m4], [M4_ONE_MEG_DEFN[divert(`1')f
711 AT_CHECK([rm -Rf tmpdir && mkdir tmpdir && test -d tmpdir])
714 AT_CHECK_M4([in.m4], [0])
715 AT_CHECK([rmdir tmpdir])
726 dnl Check that on error, the expansion is void
728 [[mkdtemp(`no_such_dir/m4-fooXXXXXX')
730 AT_CHECK_M4([in], [0], [[
731 ]], [[m4:in:1: warning: mkdtemp: cannot create directory from template 'no_such_dir/m4-fooXXXXXX': No such file or directory
734 dnl Check that umask has an effect. drws--S--T is okay.
736 [[translit(substr(esyscmd(`ls -ld 'mkdtemp(`m4-fooXXXXXX')), `0', `10'),
739 AT_CHECK([$M4 < in], [0], [[drwx------
741 AT_CHECK([umask 700; $M4 < in], [0], [[d---------
753 AT_KEYWORDS([maketemp])
755 dnl Check that on error, the expansion is void
757 [[mkstemp(`no_such_dir/m4-fooXXXXXX')
759 AT_CHECK_M4([in], [0], [[
760 ]], [[m4:in:1: warning: mkstemp: cannot create file from template 'no_such_dir/m4-fooXXXXXX': No such file or directory
763 dnl Check that extra X are appended, but not trailing NUL
764 AT_DATA([[in]], [[len(mkstemp(`m4-fooXXXXX'))
766 AT_CHECK_M4([in], [0], [[12
769 dnl Check that umask has an effect
771 [[substr(esyscmd(`ls -ld 'mkstemp(`m4-fooXXXXXX')), `0', `10')
773 AT_CHECK([$M4 < in], [0], [[-rw-------
775 AT_CHECK([umask 700; $M4 < in], [0], [[----------
778 dnl Check for Solaris compatibility of maketemp. Hopefully the pid is
779 dnl less than 20 decimal digits. Also check that --safer does not affect
780 dnl traditional behavior of maketemp, which is textual only.
785 maketemp(XXXXXXXXXXXXXXXXXXXXX)
786 maketemp(no_such_dir/XXXXXX)
788 dnl Abuse our knowledge of AT_CHECK_M4 so that we can get stderr filtering...
789 AT_CHECK_M4([-G -Q --safer], [0], [stdout], [],
790 [in& echo $! > pid; wait $!])
795 X`$SED -e 's/.*\(.\)$/\1/' pid`
796 X`echo "$pid" | $SED -e "s/.*/00000000000000000000&/" -e 's/.*\(.\{20\}$\)/\1/'`
797 no_such_dir/`echo "$pid" | $SED -e "s/.*/000000&/" -e 's/.*\(.\{6\}$\)/\1/'`
799 AT_CHECK([cat stdout], [0], [expout])
813 # forloop(i, from, to, stmt)
815 define(`forloop', `pushdef(`$1', `$2')_forloop(`$1', `$2', `$3', `$4')popdef(`$1')')
817 `$4`'ifelse($1, `$3', ,
818 `define(`$1', incr($1))_forloop(`$1', `$2', `$3', `$4')')')
820 forloop(`x', 1, 100, `2**x = mpeval(2**x)
865 2**40 = 1099511627776
866 2**41 = 2199023255552
867 2**42 = 4398046511104
868 2**43 = 8796093022208
869 2**44 = 17592186044416
870 2**45 = 35184372088832
871 2**46 = 70368744177664
872 2**47 = 140737488355328
873 2**48 = 281474976710656
874 2**49 = 562949953421312
875 2**50 = 1125899906842624
876 2**51 = 2251799813685248
877 2**52 = 4503599627370496
878 2**53 = 9007199254740992
879 2**54 = 18014398509481984
880 2**55 = 36028797018963968
881 2**56 = 72057594037927936
882 2**57 = 144115188075855872
883 2**58 = 288230376151711744
884 2**59 = 576460752303423488
885 2**60 = 1152921504606846976
886 2**61 = 2305843009213693952
887 2**62 = 4611686018427387904
888 2**63 = 9223372036854775808
889 2**64 = 18446744073709551616
890 2**65 = 36893488147419103232
891 2**66 = 73786976294838206464
892 2**67 = 147573952589676412928
893 2**68 = 295147905179352825856
894 2**69 = 590295810358705651712
895 2**70 = 1180591620717411303424
896 2**71 = 2361183241434822606848
897 2**72 = 4722366482869645213696
898 2**73 = 9444732965739290427392
899 2**74 = 18889465931478580854784
900 2**75 = 37778931862957161709568
901 2**76 = 75557863725914323419136
902 2**77 = 151115727451828646838272
903 2**78 = 302231454903657293676544
904 2**79 = 604462909807314587353088
905 2**80 = 1208925819614629174706176
906 2**81 = 2417851639229258349412352
907 2**82 = 4835703278458516698824704
908 2**83 = 9671406556917033397649408
909 2**84 = 19342813113834066795298816
910 2**85 = 38685626227668133590597632
911 2**86 = 77371252455336267181195264
912 2**87 = 154742504910672534362390528
913 2**88 = 309485009821345068724781056
914 2**89 = 618970019642690137449562112
915 2**90 = 1237940039285380274899124224
916 2**91 = 2475880078570760549798248448
917 2**92 = 4951760157141521099596496896
918 2**93 = 9903520314283042199192993792
919 2**94 = 19807040628566084398385987584
920 2**95 = 39614081257132168796771975168
921 2**96 = 79228162514264337593543950336
922 2**97 = 158456325028528675187087900672
923 2**98 = 316912650057057350374175801344
924 2**99 = 633825300114114700748351602688
925 2**100 = 1267650600228229401496703205376
929 AT_CHECK_M4([mpeval in], 0, expout)
939 AT_SETUP([multiquotes])
941 AT_DATA([[multiquotes.m4]],
944 changequote([``], [''])dnl
946 define(``foo'', ````FOO'''')dnl
948 changequote(``!'', ``!'')dnl
954 changequote(!>*>*>*>*>!, !<*<*<*<*<!)dnl five of each
955 >*>*>*>*>foo bar<*<*<*<*<
957 >*>*>*>*>*>*><*<*<*<*<*<*<
958 dumpdef(>*>*>*>*>foo<*<*<*<*<, >*>*>*>*>bar<*<*<*<*<)dnl
974 [[m4trace: -1- changequote(`[', `]') -> []
975 m4trace: -1- dnl -> []
976 m4trace: -1- changequote([``], ['']) -> ``''
977 m4trace: -1- dnl -> ``''
978 m4trace: -1- define(``foo'', ````FOO'''') -> ``''
979 m4trace: -1- dnl -> ``''
981 m4trace: -1- dumpdef(``foo'') -> ``''
982 m4trace: -1- dnl -> ``''
983 m4trace: -1- changequote(``!'', ``!'') -> !!
984 m4trace: -1- dnl -> !!
985 m4trace: -1- foo -> !``FOO''!
987 m4trace: -1- dumpdef(!foo!) -> !!
988 m4trace: -1- dnl -> !!
989 m4trace: -1- define(!bar!, !BAR!) -> !!
990 m4trace: -1- bar -> !BAR!
991 m4trace: -1- changequote(!>*>*>*>*>!, !<*<*<*<*<!) -> >*>*>*>*><*<*<*<*<
992 m4trace: -1- dnl -> >*>*>*>*><*<*<*<*<
993 m4trace: -1- foo -> >*>*>*>*>``FOO''<*<*<*<*<
994 m4trace: -1- bar -> >*>*>*>*>BAR<*<*<*<*<
995 bar: >*>*>*>*>BAR<*<*<*<*<
996 foo: >*>*>*>*>``FOO''<*<*<*<*<
997 m4trace: -1- dumpdef(>*>*>*>*>foo<*<*<*<*<, >*>*>*>*>bar<*<*<*<*<) -> >*>*>*>*><*<*<*<*<
998 m4trace: -1- dnl -> >*>*>*>*><*<*<*<*<
1001 AT_CHECK_M4([multiquotes.m4], 0, expout, experr)
1011 AT_SETUP([patsubst])
1013 AT_DATA([[patsubst.m4]],
1014 [[# traceon(`patsubst')
1015 patsubst(`GNUs not Unix.', `^', `OBS: ')
1016 patsubst(`GNUs not Unix.', `\<', `OBS: ')
1017 patsubst(`GNUs not Unix.', `\<\w', `\&=')
1018 patsubst(`GNUs not Unix.', `\w*', `(\&)')
1019 patsubst(`GNUs not Unix.', `\w+', `(\&)')
1020 patsubst(`GNUs not Unix.', `\w+')
1021 patsubst(`GNUs not '` Unix.', `[ ]+', ` ')
1025 [[# traceon(`patsubst')
1027 OBS: GNUs OBS: not OBS: Unix.
1029 (GNUs)() (not)() (Unix)().()
1030 (GNUs) (not) (Unix).
1035 AT_CHECK_M4([patsubst.m4], 0, expout)
1047 AT_DATA([[regexp.m4]],
1048 [[traceon(`regexp')dnl
1049 regexp(`hej med dig', `.*', `>>\&<<')
1050 regexp(`hej med dig', `\w*', `>>\&<<')
1051 regexp(`hej med dig', `.+', `>>\&<<')
1052 regexp(`hej med dig', `m\w+', `>>\&<<')
1053 regexp(`hej med dig', `m\(.*\)', `>>\&<< >>\1<<')
1055 regexp(`hej med dig', `.*')
1056 regexp(`hej med dig', `\w*')
1057 regexp(`hej med dig', `.+')
1058 regexp(`hej med dig', `m\w+')
1059 regexp(`hej med dig', `m\(.*\)')
1067 >>med dig<< >>ed dig<<
1077 [[m4trace: -1- regexp(`hej med dig', `.*', `>>\&<<') -> `>>hej med dig<<'
1078 m4trace: -1- regexp(`hej med dig', `\w*', `>>\&<<') -> `>>hej<<'
1079 m4trace: -1- regexp(`hej med dig', `.+', `>>\&<<') -> `>>hej med dig<<'
1080 m4trace: -1- regexp(`hej med dig', `m\w+', `>>\&<<') -> `>>med<<'
1081 m4trace: -1- regexp(`hej med dig', `m\(.*\)', `>>\&<< >>\1<<') -> `>>med dig<< >>ed dig<<'
1082 m4trace: -1- regexp(`hej med dig', `.*') -> `0'
1083 m4trace: -1- regexp(`hej med dig', `\w*') -> `0'
1084 m4trace: -1- regexp(`hej med dig', `.+') -> `0'
1085 m4trace: -1- regexp(`hej med dig', `m\w+') -> `4'
1086 m4trace: -1- regexp(`hej med dig', `m\(.*\)') -> `4'
1089 AT_CHECK_M4([regexp.m4], 0, expout, experr)
1099 AT_SETUP([sync-lines])
1103 # Several input lines, expanding to one
1104 define(`foo', ``foo' line one.
1106 `foo' line three.') xyz
1108 # Several input lines, expanding to none
1109 define(`foo', ``foo' line one.
1111 `foo' line three.')dnl
1112 # one input line, expanding to several output lines
1116 AT_CHECK_M4([[in]], 0,
1118 # Several input lines, expanding to one
1126 # Several input lines, expanding to none
1128 # one input line, expanding to several output lines
1133 foo line three. foo line one.
1149 dnl Ensure that syscmd does not inherit any unnecessary fds from trace.
1150 AT_DATA([in.m4], [[syscmd(`echo hi >&3')ifelse(sysval,
1151 `0', `skipping: sh cannot detect closed fds
1154 AT_CHECK_M4([3>&-], [0], [], [stderr], [in.m4])
1156 AT_CHECK_M4([--debugfile=trace -tdnl 3>&-], [0], [], [experr], [in.m4])
1157 AT_CHECK([cat trace], [0], [[m4trace: -1- dnl -> `'
1160 dnl Ensure that syscmd does not inherit any unnecessary fds from diversions.
1161 AT_DATA([in.m4], [M4_ONE_MEG_DEFN[divert(`1')f
1163 syscmd(`echo hi >&3')divert
1166 AT_CHECK_M4([3>&-], [0], [stdout-nolog], [experr], [in.m4])
1167 AT_CHECK([$SED -ne '/./p' stdout], [0], [[hello
1171 dnl Ensure that syscmd does not inherit any unnecessary fds from input files.
1172 AT_DATA([in.m4], [[hello syscmd(`cat <&3')dnl
1173 dnl this line should not be read by cat
1176 AT_CHECK_M4([3>&-], [0], [[hello world
1177 ]], [stderr], [in.m4])
1179 AT_CHECK_M4([in.m4 3>&-], [0], [[hello world
1189 AT_SETUP([translit])
1191 AT_DATA([[translit.m4]],
1192 [[# traceon(`translit')dnl
1193 translit(`GNUs not Unix', `a-z')
1194 translit(`GNUs not Unix', `a-z', `A-Z')
1195 translit(`GNUs not Unix', `A-Z', `a-z')
1196 translit(`GNUs not Unix', `A-Z')
1197 translit(`a-z', `a-')
1198 translit(`A-Z', `A-Z-', `-A-Z')
1199 translit(`GNUs not Unix', `Z-A', `a-z')
1202 AT_CHECK_M4([translit.m4], 0,
1203 [[# traceon(`translit')dnl
1213 dnl This used to be quadratic, taking millions of comparisons,
1214 dnl but should now operate in linear time with only several thousand checks.
1215 AT_DATA([in], [M4_ONE_MEG_DEFN[dnl
1216 define(`a_', translit(substr(f, `0', `50000'), `
1218 define(`b_', translit(substr(f, `0', `50000'), `
1220 define(`d_', translit(substr(f, `0', `50000'), `
1222 define(`c'd_, `pass')dnl
1223 translit(`a'b_, a_`b', `c'd_)
1225 AT_CHECK_M4([in], [0], [[pass
1228 dnl This validates that ranges are built using unsigned chars.
1229 AT_DATA([in], [[translit(`«abc~', `~-»')
1231 AT_CHECK_M4([in], [0], [[abc
1234 dnl Validate short strings, which take a different code path.
1236 translit(`abcdeabcde', `a')
1237 translit(`abcdeabcde', `ab')
1238 translit(`abcdeabcde', `a', `f')
1239 translit(`abcdeabcde', `aa', `fg')
1240 translit(`abcdeabcde', `a', `fg')
1241 translit(`abcdeabcde', `ab', `f')
1242 translit(`abcdeabcde', `ab', `fg')
1243 translit(`abcdeabcde', `ab', `ba')
1244 translit(`abcdeabcde', `e', `f')
1245 translit(`abc', `', `cde')
1246 translit(`', `a', `bc')
1248 AT_CHECK_M4([in], [0], [[bcdebcde
1269 AT_SETUP([undivert])
1271 AT_DATA([[undivert.m4]],
1272 [[define(`undiverted', `UNDIVERTED')
1274 undivert(`undivert.incl')
1276 include(`undivert.incl')
1279 AT_DATA([[undivert.incl]],
1280 [[This is to be undiverted soon.
1283 AT_CHECK_M4([undivert.m4], 0,
1286 This is to be undiverted soon.
1289 This is to be UNDIVERTED soon.
1303 AT_DATA([[wrap.m4]],
1305 m4wrap(`Wrapper no. 1
1308 m4wrap(`Wrapper no. 2
1309 m4wrap(`Wrapper no. 3
1310 m4wrap(`Wrapper no. 4
1316 AT_CHECK_M4([wrap.m4], 0,