* lib/m4sugar/m4sugar.m4 (m4_max, m4_min): New macros.
(m4_sign): Sort.
(m4_text_wrap): Fix off-by-one error in rewrite from m4_for to
m4_format.
* lib/autotest/general.m4 (AT_SETUP): Avoid negative width.
* tests/autotest.at (Long test title, Longer test title): Test
this fix, beyond what AS_HELP_STRING already tests.
Signed-off-by: Eric Blake <ebb9@byu.net>
2007-10-08 Eric Blake <ebb9@byu.net>
+ Fix regression in m4_text_wrap from 2007-10-05.
+ * lib/m4sugar/m4sugar.m4 (m4_max, m4_min): New macros.
+ (m4_sign): Sort.
+ (m4_text_wrap): Fix off-by-one error in rewrite from m4_for to
+ m4_format.
+ * lib/autotest/general.m4 (AT_SETUP): Avoid negative width.
+ * tests/autotest.at (Long test title, Longer test title): Test
+ this fix, beyond what AS_HELP_STRING already tests.
+
Avoid m4 warnings on bad m4_format usage.
* lib/m4sugar/m4sugar.m4 (m4_text_wrap): Use %*s, in case width
evaulates to 0.
- * lib/autotest/general.m4 (AT_ordinal): Likewise; also ensure that
+ * lib/autotest/general.m4 (AT_SETUP): Likewise; also ensure that
enough arguments are provided.
2007-10-06 Paolo Bonzini <bonzini@gnu.org>
at_setup_line='m4_defn([AT_line])'
at_desc="AS_ESCAPE(m4_dquote(m4_defn([AT_description])))"
$at_quiet AS_ECHO_N([m4_format(["%3d: $at_desc%*s"], AT_ordinal,
- m4_eval(47 - m4_qlen(m4_defn([AT_description]))), [])])
+ m4_max(0, m4_eval(47 - m4_qlen(m4_defn([AT_description])))), [])])
m4_divert_push([TEST_SCRIPT])dnl
])
[0], [],
[m4_define([m4_Cursor], m4_len(m4_Prefix))[]dnl
m4_format([%*s],
- m4_eval(m4_len(m4_Prefix) - 1 - m4_qlen(m4_defn([m4_Prefix1]))),
+ m4_max(0,m4_eval(m4_len(m4_Prefix) - m4_qlen(m4_defn([m4_Prefix1])))),
[])])[]dnl
m4_foreach_w([m4_Word], [$1],
[m4_define([m4_Cursor], m4_eval(m4_Cursor + m4_qlen(m4_defn([m4_Word])) + 1))dnl
## 10. Number processing. ##
## ----------------------- ##
-# m4_sign(A)
-# ----------
-# The sign of the integer expression A.
-m4_define([m4_sign],
-[m4_eval((([$1]) > 0) - (([$1]) < 0))])
-
# m4_cmp(A, B)
# ------------
# Compare two integer expressions.
1, 1,
0, [$0((m4_shift$1), (m4_shift$2))])])])
+# m4_max(A, B, ...)
+# m4_min(A, B, ...)
+# -----------------
+# Return the maximum (or minimum) of a series of integer expressions.
+#
+# M4 1.4.x doesn't provide ?:. Hence this huge m4_eval. Avoid m4_eval
+# if both arguments are identical, but be aware of m4_max(0xa, 10) (hence
+# the use of <=, not just <, in the second multiply).
+m4_define([m4_max],
+[m4_if([$#], [0], [m4_fatal([too few arguments to $0])],
+ [$#], [1], [$1],
+ [$#$1], [2$2], [$1],
+ [$#], [2],
+ [m4_eval((([$1]) > ([$2])) * ([$1]) + (([$1]) <= ([$2])) * ([$2]))],
+ [$0($0([$1], [$2]), m4_shift2($@))])])
+m4_define([m4_min],
+[m4_if([$#], [0], [m4_fatal([too few arguments to $0])],
+ [$#], [1], [$1],
+ [$#$1], [2$2], [$1],
+ [$#], [2],
+ [m4_eval((([$1]) < ([$2])) * ([$1]) + (([$1]) >= ([$2])) * ([$2]))],
+ [$0($0([$1], [$2]), m4_shift2($@))])])
+
+
+# m4_sign(A)
+# ----------
+# The sign of the integer expression A.
+m4_define([m4_sign],
+[m4_eval((([$1]) > 0) - (([$1]) < 0))])
+
## ------------------------ ##
## ------------------------------- ##
# AT_CHECK_AT_TITLE(TITLE, TITLE-TO-TEST, EXPANDED-TITLE-TO-TEST
-# [XFAIL-CONDITION])
+# [XFAIL-CONDITION], [COLUMN = 53])
# ---------------------------------------------------------------
# Create a new test named TITLE that runs an Autotest test suite
# comprised of a trivial test named TITLE-TO-TEST, which expands
# to EXPANDED-TITLE-TO-TEST. XFAIL-CONDITION passes verbatim to
-# AT_CHECK_AT.
+# AT_CHECK_AT. Verify that `ok' prints at COLUMN.
m4_define([AT_CHECK_AT_TITLE],
[AT_CHECK_AT([$1],
[[
AT_CLEANUP
]], [$4], [], [], [],
dnl This sed script checks for two things - that the output is properly
-dnl expanded, and that the 'ok' starts on column 53.
+dnl expanded, and that the 'ok' starts on the right column.
[AT_CHECK([[$CONFIG_SHELL ./micro-suite |
sed -n '/^ 1:/{
h
s/[^:]*: \(.*[^ ]\)[ ]*ok.*/\1/p
x
-s/^.\{53\}ok.*/ok/p
+s/^.\{]]]m4_default($5, 53)[[[\}ok.*/ok/p
}']],,
[[$3
ok
m4_define([AT_CHECK_AT_TITLE_CHAR],
[AT_CHECK_AT_TITLE([$1 in a test title], [A $2 in my name],
- [A ]m4_ifval([$3], [[$3]], [[$2]])[ in my name], $4)])
+ [A ]m4_ifval([$3], [[$3]], [[$2]])[ in my name], $4, $5)])
AT_CHECK_AT_TITLE_CHAR([Backquote], [`])
AT_CHECK_AT_TITLE_CHAR([Single-quote], ['])
AT_CHECK_AT_TITLE_CHAR([Macro echoing macro], [macro_echo([macro_name])],
[macro_expanded])
AT_CHECK_AT_TITLE_CHAR([Macro echoing single-quote], [macro_echo(['])], ['])
+AT_CHECK_AT_TITLE_CHAR([Long test title], [0123456789012345678901234567890123])
+AT_CHECK_AT_TITLE_CHAR([Longer test title],
+ [01234567890123456789012345678901234], [], [], [54])
## ----------------- ##