提交 781d70c0 编写于 作者: P Pavel Hrdina

tests.testutils: use VIR_TEST_REGENERATE_OUTPUT for virTestDifferenceFull

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: NPavel Hrdina <phrdina@redhat.com>
上级 0104c431
......@@ -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;
}
......
......@@ -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;
......@@ -508,6 +517,52 @@ int virtTestDifferenceFull(FILE *stream,
return 0;
}
/**
* @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
......@@ -516,11 +571,14 @@ int virtTestDifferenceFull(FILE *stream,
* 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);
}
......
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册