]> xenbits.xensource.com Git - libvirt.git/commitdiff
test: xml2xml: Print full filenames if xml2xml test fails
authorPeter Krempa <pkrempa@redhat.com>
Wed, 29 Oct 2014 14:53:36 +0000 (15:53 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 21 Nov 2014 10:00:10 +0000 (11:00 +0100)
To simplify looking for a problem instrument the XML comparator function
with possibility to print the filename of the failed/expected XML
output.

This is necessary as the VIR_TEST_DIFFERENT macro possibly tests two XML
files for the inactive/active state and the resulting error may not be
obvious.

tests/qemuxml2xmltest.c
tests/testutils.c
tests/testutils.h

index ca11e90ebb632d054f1f5f34e91aae77664a4e0d..a5dccd5afaa1f89a99c6ff0a3c1f6311ebeb34c2 100644 (file)
@@ -50,7 +50,7 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live)
         goto fail;
 
     if (STRNEQ(outXmlData, actual)) {
-        virtTestDifference(stderr, outXmlData, actual);
+        virtTestDifferenceFull(stderr, outXmlData, outxml, actual, inxml);
         goto fail;
     }
 
index 9d6980f9ce24e5e869cb70d57c14cb99689802f2..9a79f98018c15c58fe8b02d58fa032dae13090ae 100644 (file)
@@ -450,14 +450,19 @@ virtTestCaptureProgramOutput(const char *const argv[] ATTRIBUTE_UNUSED,
 /**
  * @param stream: output stream write to differences to
  * @param expect: expected output text
+ * @param expectName: name designator of the expected text
  * @param actual: actual output text
+ * @param actualName: name designator of the actual text
  *
- * Display expected and actual output text, trimmed to
- * first and last characters at which differences occur
+ * Display expected and actual output text, trimmed to first and last
+ * characters at which differences occur. Displays names of the text strings if
+ * non-NULL.
  */
-int virtTestDifference(FILE *stream,
-                       const char *expect,
-                       const char *actual)
+int virtTestDifferenceFull(FILE *stream,
+                           const char *expect,
+                           const char *expectName,
+                           const char *actual,
+                           const char *actualName)
 {
     const char *expectStart;
     const char *expectEnd;
@@ -495,11 +500,15 @@ int virtTestDifference(FILE *stream,
     }
 
     /* Show the trimmed differences */
+    if (expectName)
+        fprintf(stream, "\nIn '%s':", expectName);
     fprintf(stream, "\nOffset %d\nExpect [", (int) (expectStart - expect));
     if ((expectEnd - expectStart + 1) &&
         fwrite(expectStart, (expectEnd-expectStart+1), 1, stream) != 1)
         return -1;
     fprintf(stream, "]\n");
+    if (actualName)
+        fprintf(stream, "In '%s':\n", actualName);
     fprintf(stream, "Actual [");
     if ((actualEnd - actualStart + 1) &&
         fwrite(actualStart, (actualEnd-actualStart+1), 1, stream) != 1)
@@ -512,6 +521,22 @@ int virtTestDifference(FILE *stream,
     return 0;
 }
 
+/**
+ * @param stream: output stream write to differences to
+ * @param expect: expected output text
+ * @param actual: actual output text
+ *
+ * Display expected and actual output text, trimmed to
+ * first and last characters at which differences occur
+ */
+int virtTestDifference(FILE *stream,
+                       const char *expect,
+                       const char *actual)
+{
+    return virtTestDifferenceFull(stream, expect, NULL, actual, NULL);
+}
+
+
 /**
  * @param stream: output stream write to differences to
  * @param expect: expected output text
index ad28ea78c05cfb6821077f7528ff06f64c54a26b..d78818d34e66e13ff8e42c365981e5de7a90c820 100644 (file)
@@ -64,6 +64,11 @@ void virtTestClearCommandPath(char *cmdset);
 int virtTestDifference(FILE *stream,
                        const char *expect,
                        const char *actual);
+int virtTestDifferenceFull(FILE *stream,
+                           const char *expect,
+                           const char *expectName,
+                           const char *actual,
+                           const char *actualName);
 int virtTestDifferenceBin(FILE *stream,
                           const char *expect,
                           const char *actual,