1 # Hand crafted tests for GNU M4. -*- Autotest -*-
2 # Copyright (C) 2001, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 # This file is part of GNU M4.
6 # GNU M4 is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # GNU M4 is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 AT_BANNER([Torturing builtins.])
26 AT_SETUP([__@&t@file__])
28 dnl Unfortunately, AT_DATA does not make it easy to create files without
29 dnl a trailing newline.
30 [echo $ECHO_N "__line"__:__"file__$ECHO_C"] > nested
37 dnl Make sure line numbers are consistent, even if include file does not
38 dnl end with a newline
39 AT_CHECK_M4([outer], [0],
52 AT_SETUP([__@&t@line__])
54 dnl Unfortunately, AT_DATA does not make it easy to create files without
55 dnl a trailing newline.
56 [echo $ECHO_N "__file"__:__"line__$ECHO_C"] > nested
63 dnl Make sure line numbers are consistent, even if include file does not
64 dnl end with a newline
65 AT_CHECK_M4([outer], [0],
78 AT_SETUP([__m4_@&t@version__])
80 AT_DATA([in], [[defn(`__m4_version__')
82 AT_CHECK_M4([--version], [0], [stdout])
83 AT_CHECK([[$SED -e 's/.*(GNU M4\(.*\)) \([^ ]*\).*/\2\1/;q' < stdout]],
86 AT_CHECK_M4([in], [0], [expout])
88 dnl Prove that __m4_version__ is unquoted, by making '.' an active character.
89 AT_DATA([in], [[changesyntax(`A.')define(`.', `errprint(`hi
93 AT_CHECK_M4([in], [0], [expout], [[hi
105 dnl This was a regression in 1.4.10b.
107 [[define(`s', `builtin(`shift', $@)')dnl
108 define(`loop', `ifelse(`$2', `', `-', `$1$2: $0(`$1', s(s($@)))')')dnl
112 loop(`1', `2', `3', `4')
113 loop(`1', `2', `3', `4', `5')
115 AT_CHECK_M4([in.m4], [0],
130 AT_SETUP([changequote])
133 [[define(`aaaaaaaaaaaaaaaaaaaa', `A')define(`q', `"$@"')
134 changequote(`"', `"')
135 q(q("aaaaaaaaaaaaaaaaaaaa", "a"))
136 changequote`'define(`echo', `$@')dnl
137 changequote(`<<<', `>>')dnl
141 AT_CHECK_M4([in.m4], [0], [[
156 AT_DATA([[debug.m4]],
157 [[define(`countdown', `$1 ifelse(eval($1 > 0), 1, `countdown(decr($1))', `Liftoff')')
171 [[m4trace: -1- countdown ... = `$1 ifelse(eval($1 > 0), 1, `countdown(decr($1))', `Liftoff')'
172 m4trace: -1- countdown(`2') -> `2 ifelse(eval(2 > 0), 1, `countdown(decr(2))', `Liftoff')'
173 m4trace: -1- countdown ... = `$1 ifelse(eval($1 > 0), 1, `countdown(decr($1))', `Liftoff')'
174 m4trace: -1- countdown(`1') -> `1 ifelse(eval(1 > 0), 1, `countdown(decr(1))', `Liftoff')'
175 m4trace: -1- countdown ... = `$1 ifelse(eval($1 > 0), 1, `countdown(decr($1))', `Liftoff')'
176 m4trace: -1- countdown(`0') -> `0 ifelse(eval(0 > 0), 1, `countdown(decr(0))', `Liftoff')'
179 AT_CHECK_M4([debug.m4], 0, expout, experr)
181 dnl Test a regression introduced 2008-05-08, fixed 2008-07-30.
182 AT_DATA([debug.m4], [[debugmode(`e')traceon(`ifelse')dnl
183 define(`e', `ifelse(`$1', `$2', `ifelse(`$1', `$2', `e(shift($@))')', `$2')')
187 AT_CHECK_M4([debug.m4], [0], [[
189 ]], [[m4trace: -1- ifelse -> ifelse(`1', `1', `e(shift(`1',`1',`a'))')
190 m4trace: -1- ifelse -> e(shift(`1',`1',`a'))
191 m4trace: -1- ifelse -> a
203 AT_DATA([[define.m4]],
204 [[undefine(`macro')dnl
205 pushdef(`macro', `base value')dnl
206 pushdef(`macro', `hello, world')dnl
207 pushdef(`macro', `top value')dnl
208 define(`macro', `new value')dnl
216 AT_CHECK_M4([define.m4], 0,
220 ]], [[m4:define.m4:1: Warning: undefine: undefined macro `macro'
223 AT_CHECK_M4([--traditional define.m4], 0,
227 ]], [[m4:define.m4:1: Warning: undefine: undefined macro `macro'
230 dnl check regression present 2008-02-22 to 2008-04-30.
231 AT_DATA([in.m4], [[define(`qq', ``$*;$@'')dnl
232 define(`foo', qq(`a', `b'))dnl
236 AT_CHECK_M4([in.m4], [0], [[a,b;a,b
251 [[define(`e', `$@')define(`q', ``$@'')define(`u', `$*')
252 define(`cmp', `ifelse($1, $2, `yes', `no')')define(`d', defn(`defn'))
253 cmp(`defn(`defn')', `defn(`d')')
254 cmp(`defn(`defn')', ``<defn>'')
255 cmp(`q(defn(`defn'))', `q(defn(`d'))')
256 cmp(`q(defn(`defn'))', `q(`<defn>')')
257 cmp(`q(defn(`defn'))', ``'')
258 cmp(`q(`1', `2', defn(`defn'))', `q(`1', `2', defn(`d'))')
259 cmp(`q(`1', `2', defn(`defn'))', `q(`1', `2', `<defn>')')
260 cmp(`q(`1', `2', defn(`defn'))', ```1',`2',<defn>'')
261 cmp(`q(`1', `2', defn(`defn'))', ```1',`2',`''')
262 define(`cat', `$1`'ifelse(`$@%:@', `1', `', `$0(shift($@))')')
263 cat(`define(`foo',', defn(`divnum'), `)foo')
264 cat(e(`define(`bar',', defn(`divnum'), `)bar'))
265 m4wrap(`u('q(`cat(`define(`baz','', defn(`divnum'), ``)baz')')`)
269 AT_CHECK_M4([in.m4], [0], [[
296 AT_DATA([[divert.m4]],
297 [[divert(1)Text diverted a first time.
298 divert(0)undivert(1)dnl
299 divert(1)Text diverted a second time.
300 divert(0)undivert(1)dnl
303 AT_CHECK_M4([divert.m4], 0,
304 [[Text diverted a first time.
305 Text diverted a second time.
308 dnl Test second divert argument, added for m4 2.0
309 AT_DATA([in.m4], [[define(`echo',`$1')dnl
310 divert(`-1', `discarded without warning')
312 echo(` world'divert(divnum, `hello'))
315 AT_CHECK_M4([-s in.m4], [0], [[#line 4 "in.m4"
319 dnl Test large diversions, which were broken in m4 1.4.8-1.4.10.
320 dnl Hopefully $SED doesn't choke on the over-long second line.
321 AT_CHECK([echo 'divert(1)hi
322 format(%1000000d, 1)' | $M4 | $SED -n 1p], [0], [[hi
325 AT_DATA([in.m4], [M4_ONE_MEG_DEFN[divert(`2')f`'dnl
330 dnl Rather than open-code the 1 megabyte expected output, we reduce the
331 dnl size of testsuite by constructing it.
334 cat expout expout > expout2
335 cat expout2 expout2 > expout
336 cat expout expout > expout2
337 cat expout2 expout2 > expout
338 cat expout expout > expout2
339 cat expout2 expout2 > expout
340 cat expout expout > expout2
341 cat expout2 expout2 > expout
342 cat expout expout > expout2
343 cat expout2 expout2 > expout
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 # 512 kilobytes
354 cat expout2 expout2 >> expout # 1 megabyte
355 echo goodbye >> expout
358 AT_CHECK_M4([in.m4], [0], [expout])
360 dnl Avoid quadratic copying time when transferring diversions; test
361 dnl both in-memory and diversions spilled to a file.
362 AT_DATA([in.m4], [[include(`forloop2.m4')dnl
363 divert(`1')format(`%10000s', `')dnl
364 forloop(`i', `1', `10000',
365 `divert(incr(i))undivert(i)')dnl
366 divert(`9001')format(`%1000000s', `')dnl
367 forloop(`i', `9001', `10000',
368 `divert(incr(i))undivert(i)')dnl
372 AT_CHECK_M4([-I "$top_srcdir/examples" in.m4])
383 dnl Unfortunately, AT_DATA does not make it easy to create files without
384 dnl a trailing newline.
385 [echo $ECHO_N "__file"__:__"line__ d""nl ignored$ECHO_C"] > nested
388 include(`nested') still ignored
391 __file__:__line__ include(`nested') ignored
397 dnl Make sure line numbers are consistent, even if include file does not
398 dnl end with a newline
399 AT_CHECK_M4([outer], [0],
402 outer:7 nested:1 outer:8
414 dnl Make sure that stderr and stdout are properly interleaved when directed
415 dnl to the same file.
416 AT_DATA([in], [[1dumpdef(`defn')3
418 AT_CHECK_M4([in], [0], [[13
421 AT_CHECK_M4([in 2>&1], [0], [[1defn: <defn>
434 dnl Make sure that stderr and stdout are properly interleaved when directed
435 dnl to the same file.
436 AT_DATA([in], [[1errprint(`2')3errprint(`
439 AT_CHECK_M4([in], [0], [[13
442 AT_CHECK_M4([in 2>&1], [0], [[123
455 AT_DATA([[esyscmd.m4]],
456 [[# Cannot use real hostname program because test would fail
457 define(`hostname', esyscmd(`echo www.gnu.org'))dnl
458 `hostname = >>'hostname`<<'
460 pushdef(`_tmp', `$1')_tmp(translit(esyscmd(`echo www.gnu.org'), `.', `,'))`'popdef(`_tmp'))dnl
461 `hostname = >>'hostname`<<'
464 AT_CHECK_M4([esyscmd.m4], 0,
465 [[# Cannot use real hostname program because test would fail
466 hostname = >>www.gnu.org
471 dnl Ensure that esyscmd does not inherit any unnecessary fds from trace.
472 AT_DATA([in.m4], [[esyscmd(`echo hi >&3')ifelse(sysval,
473 `0', `skipping: sh cannot detect closed fds
476 AT_CHECK_M4([3>&-], [0], [], [stderr], [in.m4])
478 AT_CHECK_M4([--debugfile=trace -tdnl 3>&-], [0], [], [experr], [in.m4])
479 AT_CHECK([cat trace], [0], [[m4trace: -1- dnl -> `'
482 dnl Ensure that esyscmd does not inherit any unnecessary fds from diversions.
483 AT_DATA([in.m4], [M4_ONE_MEG_DEFN[divert(`1')f
485 esyscmd(`echo hi >&3')divert
488 AT_CHECK_M4([3>&-], [0], [stdout-nolog], [experr], [in.m4])
489 AT_CHECK([$SED -ne '/./p' stdout], [0], [[hello
493 dnl Ensure that esyscmd does not inherit any unnecessary fds from input files.
494 AT_DATA([in.m4], [[hello esyscmd(`cat <&3')dnl
495 dnl this line should not be read by cat
498 AT_CHECK_M4([3>&-], [0], [[hello world
499 ]], [stderr], [in.m4])
501 AT_CHECK_M4([in.m4 3>&-], [0], [[hello world
512 dnl ensure that comparisons work regardless of reference chains in the middle
513 [[define(`e', `$@')define(`long', `01234567890123456789')
515 ifelse(long, `01234567890123456789', `yes', `no')
516 ifelse(`01234567890123456789', long, `yes', `no')
517 ifelse(long, `01234567890123456789-', `yes', `no')
518 ifelse(`01234567890123456789-', long, `yes', `no')
519 dnl through macro expansion
520 ifelse(e(long), `01234567890123456789', `yes', `no')
521 ifelse(`01234567890123456789', e(long), `yes', `no')
522 ifelse(e(long), `01234567890123456789-', `yes', `no')
523 ifelse(`01234567890123456789-', e(long), `yes', `no')
524 dnl concatenate macro expansion with unquoted characters
525 ifelse(-e(long), `-01234567890123456789', `yes', `no')
526 ifelse(-`01234567890123456789', -e(long), `yes', `no')
527 ifelse(-e(long), `-01234567890123456789-', `yes', `no')
528 ifelse(`-01234567890123456789-', -e(long), `yes', `no')
529 ifelse(-e(long)-, `-01234567890123456789-', `yes', `no')
530 ifelse(-`01234567890123456789-', -e(long)-, `yes', `no')
531 ifelse(-e(long)-, `-01234567890123456789', `yes', `no')
532 ifelse(`-01234567890123456789', -e(long)-, `yes', `no')
533 dnl concatenate macro expansion with quoted characters
534 ifelse(`-'e(long), `-01234567890123456789', `yes', `no')
535 ifelse(-`01234567890123456789', `-'e(long), `yes', `no')
536 ifelse(`-'e(long), `-01234567890123456789-', `yes', `no')
537 ifelse(`-01234567890123456789-', `-'e(long), `yes', `no')
538 ifelse(`-'e(long)`-', `-01234567890123456789-', `yes', `no')
539 ifelse(-`01234567890123456789-', `-'e(long)`-', `yes', `no')
540 ifelse(`-'e(long)`-', `-01234567890123456789', `yes', `no')
541 ifelse(`-01234567890123456789', `-'e(long)`-', `yes', `no')
576 AT_DATA([[include.m4]],
580 include(`incl-test.m4')
586 AT_DATA([[incl-test.m4]],
605 [[m4:include.m4:2: include: cannot open `NOFILE': No such file or directory
606 m4:include.m4:6: include: cannot open `NOFILE': No such file or directory
609 AT_CHECK_M4([include.m4], 1, expout, experr)
611 dnl make sure files are handled correctly even via builtin
614 AT_DATA([in], [[builtin(`include', `foo')dnl
617 AT_CHECK_M4([in], [0], [[bar
630 dnl This used to be quadratic, taking millions of comparisons,
631 dnl but should now operate in linear time with only several thousand checks.
632 AT_DATA([in], [M4_ONE_MEG_DEFN[dnl
633 index(substr(f, `0', `500000')-, substr(f, `0', `100000')-)
635 AT_CHECK_M4([in], [0], [[400000
638 dnl This validates that index is 8-bit safe.
639 AT_DATA([in], [[index(`1«2', `»')
644 AT_CHECK_M4([in], [0], [[-1
660 AT_DATA([[indir.m4]],
661 [[define(`%%$$##', `>>>$0<<< cnt $#')
663 # indir(`%%$$##', nonsense, nonsense)
664 indir(`%%$$##', nonsense, nonsense)
666 # indir(`indir', `%%$$##', nonsense)
667 indir(`indir', `%%$$##', nonsense)
669 # indir(`indir', `indir', `indir', `indir', `%%$$##')
670 indir(`indir', `indir', `indir', `indir', `%%$$##')
676 # indir(`%%$$##', nonsense, nonsense)
679 # indir(`indir', `%%$$##', nonsense)
682 # indir(`indir', `indir', `indir', `indir', `%%$$##')
686 AT_CHECK_M4([indir.m4], 0, expout)
697 dnl Ensure that spilled diversions are gracefully cleaned up
698 AT_DATA([in.m4], [M4_ONE_MEG_DEFN[divert(`1')f
701 AT_CHECK([rm -Rf tmpdir && mkdir tmpdir && test -d tmpdir])
704 AT_CHECK_M4([in.m4], [0])
705 AT_CHECK([rmdir tmpdir])
716 dnl Check that on error, the expansion is void
718 [[mkdtemp(`no_such_dir/m4-fooXXXXXX')
720 AT_CHECK_M4([in], [0], [[
721 ]], [[m4:in:1: Warning: mkdtemp: cannot create directory from template `no_such_dir/m4-fooXXXXXX': No such file or directory
724 dnl Check that umask has an effect. drws--S--T is okay.
726 [[translit(substr(esyscmd(`ls -ld 'mkdtemp(`m4-fooXXXXXX')), `0', `10'),
729 AT_CHECK([$M4 < in], [0], [[drwx------
731 AT_CHECK([umask 700; $M4 < in], [0], [[d---------
743 AT_KEYWORDS([maketemp])
745 dnl Check that on error, the expansion is void
747 [[mkstemp(`no_such_dir/m4-fooXXXXXX')
749 AT_CHECK_M4([in], [0], [[
750 ]], [[m4:in:1: Warning: mkstemp: cannot create file from template `no_such_dir/m4-fooXXXXXX': No such file or directory
753 dnl Check that extra X are appended, but not trailing NUL
754 AT_DATA([[in]], [[len(mkstemp(`m4-fooXXXXX'))
756 AT_CHECK_M4([in], [0], [[12
759 dnl Check that umask has an effect
761 [[substr(esyscmd(`ls -ld 'mkstemp(`m4-fooXXXXXX')), `0', `10')
763 AT_CHECK([$M4 < in], [0], [[-rw-------
765 AT_CHECK([umask 700; $M4 < in], [0], [[----------
768 dnl Check for Solaris compatibility of maketemp. Hopefully the pid is
769 dnl less than 20 decimal digits. Also check that --safer does not affect
770 dnl traditional behavior of maketemp, which is textual only.
775 maketemp(XXXXXXXXXXXXXXXXXXXXX)
776 maketemp(no_such_dir/XXXXXX)
778 dnl Abuse our knowledge of AT_CHECK_M4 so that we can get stderr filtering...
779 AT_CHECK_M4([-G -Q --safer], [0], [stdout], [],
780 [in& echo $! > pid; wait $!])
785 X`$SED -e 's/.*\(.\)$/\1/' pid`
786 X`echo "$pid" | $SED -e "s/.*/00000000000000000000&/" -e 's/.*\(.\{20\}$\)/\1/'`
787 no_such_dir/`echo "$pid" | $SED -e "s/.*/000000&/" -e 's/.*\(.\{6\}$\)/\1/'`
789 AT_CHECK([cat stdout], [0], [expout])
799 AT_CHECK_DYNAMIC_MODULE
804 # forloop(i, from, to, stmt)
806 define(`forloop', `pushdef(`$1', `$2')_forloop(`$1', `$2', `$3', `$4')popdef(`$1')')
808 `$4`'ifelse($1, `$3', ,
809 `define(`$1', incr($1))_forloop(`$1', `$2', `$3', `$4')')')
811 forloop(`x', 1, 100, `2**x = mpeval(2**x)
856 2**40 = 1099511627776
857 2**41 = 2199023255552
858 2**42 = 4398046511104
859 2**43 = 8796093022208
860 2**44 = 17592186044416
861 2**45 = 35184372088832
862 2**46 = 70368744177664
863 2**47 = 140737488355328
864 2**48 = 281474976710656
865 2**49 = 562949953421312
866 2**50 = 1125899906842624
867 2**51 = 2251799813685248
868 2**52 = 4503599627370496
869 2**53 = 9007199254740992
870 2**54 = 18014398509481984
871 2**55 = 36028797018963968
872 2**56 = 72057594037927936
873 2**57 = 144115188075855872
874 2**58 = 288230376151711744
875 2**59 = 576460752303423488
876 2**60 = 1152921504606846976
877 2**61 = 2305843009213693952
878 2**62 = 4611686018427387904
879 2**63 = 9223372036854775808
880 2**64 = 18446744073709551616
881 2**65 = 36893488147419103232
882 2**66 = 73786976294838206464
883 2**67 = 147573952589676412928
884 2**68 = 295147905179352825856
885 2**69 = 590295810358705651712
886 2**70 = 1180591620717411303424
887 2**71 = 2361183241434822606848
888 2**72 = 4722366482869645213696
889 2**73 = 9444732965739290427392
890 2**74 = 18889465931478580854784
891 2**75 = 37778931862957161709568
892 2**76 = 75557863725914323419136
893 2**77 = 151115727451828646838272
894 2**78 = 302231454903657293676544
895 2**79 = 604462909807314587353088
896 2**80 = 1208925819614629174706176
897 2**81 = 2417851639229258349412352
898 2**82 = 4835703278458516698824704
899 2**83 = 9671406556917033397649408
900 2**84 = 19342813113834066795298816
901 2**85 = 38685626227668133590597632
902 2**86 = 77371252455336267181195264
903 2**87 = 154742504910672534362390528
904 2**88 = 309485009821345068724781056
905 2**89 = 618970019642690137449562112
906 2**90 = 1237940039285380274899124224
907 2**91 = 2475880078570760549798248448
908 2**92 = 4951760157141521099596496896
909 2**93 = 9903520314283042199192993792
910 2**94 = 19807040628566084398385987584
911 2**95 = 39614081257132168796771975168
912 2**96 = 79228162514264337593543950336
913 2**97 = 158456325028528675187087900672
914 2**98 = 316912650057057350374175801344
915 2**99 = 633825300114114700748351602688
916 2**100 = 1267650600228229401496703205376
920 AT_CHECK_M4([-m mpeval in], 0, expout)
930 AT_SETUP([multiquotes])
932 AT_DATA([[multiquotes.m4]],
935 changequote([``], [''])dnl
937 define(``foo'', ````FOO'''')dnl
939 changequote(``!'', ``!'')dnl
945 changequote(!>*>*>*>*>!, !<*<*<*<*<!)dnl five of each
946 >*>*>*>*>foo bar<*<*<*<*<
948 >*>*>*>*>*>*><*<*<*<*<*<*<
949 dumpdef(>*>*>*>*>foo<*<*<*<*<, >*>*>*>*>bar<*<*<*<*<)dnl
965 [[m4trace: -1- changequote(`[', `]') -> []
966 m4trace: -1- dnl -> []
967 m4trace: -1- changequote([``], ['']) -> ``''
968 m4trace: -1- dnl -> ``''
969 m4trace: -1- define(``foo'', ````FOO'''') -> ``''
970 m4trace: -1- dnl -> ``''
972 m4trace: -1- dumpdef(``foo'') -> ``''
973 m4trace: -1- dnl -> ``''
974 m4trace: -1- changequote(``!'', ``!'') -> !!
975 m4trace: -1- dnl -> !!
976 m4trace: -1- foo -> !``FOO''!
978 m4trace: -1- dumpdef(!foo!) -> !!
979 m4trace: -1- dnl -> !!
980 m4trace: -1- define(!bar!, !BAR!) -> !!
981 m4trace: -1- bar -> !BAR!
982 m4trace: -1- changequote(!>*>*>*>*>!, !<*<*<*<*<!) -> >*>*>*>*><*<*<*<*<
983 m4trace: -1- dnl -> >*>*>*>*><*<*<*<*<
984 m4trace: -1- foo -> >*>*>*>*>``FOO''<*<*<*<*<
985 m4trace: -1- bar -> >*>*>*>*>BAR<*<*<*<*<
986 bar: >*>*>*>*>BAR<*<*<*<*<
987 foo: >*>*>*>*>``FOO''<*<*<*<*<
988 m4trace: -1- dumpdef(>*>*>*>*>foo<*<*<*<*<, >*>*>*>*>bar<*<*<*<*<) -> >*>*>*>*><*<*<*<*<
989 m4trace: -1- dnl -> >*>*>*>*><*<*<*<*<
992 AT_CHECK_M4([multiquotes.m4], 0, expout, experr)
1002 AT_SETUP([patsubst])
1004 AT_DATA([[patsubst.m4]],
1005 [[# traceon(`patsubst')
1006 patsubst(`GNUs not Unix.', `^', `OBS: ')
1007 patsubst(`GNUs not Unix.', `\<', `OBS: ')
1008 patsubst(`GNUs not Unix.', `\<\w', `\&=')
1009 patsubst(`GNUs not Unix.', `\w*', `(\&)')
1010 patsubst(`GNUs not Unix.', `\w+', `(\&)')
1011 patsubst(`GNUs not Unix.', `\w+')
1012 patsubst(`GNUs not '` Unix.', `[ ]+', ` ')
1016 [[# traceon(`patsubst')
1018 OBS: GNUs OBS: not OBS: Unix.
1020 (GNUs)() (not)() (Unix)().()
1021 (GNUs) (not) (Unix).
1026 AT_CHECK_M4([patsubst.m4], 0, expout)
1038 AT_DATA([[regexp.m4]],
1039 [[traceon(`regexp')dnl
1040 regexp(`hej med dig', `.*', `>>\&<<')
1041 regexp(`hej med dig', `\w*', `>>\&<<')
1042 regexp(`hej med dig', `.+', `>>\&<<')
1043 regexp(`hej med dig', `m\w+', `>>\&<<')
1044 regexp(`hej med dig', `m\(.*\)', `>>\&<< >>\1<<')
1046 regexp(`hej med dig', `.*')
1047 regexp(`hej med dig', `\w*')
1048 regexp(`hej med dig', `.+')
1049 regexp(`hej med dig', `m\w+')
1050 regexp(`hej med dig', `m\(.*\)')
1058 >>med dig<< >>ed dig<<
1068 [[m4trace: -1- regexp(`hej med dig', `.*', `>>\&<<') -> `>>hej med dig<<'
1069 m4trace: -1- regexp(`hej med dig', `\w*', `>>\&<<') -> `>>hej<<'
1070 m4trace: -1- regexp(`hej med dig', `.+', `>>\&<<') -> `>>hej med dig<<'
1071 m4trace: -1- regexp(`hej med dig', `m\w+', `>>\&<<') -> `>>med<<'
1072 m4trace: -1- regexp(`hej med dig', `m\(.*\)', `>>\&<< >>\1<<') -> `>>med dig<< >>ed dig<<'
1073 m4trace: -1- regexp(`hej med dig', `.*') -> `0'
1074 m4trace: -1- regexp(`hej med dig', `\w*') -> `0'
1075 m4trace: -1- regexp(`hej med dig', `.+') -> `0'
1076 m4trace: -1- regexp(`hej med dig', `m\w+') -> `4'
1077 m4trace: -1- regexp(`hej med dig', `m\(.*\)') -> `4'
1080 AT_CHECK_M4([regexp.m4], 0, expout, experr)
1090 AT_SETUP([sync-lines])
1094 # Several input lines, expanding to one
1095 define(`foo', ``foo' line one.
1097 `foo' line three.') xyz
1099 # Several input lines, expanding to none
1100 define(`foo', ``foo' line one.
1102 `foo' line three.')dnl
1103 # one input line, expanding to several output lines
1107 AT_CHECK_M4([[in]], 0,
1109 # Several input lines, expanding to one
1117 # Several input lines, expanding to none
1119 # one input line, expanding to several output lines
1124 foo line three. foo line one.
1140 dnl Ensure that syscmd does not inherit any unnecessary fds from trace.
1141 AT_DATA([in.m4], [[syscmd(`echo hi >&3')ifelse(sysval,
1142 `0', `skipping: sh cannot detect closed fds
1145 AT_CHECK_M4([3>&-], [0], [], [stderr], [in.m4])
1147 AT_CHECK_M4([--debugfile=trace -tdnl 3>&-], [0], [], [experr], [in.m4])
1148 AT_CHECK([cat trace], [0], [[m4trace: -1- dnl -> `'
1151 dnl Ensure that syscmd does not inherit any unnecessary fds from diversions.
1152 AT_DATA([in.m4], [M4_ONE_MEG_DEFN[divert(`1')f
1154 syscmd(`echo hi >&3')divert
1157 AT_CHECK_M4([3>&-], [0], [stdout-nolog], [experr], [in.m4])
1158 AT_CHECK([$SED -ne '/./p' stdout], [0], [[hello
1162 dnl Ensure that syscmd does not inherit any unnecessary fds from input files.
1163 AT_DATA([in.m4], [[hello syscmd(`cat <&3')dnl
1164 dnl this line should not be read by cat
1167 AT_CHECK_M4([3>&-], [0], [[hello world
1168 ]], [stderr], [in.m4])
1170 AT_CHECK_M4([in.m4 3>&-], [0], [[hello world
1180 AT_SETUP([translit])
1182 AT_DATA([[translit.m4]],
1183 [[# traceon(`translit')dnl
1184 translit(`GNUs not Unix', `a-z')
1185 translit(`GNUs not Unix', `a-z', `A-Z')
1186 translit(`GNUs not Unix', `A-Z', `a-z')
1187 translit(`GNUs not Unix', `A-Z')
1188 translit(`a-z', `a-')
1189 translit(`A-Z', `A-Z-', `-A-Z')
1190 translit(`GNUs not Unix', `Z-A', `a-z')
1193 AT_CHECK_M4([translit.m4], 0,
1194 [[# traceon(`translit')dnl
1204 dnl This used to be quadratic, taking millions of comparisons,
1205 dnl but should now operate in linear time with only several thousand checks.
1206 AT_DATA([in], [M4_ONE_MEG_DEFN[dnl
1207 define(`a_', translit(substr(f, `0', `50000'), `
1209 define(`b_', translit(substr(f, `0', `50000'), `
1211 define(`d_', translit(substr(f, `0', `50000'), `
1213 define(`c'd_, `pass')dnl
1214 translit(`a'b_, a_`b', `c'd_)
1216 AT_CHECK_M4([in], [0], [[pass
1219 dnl This validates that ranges are built using unsigned chars.
1220 AT_DATA([in], [[translit(`«abc~', `~-»')
1222 AT_CHECK_M4([in], [0], [[abc
1225 dnl Validate short strings, which take a different code path.
1227 translit(`abcdeabcde', `a')
1228 translit(`abcdeabcde', `ab')
1229 translit(`abcdeabcde', `a', `f')
1230 translit(`abcdeabcde', `aa', `fg')
1231 translit(`abcdeabcde', `a', `fg')
1232 translit(`abcdeabcde', `ab', `f')
1233 translit(`abcdeabcde', `ab', `fg')
1234 translit(`abcdeabcde', `ab', `ba')
1235 translit(`abcdeabcde', `e', `f')
1236 translit(`abc', `', `cde')
1237 translit(`', `a', `bc')
1239 AT_CHECK_M4([in], [0], [[bcdebcde
1260 AT_SETUP([undivert])
1262 AT_DATA([[undivert.m4]],
1263 [[define(`undiverted', `UNDIVERTED')
1265 undivert(`undivert.incl')
1267 include(`undivert.incl')
1270 AT_DATA([[undivert.incl]],
1271 [[This is to be undiverted soon.
1274 AT_CHECK_M4([undivert.m4], 0,
1277 This is to be undiverted soon.
1280 This is to be UNDIVERTED soon.
1294 AT_DATA([[wrap.m4]],
1296 m4wrap(`Wrapper no. 1
1299 m4wrap(`Wrapper no. 2
1300 m4wrap(`Wrapper no. 3
1301 m4wrap(`Wrapper no. 4
1307 AT_CHECK_M4([wrap.m4], 0,