]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: utils: Allow NULL strings to be equal to empty file in virTestCompareToFile
authorPeter Krempa <pkrempa@redhat.com>
Fri, 28 Jul 2017 10:37:48 +0000 (12:37 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 28 Jul 2017 15:59:06 +0000 (17:59 +0200)
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

index 40e9650fdd3ca8bc14c0d405dd81a6d4c37b7a1c..71692f1fa56316145d1fc4cd1461f5231a920aeb 100644 (file)
@@ -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;