+2008-08-03 Peter Maydell <pmaydell@chiark.greenend.org.uk>
+
+ * sbr/fmt_compile.c: when doing an if-test on the result
+ of a function which returns a string result, check whether
+ the string is non-empty (as the documentation says we do).
+ Previously we were always testing the integer 'value'. Bug
+ spotted by Eric Gillespie.
+ * test/tests/repl/test-if-str: test case for this bug.
+
2008-07-24 Eric Gillespie <epg@pretzelnet.org>
* test/setup-test: Run 'make clean' before building
#define TF_NOP 8 /* like expr but no result */
/* ftable->flags */
+/* NB that TFL_PUTS is also used to decide whether the test
+ * in a "%<(function)..." should be a string or numeric one.
+ */
#define TFL_PUTS 1 /* implicit putstr if top level */
#define TFL_PUTN 2 /* implicit putnum if top level */
if (ftbl->f_type >= IF_FUNCS)
fp->f_type = ftbl->extra;
else {
- LV (FT_IF_V_NE, 0);
+ /* Put out a string test or a value test depending
+ * on what this function's return type is.
+ */
+ if (ftbl->flags & TFL_PUTS) {
+ LV (FT_IF_S, 0);
+ } else {
+ LV (FT_IF_V_NE, 0);
+ }
}
}
else {
--- /dev/null
+#!/bin/sh
+######################################################
+#
+# Test that an '%<(function)...' if-construct correctly
+# tests whether 'str' is empty if the function returns
+# a string, and tests 'value' if the function returns
+# an integer.
+#
+######################################################
+
+# create test replgroupcomps
+form=$MH_TEST_DIR/$$.replgroupcomps
+cat > $form <<EOF
+X-STRING: %(num)%(lit)%<(lit FOO) found%| missing%>\n\
+X-NUMBER: %(num)%(lit)%<(num 3) yes%| no%>\n\
+X-NOSTRING: %(num 3)%(lit x)%<(lit) found%| missing%>\n\
+X-NONUMBER: %(num 3)%(lit x)%<(num) yes%| no%>\n\
+--------
+EOF
+
+expected=$MH_TEST_DIR/$$.expected
+actual=$MH_TEST_DIR/Mail/draft
+
+cat > $expected <<EOF
+X-STRING: 0 found
+X-NUMBER: 0 yes
+X-NOSTRING: 3x missing
+X-NONUMBER: 3x no
+--------
+Test1 writes:
+> This is message number 1
+EOF
+
+repl -editor true -format -form $form -group -nocc me -nowhatnowproc 1
+
+diff -u $expected $actual