Re: [gmime-devel] [PATCH 3/6] consolidate setup of GnuPG homedir for test suites



Hah. I was just thinking this after committing your previous patch :)

This patch has now also been committed.

Thanks!

Jeff

On 12/2/2016 2:02 AM, Daniel Kahn Gillmor wrote:
three different test suites all set up and tear down the GnuPG homedir
in the same way.  By consolidating that code in testsuite.c we can
improve it in a single place.
---
  tests/test-pgp.c     | 10 ++--------
  tests/test-pgpmime.c | 10 ++--------
  tests/test-smime.c   | 10 ++--------
  tests/testsuite.c    | 21 +++++++++++++++++++++
  tests/testsuite.h    |  3 +++
  5 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/tests/test-pgp.c b/tests/test-pgp.c
index 3e7a2a4..8fc755c 100644
--- a/tests/test-pgp.c
+++ b/tests/test-pgp.c
@@ -283,13 +283,7 @@ int main (int argc, char **argv)
        
        testsuite_init (argc, argv);
        
-       /* reset .gnupg config directory */
-       if (system ("/bin/rm -rf ./tmp") != 0)
-               return EXIT_FAILURE;
-       if (system ("/bin/mkdir ./tmp") != 0)
-               return EXIT_FAILURE;
-       setenv ("GNUPGHOME", "./tmp/.gnupg", 1);
-       if (system ("gpg --list-keys > /dev/null 2>&1") != 0)
+       if (testsuite_setup_gpghome ())
                return EXIT_FAILURE;
        
        for (i = 1; i < argc; i++) {
@@ -404,7 +398,7 @@ int main (int argc, char **argv)
        
        g_mime_shutdown ();
        
-       if (system ("/bin/rm -rf ./tmp") != 0)
+       if (testsuite_destroy_gpghome ())
                return EXIT_FAILURE;
        
        return testsuite_exit ();
diff --git a/tests/test-pgpmime.c b/tests/test-pgpmime.c
index b5a8b21..4cead27 100644
--- a/tests/test-pgpmime.c
+++ b/tests/test-pgpmime.c
@@ -419,13 +419,7 @@ int main (int argc, char *argv[])
        
        testsuite_init (argc, argv);
        
-       /* reset .gnupg config directory */
-       if (system ("/bin/rm -rf ./tmp") != 0)
-               return EXIT_FAILURE;
-       if (system ("/bin/mkdir ./tmp") != 0)
-               return EXIT_FAILURE;
-       setenv ("GNUPGHOME", "./tmp/.gnupg", 1);
-       if (system ("gpg --list-keys > /dev/null 2>&1") != 0)
+       if (testsuite_setup_gpghome ())
                return EXIT_FAILURE;
        
        for (i = 1; i < argc; i++) {
@@ -489,7 +483,7 @@ int main (int argc, char *argv[])
        
        g_mime_shutdown ();
        
-       if (system ("/bin/rm -rf ./tmp") != 0)
+       if (testsuite_destroy_gpghome ())
                return EXIT_FAILURE;
        
        return testsuite_exit ();
diff --git a/tests/test-smime.c b/tests/test-smime.c
index f05e03a..f35fbb7 100644
--- a/tests/test-smime.c
+++ b/tests/test-smime.c
@@ -420,13 +420,7 @@ int main (int argc, char *argv[])
        
        testsuite_init (argc, argv);
        
-       /* reset .gnupg config directory */
-       if (system ("/bin/rm -rf ./tmp") != 0)
-               return EXIT_FAILURE;
-       if (system ("/bin/mkdir ./tmp") != 0)
-               return EXIT_FAILURE;
-       g_setenv ("GNUPGHOME", "./tmp/.gnupg", 1);
-       if (system ("gpg --list-keys > /dev/null 2>&1") != 0)
+       if (testsuite_setup_gpghome ())
                return EXIT_FAILURE;
        
        for (i = 1; i < argc; i++) {
@@ -490,7 +484,7 @@ int main (int argc, char *argv[])
        
        g_mime_shutdown ();
        
-       if (system ("/bin/rm -rf ./tmp") != 0)
+       if (testsuite_destroy_gpghome ())
                return EXIT_FAILURE;
        
        return testsuite_exit ();
diff --git a/tests/testsuite.c b/tests/testsuite.c
index 2b72301..acd36a5 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -346,6 +346,27 @@ g_throw (Exception *ex)
        longjmp (env->env, 1);
  }
+int
+testsuite_setup_gpghome ()
+{
+       /* reset .gnupg config directory */
+       if (system ("/bin/rm -rf ./tmp") != 0)
+               return EXIT_FAILURE;
+       if (system ("/bin/mkdir ./tmp") != 0)
+               return EXIT_FAILURE;
+       g_setenv ("GNUPGHOME", "./tmp/.gnupg", 1);
+       if (system ("gpg --list-keys > /dev/null 2>&1") != 0)
+               return EXIT_FAILURE;
+       return EXIT_SUCCESS;
+}
+
+int
+testsuite_destroy_gpghome ()
+{
+       if (system ("/bin/rm -rf ./tmp") != 0)
+               return EXIT_FAILURE;
+       return EXIT_SUCCESS;
+}
#ifdef BUILD
  int main (int argc, char **argv)
diff --git a/tests/testsuite.h b/tests/testsuite.h
index ece9014..6c92a5a 100644
--- a/tests/testsuite.h
+++ b/tests/testsuite.h
@@ -45,6 +45,9 @@ void testsuite_check_passed (void);
int testsuite_total_errors (void); +/* for those parts of the test suite that use GnuPG */
+int testsuite_setup_gpghome (void);
+int testsuite_destroy_gpghome (void);
/*#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
  #define G_GNUC_NORETURN __attribute__((noreturn))




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