tests: Add newlines with VIR_TEST_REGENERATE_OUTPUT

Message ID 4aba1552490509234ac6be10eb7c4534fa892287.1451935906.git.crobinso@redhat.com
State New
Headers show

Commit Message

Cole Robinson Jan. 4, 2016, 7:31 p.m.
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(-)

-- 
2.5.0

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

Patch

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;
 }