This patch enable regeneration of expected output file for
virTestDifferenceFull. It also introduces new
virTestDifferenceFullNoRegenerate function for special cases, where we
don't want to regenerate output.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
tests/qemuxml2xmltest.c | 8 ++++--
tests/testutils.c | 76 +++++++++++++++++++++++++++++++++++++++++++------
tests/testutils.h | 5 ++++
3 files changed, 77 insertions(+), 12 deletions(-)
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index f967ceb..2312f72 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -188,9 +188,11 @@ testCompareStatusXMLToXMLFiles(const void *opaque)
}
if (STRNEQ(actual, expect)) {
- virtTestDifferenceFull(stderr,
- expect, data->outActiveName,
- actual, data->inName);
+ /* For status test we don't want to regenerate output to not
+ * add the status data.*/
+ virtTestDifferenceFullNoRegenerate(stderr,
+ expect, data->outActiveName,
+ actual, data->inName);
goto cleanup;
}
diff --git a/tests/testutils.c b/tests/testutils.c
index 2b0d3b6..70e3456 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -440,16 +440,19 @@ virtTestCaptureProgramOutput(const char *const argv[]
ATTRIBUTE_UNUSED,
* @param expectName: name designator of the expected text
* @param actual: actual output text
* @param actualName: name designator of the actual text
+ * @param regenerate: enable or disable regenerate functionality
*
* 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 virtTestDifferenceFull(FILE *stream,
- const char *expect,
- const char *expectName,
- const char *actual,
- const char *actualName)
+static int
+virtTestDifferenceFullInternal(FILE *stream,
+ const char *expect,
+ const char *expectName,
+ const char *actual,
+ const char *actualName,
+ bool regenerate)
{
const char *expectStart;
const char *expectEnd;
@@ -466,6 +469,12 @@ int virtTestDifferenceFull(FILE *stream,
actualStart = actual;
actualEnd = actual + (strlen(actual)-1);
+ if (regenerate && virTestGetRegenerate() > 0) {
+ if (expectName && actual &&
+ virFileWriteStr(expectName, actual, 0666) < 0)
+ return -1;
+ }
+
if (!virTestGetDebug())
return 0;
@@ -511,16 +520,65 @@ int virtTestDifferenceFull(FILE *stream,
/**
* @param stream: output stream to write 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. Displays names of the text strings if
+ * non-NULL. If VIR_TEST_REGENERATE_OUTPUT is used, this function will
+ * regenerate the expected file.
+ */
+int
+virtTestDifferenceFull(FILE *stream,
+ const char *expect,
+ const char *expectName,
+ const char *actual,
+ const char *actualName)
+{
+ return virtTestDifferenceFullInternal(stream, expect, expectName,
+ actual, actualName, true);
+}
+
+/**
+ * @param stream: output stream to write 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. Displays names of the text strings if
+ * non-NULL. If VIR_TEST_REGENERATE_OUTPUT is used, this function will not
+ * regenerate the expected file.
+ */
+int
+virtTestDifferenceFullNoRegenerate(FILE *stream,
+ const char *expect,
+ const char *expectName,
+ const char *actual,
+ const char *actualName)
+{
+ return virtTestDifferenceFullInternal(stream, expect, expectName,
+ actual, actualName, false);
+}
+
+/**
+ * @param stream: output stream to write 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)
+int
+virtTestDifference(FILE *stream,
+ const char *expect,
+ const char *actual)
{
- return virtTestDifferenceFull(stream, expect, NULL, actual, NULL);
+ return virtTestDifferenceFullNoRegenerate(stream,
+ expect, NULL,
+ actual, NULL);
}
diff --git a/tests/testutils.h b/tests/testutils.h
index 8ef70e4..3bd9004 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -67,6 +67,11 @@ int virtTestDifferenceFull(FILE *stream,
const char *expectName,
const char *actual,
const char *actualName);
+int virtTestDifferenceFullNoRegenerate(FILE *stream,
+ const char *expect,
+ const char *expectName,
+ const char *actual,
+ const char *actualName);
int virtTestDifferenceBin(FILE *stream,
const char *expect,
const char *actual,
--
2.6.3