[network-manager-openvpn] properties/tests: use separate output directory for tests



commit f00efbaacde08827f714d02a94c6f936ee5562b9
Author: Thomas Haller <thaller redhat com>
Date:   Wed Mar 2 13:18:38 2016 +0100

    properties/tests: use separate output directory for tests
    
    When building in-tree, SRCDIR and TMPDIR would point to the
    same directory. Which means that test_tls_inline_import()
    would overwrite the configuration files to which it tries
    to assert against.
    
    For out-of-tree builds, the directories differed. Commit
    b2c41184de73c tried to fix a failure of `make distcheck`.
    That however is wrong for the in-tree case, where it would
    delete files from the source tree.

 properties/tests/test-import-export.c |   27 +++++++++++++++++++++------
 1 files changed, 21 insertions(+), 6 deletions(-)
---
diff --git a/properties/tests/test-import-export.c b/properties/tests/test-import-export.c
index 7aef1c2..763e785 100644
--- a/properties/tests/test-import-export.c
+++ b/properties/tests/test-import-export.c
@@ -24,6 +24,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <locale.h>
+#include <sys/stat.h>
 
 #include "nm-default.h"
 
@@ -33,11 +34,8 @@
 
 #include "nm-test-utils.h"
 
-#define TEST_SRCDIR_CONF     TEST_SRCDIR"/conf"
-#define TEST_BUILDDIR_CONF   TEST_BUILDDIR"/conf"
-
-#define SRCDIR TEST_SRCDIR_CONF
-#define TMPDIR TEST_BUILDDIR_CONF
+#define SRCDIR TEST_SRCDIR"/conf"
+#define TMPDIR TEST_BUILDDIR"/conf-tmp"
 
 /*****************************************************************************/
 
@@ -1308,10 +1306,18 @@ NMTST_DEFINE ();
 
 int main (int argc, char **argv)
 {
+       int errsv, result;
+
        _nmovpn_test_temp_path = TMPDIR;
 
        nmtst_init (&argc, &argv, TRUE);
 
+       if (mkdir (TMPDIR, 0755) != 0) {
+               errsv = errno;
+               if (errsv != EEXIST)
+                       g_error ("failed creating \"%s\": %s", TMPDIR, g_strerror (errsv));
+       }
+
 #define _add_test_func_simple(func)       g_test_add_func ("/ovpn/properties/" #func, func)
 #define _add_test_func(detail, func, ...) nmtst_add_test_func ("/ovpn/properties/" detail, func, 
##__VA_ARGS__)
 
@@ -1370,6 +1376,15 @@ int main (int argc, char **argv)
 
        _add_test_func_simple (test_args_parse_line);
 
-       return g_test_run ();
+       result = g_test_run ();
+       if (result != EXIT_SUCCESS)
+               return result;
+
+       if (rmdir (TMPDIR) != 0) {
+               errsv = errno;
+               g_error ("failed deleting %s: %s", TMPDIR, g_strerror (errsv));
+       }
+
+       return EXIT_SUCCESS;
 }
 


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