[PATCH 02/10] tests: introduce VIR_TEST_REGENERATE_OUTPUT flag

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

 



When this flag is specified, some of the expected output files will be
regenerated with the actual output data.  This is a helper for updating
test data.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 tests/testutils.c | 14 +++++++++++---
 tests/testutils.h |  1 +
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/tests/testutils.c b/tests/testutils.c
index 857e819..2b0d3b6 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -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))
diff --git a/tests/testutils.h b/tests/testutils.h
index ccf1d29..8ef70e4 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -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 {                                        \
-- 
2.6.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]