[PATCH v2 1/2] tests: utils: Allow NULL strings to be equal to empty file in virTestCompareToFile

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

 



Treat an NULL string equivalent to an empty string in
virTestCompareToFile so that callers don't need to add additional logic
in case when a test produces no output.
---
 tests/testutils.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tests/testutils.c b/tests/testutils.c
index 40e9650fd..71692f1fa 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -777,6 +777,8 @@ int virTestDifferenceBin(FILE *stream,
 /*
  * @param strcontent: String input content
  * @param filename: File to compare strcontent against
+ *
+ * If @strcontent is NULL, it's treated as an empty string.
  */
 int
 virTestCompareToFile(const char *strcontent,
@@ -787,6 +789,9 @@ virTestCompareToFile(const char *strcontent,
     char *fixedcontent = NULL;
     const char *cmpcontent = strcontent;

+    if (!cmpcontent)
+        cmpcontent = "";
+
     if (virTestLoadFile(filename, &filecontent) < 0 && !virTestGetRegenerate())
         goto failure;

-- 
2.13.2

--
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]
  Powered by Linux