]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: add helper for VIR_TEST_REGENERATE_OUTPUT flag
authorPavel Hrdina <phrdina@redhat.com>
Thu, 10 Dec 2015 12:30:37 +0000 (13:30 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Fri, 8 Jan 2016 15:05:26 +0000 (16:05 +0100)
When this flag is specified, some of the expected output files will be
regenerated with the actual output data.  Use helper function like for
other flags.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
tests/testutils.c
tests/testutils.h

index 857e8195f0da6cd9598a094b468912b586e8a11b..2b0d3b6e679d9c3d970d679854709d1badf1358d 100644 (file)
@@ -67,6 +67,7 @@ VIR_LOG_INIT("tests.testutils");
 static unsigned int testDebug = -1;
 static unsigned int testVerbose = -1;
 static unsigned int testExpensive = -1;
+static unsigned int testRegenerate = -1;
 
 #ifdef TEST_OOM
 static unsigned int testOOM;
@@ -598,9 +599,8 @@ virtTestCompareToFile(const char *strcontent,
     int ret = -1;
     char *filecontent = NULL;
     char *fixedcontent = NULL;
-    bool regenerate = !!virTestGetFlag("VIR_TEST_REGENERATE_OUTPUT");
 
-    if (virtTestLoadFile(filename, &filecontent) < 0 && !regenerate)
+    if (virtTestLoadFile(filename, &filecontent) < 0 && !virTestGetRegenerate())
         goto failure;
 
     if (filecontent &&
@@ -612,7 +612,7 @@ virtTestCompareToFile(const char *strcontent,
 
     if (STRNEQ_NULLABLE(fixedcontent ? fixedcontent : strcontent,
                         filecontent)) {
-        if (regenerate) {
+        if (virTestGetRegenerate()) {
             if (virFileWriteStr(filename, strcontent, 0666) < 0)
                 goto failure;
             goto out;
@@ -716,6 +716,14 @@ virTestGetExpensive(void)
     return testExpensive;
 }
 
+unsigned int
+virTestGetRegenerate(void)
+{
+    if (testRegenerate == -1)
+        testRegenerate = virTestGetFlag("VIR_TEST_REGENERATE_OUTPUT");
+    return testRegenerate;
+}
+
 int virtTestMain(int argc,
                  char **argv,
                  int (*func)(void))
index ccf1d29e141705471015e234096c8201852a7830..8ef70e40b86417ae09e622947d93d096259fd3e5 100644 (file)
@@ -77,6 +77,7 @@ int virtTestCompareToFile(const char *strcontent,
 unsigned int virTestGetDebug(void);
 unsigned int virTestGetVerbose(void);
 unsigned int virTestGetExpensive(void);
+unsigned int virTestGetRegenerate(void);
 
 # define VIR_TEST_DEBUG(...)                    \
     do {                                        \