[libvirt] [PATCH] tests: Add newlines with VIR_TEST_REGENERATE_OUTPUT

Cole Robinson crobinso at redhat.com
Mon Jan 4 19:31:58 UTC 2016


Since test files are formatted predictably nowadays, we can make
VIR_TEST_REGENERATE_OUTPUT handle most cases for us with a simple
replacement. test-wrap-argv.pl is still canon, but this bit makes
it easier to confirm test output changes during active development.
---
 tests/testutils.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tests/testutils.c b/tests/testutils.c
index 857e819..6487a62 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -598,6 +598,7 @@ virtTestCompareToFile(const char *strcontent,
     int ret = -1;
     char *filecontent = NULL;
     char *fixedcontent = NULL;
+    char *regencontent = NULL;
     bool regenerate = !!virTestGetFlag("VIR_TEST_REGENERATE_OUTPUT");
 
     if (virtTestLoadFile(filename, &filecontent) < 0 && !regenerate)
@@ -613,7 +614,10 @@ virtTestCompareToFile(const char *strcontent,
     if (STRNEQ_NULLABLE(fixedcontent ? fixedcontent : strcontent,
                         filecontent)) {
         if (regenerate) {
-            if (virFileWriteStr(filename, strcontent, 0666) < 0)
+            if (!(regencontent = virStringReplace(strcontent, " -", " \\\n-")))
+                goto failure;
+
+            if (virFileWriteStr(filename, regencontent, 0666) < 0)
                 goto failure;
             goto out;
         }
@@ -626,6 +630,7 @@ virtTestCompareToFile(const char *strcontent,
  failure:
     VIR_FREE(fixedcontent);
     VIR_FREE(filecontent);
+    VIR_FREE(regencontent);
     return ret;
 }
 
-- 
2.5.0




More information about the libvir-list mailing list