dnl
AT_BANNER([DEFINE])
+m4_define([PSPP_CHECK_MACRO_EXPANSION],
+ [AT_SETUP([macro expansion - $1])
+ AT_DATA([define.sps], [$2
+DEBUG EXPAND.
+$3
+])
+ AT_DATA([expout], [$4
+])
+ AT_CHECK([pspp --testing-mode define.sps | sed '/^$/d'], [$6
+], [expout])
+ AT_CLEANUP])
+
AT_SETUP([simple macro expansion])
AT_DATA([define.sps], [dnl
DEFINE !macro()
"x "" y".
])
AT_CLEANUP
-
-AT_SETUP([macro expansion with arguments])
+\f
+PSPP_CHECK_MACRO_EXPANSION([one !TOKENS(1) positional argument],
+ [DEFINE !t1(!positional !tokens(1)) t1 (!1) !ENDDEFINE.],
+ [!t1 a.
+!t1 b.
+!t1 a b.],
+ [t1(a)
+t1(b)
+t1(a)
+note: unexpanded token "b"])
+\f
+AT_SETUP([macro expansion with positional arguments])
AT_DATA([define.sps], [dnl
DEFINE !title(!positional !tokens(1)) !1 !ENDDEFINE.
DEFINE !t1(!positional !tokens(1)) t1 (!1) !ENDDEFINE.
cmd2(!1, !2)
!ENDDEFINE.
+DEFINE !p(!positional !tokens(1)
+ /!positional !tokens(1)
+ /!positional !tokens(1))
+p(!1, !2, !3)
+!ENDDEFINE.
+
DEBUG EXPAND.
!title "!TOKENS(1) argument."
!t1 a.
!cmd 1 2 3 4.
!cmd2 5 6.
7.
+
+!title "Three !TOKENS(1) arguments."
+!p a b c.
+!p 1 -2 -3.
])
AT_CHECK([pspp --testing-mode define.sps], [0], [dnl
"!TOKENS(1) argument."
cmd(1 2 3 4)
cmd2(5 6, 7)
+
+"Three !TOKENS(1) arguments."
+
+p(a, b, c)
+
+p(1, -2, -3)
+])
+AT_CLEANUP
+\f
+AT_SETUP([macro expansion with positional arguments - negative])
+AT_DATA([define.sps], [dnl
+DEFINE !title(!positional !tokens(1)) !1 !ENDDEFINE.
+DEFINE !p(!positional !tokens(1)
+ /!positional !tokens(1)
+ /!positional !tokens(1))
+(!1, !2, !3)
+!ENDDEFINE.
+
+DEFINE !ce(!positional !charend('/')) ce(!1) !ENDDEFINE.
+
+DEFINE !enc1(!positional !enclose('{', '}')) enc1(!1) !ENDDEFINE.
+DEBUG EXPAND.
+!title "Too few tokens for !TOKENS."
+!p a b.
+!p a.
+!p.
+
+!title "Missing charend delimiter."
+!ce a b c.
+
+!title "Missing start delimiter."
+!enc1 a b c.
+
+!title "Missing end delimiter."
+!enc1{a b c.
+])
+AT_CHECK([pspp --testing-mode define.sps], [1], [dnl
+"Too few tokens for !TOKENS."
+
+define.sps:13: error: DEBUG EXPAND: Unexpected end of command reading
+argument !3 to macro !p.
+
+note: unexpanded token "!p"
+
+note: unexpanded token "a"
+
+note: unexpanded token "b"
+
+define.sps:14: error: DEBUG EXPAND: Unexpected end of command reading
+argument !2 to macro !p.
+
+note: unexpanded token "!p"
+
+note: unexpanded token "a"
+
+define.sps:15: error: DEBUG EXPAND: Unexpected end of command reading
+argument !1 to macro !p.
+
+note: unexpanded token "!p"
+
+"Missing charend delimiter."
+
+define.sps:18: error: DEBUG EXPAND: Unexpected end of command reading
+argument !1 to macro !ce.
+
+note: unexpanded token "!ce"
+
+note: unexpanded token "a"
+
+note: unexpanded token "b"
+
+note: unexpanded token "c"
+
+"Missing start delimiter."
+
+define.sps:21: error: DEBUG EXPAND: Found `a' while expecting `{' reading
+argument !1 to macro !enc1.
+
+note: unexpanded token "!enc1"
+
+note: unexpanded token "a"
+
+note: unexpanded token "b"
+
+note: unexpanded token "c"
+
+"Missing end delimiter."
+
+define.sps:24: error: DEBUG EXPAND: Unexpected end of command reading
+argument !1 to macro !enc1.
+
+note: unexpanded token "!enc1"
+
+note: unexpanded token "{"
+
+note: unexpanded token "a"
+
+note: unexpanded token "b"
+
+note: unexpanded token "c"
])
AT_CLEANUP
+\f
+PSPP_CHECK_MACRO_EXPANSION([one !TOKENS(1) keyword argument],
+ [DEFINE !k(arg1 = !TOKENS(1)) k(!arg1) !ENDDEFINE.],
+ [!k arg1=x.
+!k arg1=x y.
+!k.],
+ [k(x)
+k(x)
+note: unexpanded token "y"
+k( )])
\ No newline at end of file