commit-mailutils
[Top][All Lists]
Advanced

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

[SCM] GNU Mailutils branch, master, updated. release-3.1.1-41-gaf06135


From: Sergey Poznyakoff
Subject: [SCM] GNU Mailutils branch, master, updated. release-3.1.1-41-gaf06135
Date: Thu, 19 Jan 2017 15:13:08 +0000 (UTC)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Mailutils".

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=af06135f2e383ed76107e4e4aa8c866e515c40e4

The branch, master has been updated
       via  af06135f2e383ed76107e4e4aa8c866e515c40e4 (commit)
      from  9ba835fbb5a937735f51925c2170bbc748820fcf (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit af06135f2e383ed76107e4e4aa8c866e515c40e4
Author: Sergey Poznyakoff <address@hidden>
Date:   Thu Jan 19 13:11:27 2017 +0200

    Add tests for mu_str_expand and mu_str_vexpand functions
    
    * libmailutils/string/expvar.c (exp_shell): Fix out-of-buffer
    read when used without arguments.
    (mu_str_expand): Improve error handling.
    * libmailutils/tests/testsuite.at (MU_GENERIC_TEST_CMD): New
    macro.
    Include exp.at
    * libmailutils/tests/vexp.c: New file.
    * libmailutils/tests/Makefile.am: Build vexp. Add exp.at
    * libmailutils/tests/exp.at: New file.

-----------------------------------------------------------------------

Summary of changes:
 libmailutils/string/expvar.c                   |   44 ++++++++++++++-----
 libmailutils/tests/.gitignore                  |    2 +
 libmailutils/tests/Makefile.am                 |    2 +
 libmailutils/tests/exp.at                      |   52 ++++++++++++++++++++++
 libmailutils/tests/exp.c                       |   16 +++++++
 libmailutils/tests/testsuite.at                |   23 ++++++++++
 testsuite/fldel.c => libmailutils/tests/vexp.c |   56 ++++++++++++------------
 7 files changed, 154 insertions(+), 41 deletions(-)
 create mode 100644 libmailutils/tests/exp.at
 copy testsuite/fldel.c => libmailutils/tests/vexp.c (56%)

diff --git a/libmailutils/string/expvar.c b/libmailutils/string/expvar.c
index a9361ef..04e4542 100644
--- a/libmailutils/string/expvar.c
+++ b/libmailutils/string/expvar.c
@@ -173,7 +173,7 @@ exp_shell (char **ret, char const *str, size_t len, void 
*closure)
        --buflen;
       buffer[buflen] = 0;
     }
-  
+
   pclose (fp);
   free (cmd);
 
@@ -229,8 +229,8 @@ exp_runcmd (char **ret, const char *str, size_t len, char 
**argv, void *closure)
 
   if (strcmp (argv[0], SHELL_CMD) == 0)
     {
-      len -= sizeof SHELL_CMD;
-      str += sizeof SHELL_CMD;
+      len -= sizeof SHELL_CMD - 1;
+      str += sizeof SHELL_CMD - 1;
       while (len > 0 && mu_isspace (*str))
        {
          len--;
@@ -282,8 +282,7 @@ int
 mu_str_expand (char **output, char const *input, mu_assoc_t assoc)
 {
   struct mu_wordsplit ws;
-  size_t wordc;
-  char **wordv;
+  int rc = 0;
   
   ws.ws_getvar = exp_getvar;
   ws.ws_command = exp_runcmd;
@@ -294,15 +293,36 @@ mu_str_expand (char **output, char const *input, 
mu_assoc_t assoc)
                    MU_WRDSF_NOSPLIT | MU_WRDSF_GETVAR | MU_WRDSF_CLOSURE
                    | MU_WRDSF_OPTIONS))
     {
-      char *p = strdup (mu_wordsplit_strerror (&ws));
-      if (p)
-       *output = p;
-      return MU_ERR_FAILURE;
+      if (ws.ws_errno == MU_WRDSE_NOSPACE)
+       rc = ENOMEM;
+      else
+       {
+         char *p = strdup (mu_wordsplit_strerror (&ws));
+         if (!p)
+           rc = ENOMEM;
+         else
+           {
+             *output = p;
+             rc = MU_ERR_FAILURE;
+           }
+       }
+    }
+  else if (ws.ws_wordc == 0)
+    {
+      *output = strdup ("");
+      if (!*output)
+       rc = ENOMEM;
+    }
+  else
+    {
+      size_t wordc;
+      char **wordv;
+      
+      mu_wordsplit_get_words (&ws, &wordc, &wordv);
+      *output = wordv[0];
     }
-  mu_wordsplit_get_words (&ws, &wordc, &wordv);
-  *output = wordv[0];
   mu_wordsplit_free (&ws);
-  return 0;
+  return rc;
 }
 
 int
diff --git a/libmailutils/tests/.gitignore b/libmailutils/tests/.gitignore
index 10ebd32..45351de 100644
--- a/libmailutils/tests/.gitignore
+++ b/libmailutils/tests/.gitignore
@@ -11,6 +11,7 @@ argcv
 debugspec
 decode2047
 encode2047
+exp
 fltst
 fsaf
 fsaftomod
@@ -34,6 +35,7 @@ tcli
 tempfile
 url-comp
 url-parse
+vexp
 wicket
 wordwrap
 wsp
diff --git a/libmailutils/tests/Makefile.am b/libmailutils/tests/Makefile.am
index b31b5ac..4c6b2f3 100644
--- a/libmailutils/tests/Makefile.am
+++ b/libmailutils/tests/Makefile.am
@@ -70,6 +70,7 @@ noinst_PROGRAMS = \
  tcli\
  url-comp\
  url-parse\
+ vexp\
  wicket\
  wordwrap\
  wsp
@@ -89,6 +90,7 @@ TESTSUITE_AT = \
  debugspec.at\
  decode2047.at\
  encode2047.at\
+ exp.at\
  fromflt.at\
  fsaf.at\
  fsaftomod.at\
diff --git a/libmailutils/tests/exp.at b/libmailutils/tests/exp.at
new file mode 100644
index 0000000..d97c252
--- /dev/null
+++ b/libmailutils/tests/exp.at
@@ -0,0 +1,52 @@
+# This file is part of GNU Mailutils. -*- Autotest -*-
+# Copyright (C) 2007-2012, 2014-2017 Free Software Foundation, Inc.
+#
+# GNU Mailutils is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 3, or (at
+# your option) any later version.
+#
+# GNU Mailutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_BANNER(Variable and command expansion)
+
+dnl ------------------------------------------------------------
+dnl TESTEXP([NAME], [KW = `'], [INPUT], [STDOUT = `'],
+dnl         [STDERR = `'])
+dnl
+m4_pushdef([TESTEXP],[
+m4_pushdef([MU_TEST_GROUP],[Expand])
+m4_pushdef([MU_TEST_KEYWORDS],[expand])
+MU_GENERIC_TEST_CMD([$1],[$2],[$3],[],[$4
+],[$5])
+m4_popdef([MU_TEST_KEYWORDS])
+m4_popdef([MU_TEST_GROUP])
+])
+
+m4_pushdef([MU_TEST_COMMAND],[exp])
+TESTEXP([variable expansion],[],[x=foo y=bar -- 'test $x $y $z end'],
+[test foo bar  end])
+
+TESTEXP([domainpart],[],[-- '$(domainpart "address@hidden")'],
+[example.com])
+
+TESTEXP([localpart],[],[-- '$(localpart "address@hidden")'],
+[foo])
+
+TESTEXP([shell],[],[-- '$(shell echo "test string" | tr " " -)'],
+[test-string])
+
+m4_popdef([MU_TEST_COMMAND])
+
+m4_pushdef([MU_TEST_COMMAND],[vexp])
+TESTEXP([mu_str_vexpand],[],['certain $user on $host running $package'],
+[certain somebody on localhost running mailutils])
+
+m4_popdef([MU_TEST_COMMAND])
+m4_popdef([TESTEXP])
\ No newline at end of file
diff --git a/libmailutils/tests/exp.c b/libmailutils/tests/exp.c
index 35a52d0..f126f88 100644
--- a/libmailutils/tests/exp.c
+++ b/libmailutils/tests/exp.c
@@ -1,3 +1,19 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+   Copyright (C) 2017 Free Software Foundation, Inc.
+
+   GNU Mailutils is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
+
+   GNU Mailutils is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
+
 #include <mailutils/mailutils.h>
 
 int
diff --git a/libmailutils/tests/testsuite.at b/libmailutils/tests/testsuite.at
index 0c62040..11e12c8 100644
--- a/libmailutils/tests/testsuite.at
+++ b/libmailutils/tests/testsuite.at
@@ -51,6 +51,28 @@ MU_TEST_COMMAND < input],[$4],[$5],[$6],[$7],[$8])
 AT_CLEANUP
 ])
 
+dnl ------------------------------------------------------------
+dnl MU_GENERIC_TEST_CMD([NAME], [KW = `'], [ARGS],
+dnl                     [CODE], [STDOUT = `'], [STDERR = `'],
+dnl                     [RUN-IF-FAIL], [RUN-IF-PASS])
+dnl
+dnl NAME        $1
+dnl KW          $2
+dnl ARGS        $3
+dnl CODE        $4
+dnl STDOUT      $5
+dnl STDERR      $6
+dnl RUN-IF-FAIL $7
+dnl RUN-IF-PASS $8
+dnl
+m4_define([MU_GENERIC_TEST_CMD],[
+AT_SETUP([m4_if(MU_TEST_GROUP,[],,MU_TEST_GROUP: 
)m4_if([$1],[],[mu_firstline([$3])],[$1])])
+AT_KEYWORDS([MU_TEST_KEYWORDS $2])
+AT_CHECK([
+MU_TEST_COMMAND $3],[$4],[$5],[$6],[$7],[$8])
+AT_CLEANUP
+])
+
 AT_INIT
 
 AT_BANNER([Conversions])
@@ -131,6 +153,7 @@ m4_include([strerr.at])
 m4_include([list.at])
 m4_include([address.at])
 m4_include([wordsplit.at])
+m4_include([exp.at])
 m4_include([url.at])
 m4_include([url-comp.at])
 m4_include([mailcap.at])
diff --git a/testsuite/fldel.c b/libmailutils/tests/vexp.c
similarity index 56%
copy from testsuite/fldel.c
copy to libmailutils/tests/vexp.c
index 8872bda..7c38174 100644
--- a/testsuite/fldel.c
+++ b/libmailutils/tests/vexp.c
@@ -1,5 +1,5 @@
 /* GNU Mailutils -- a suite of utilities for electronic mail
-   Copyright (C) 2010-2012, 2014-2017 Free Software Foundation, Inc.
+   Copyright (C) 2017 Free Software Foundation, Inc.
 
    GNU Mailutils is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -14,41 +14,39 @@
    You should have received a copy of the GNU General Public License
    along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <config.h>
 #include <mailutils/mailutils.h>
+#include <assert.h>
 
 int
 main (int argc, char **argv)
 {
   int rc;
-  mu_folder_t f;
-  
-  if (argc != 3)
-    {
-      fprintf (stderr, "usage: %s URL NAME\n", argv[0]);
-      return 1;
-    }
+  char *p;
 
-  mu_register_all_mbox_formats ();
-  
-  MU_ASSERT (mu_folder_create (&f, argv[1]));
-  rc = mu_folder_delete (f, argv[2]);
-  if (rc)
+  assert (argc == 2);
+
+  rc = mu_str_vexpand (&p, argv[1],
+                      "user", "somebody",
+                      "host", "localhost",
+                      "name", "tests",
+                      "package", PACKAGE,
+                      NULL);
+  switch (rc)
     {
-      if (rc == ENOTEMPTY)
-       {
-         printf ("mailbox removed, but has subfolders\n");
-         rc = 0;
-       }
-      else
-       fprintf (stderr, "%s\n", mu_strerror (rc));
+    case 0:
+      printf ("%s\n", p);
+      free (p);
+      break;
+      
+    case MU_ERR_FAILURE:
+      mu_error ("%s", p);
+      free (p);
+      break;
+      
+    default:
+      mu_error ("%s", mu_strerror (rc));
+      return 1;
     }
-  mu_folder_destroy (&f);
-  
-  return rc != 0;
+  return 0;
 }


hooks/post-receive
-- 
GNU Mailutils



reply via email to

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