nmh-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nmh-commits] nmh sbr/fmt_compile.c ChangeLog test/tests/repl...


From: Peter Maydell
Subject: [Nmh-commits] nmh sbr/fmt_compile.c ChangeLog test/tests/repl...
Date: Sun, 03 Aug 2008 13:32:18 +0000

CVSROOT:        /sources/nmh
Module name:    nmh
Changes by:     Peter Maydell <pm215>   08/08/03 13:32:18

Modified files:
        sbr            : fmt_compile.c 
        .              : ChangeLog 
Added files:
        test/tests/repl: test-if-str 

Log message:
        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'.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/nmh/sbr/fmt_compile.c?cvsroot=nmh&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/nmh/test/tests/repl/test-if-str?cvsroot=nmh&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/nmh/ChangeLog?cvsroot=nmh&r1=1.278&r2=1.279

Patches:
Index: sbr/fmt_compile.c
===================================================================
RCS file: /sources/nmh/nmh/sbr/fmt_compile.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- sbr/fmt_compile.c   13 Apr 2007 11:53:08 -0000      1.8
+++ sbr/fmt_compile.c   3 Aug 2008 13:32:17 -0000       1.9
@@ -2,7 +2,7 @@
 /*
  * fmt_compile.c -- "compile" format strings for fmt_scan
  *
- * $Id: fmt_compile.c,v 1.8 2007/04/13 11:53:08 jjr Exp $
+ * $Id: fmt_compile.c,v 1.9 2008/08/03 13:32:17 pm215 Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -53,6 +53,9 @@
 #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 */
 
@@ -610,9 +613,16 @@
                if (ftbl->f_type >= IF_FUNCS)
                    fp->f_type = ftbl->extra;
                else {
+                   /* 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 {
                CERROR("'(' or '{' expected");  /*}*/
            }

Index: ChangeLog
===================================================================
RCS file: /sources/nmh/nmh/ChangeLog,v
retrieving revision 1.278
retrieving revision 1.279
diff -u -b -r1.278 -r1.279
--- ChangeLog   25 Jul 2008 01:07:39 -0000      1.278
+++ ChangeLog   3 Aug 2008 13:32:18 -0000       1.279
@@ -1,3 +1,12 @@
+2008-08-03  Peter Maydell  <address@hidden>
+
+       * 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  <address@hidden>
 
        * test/setup-test: Run 'make clean' before building

Index: test/tests/repl/test-if-str
===================================================================
RCS file: test/tests/repl/test-if-str
diff -N test/tests/repl/test-if-str
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ test/tests/repl/test-if-str 3 Aug 2008 13:32:18 -0000       1.1
@@ -0,0 +1,36 @@
+#!/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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]