tests: add helper for VIR_TEST_REGENERATE_OUTPUT flag

When this flag is specified, some of the expected output files will be
regenerated with the actual output data.  Use helper function like for
other flags.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2015-12-10 13:30:37 +01:00
parent 4100aecd13
commit 0104c43195
2 changed files with 12 additions and 3 deletions

View File

@ -67,6 +67,7 @@ VIR_LOG_INIT("tests.testutils");
static unsigned int testDebug = -1;
static unsigned int testVerbose = -1;
static unsigned int testExpensive = -1;
static unsigned int testRegenerate = -1;
#ifdef TEST_OOM
static unsigned int testOOM;
@ -598,9 +599,8 @@ virtTestCompareToFile(const char *strcontent,
int ret = -1;
char *filecontent = NULL;
char *fixedcontent = NULL;
bool regenerate = !!virTestGetFlag("VIR_TEST_REGENERATE_OUTPUT");
if (virtTestLoadFile(filename, &filecontent) < 0 && !regenerate)
if (virtTestLoadFile(filename, &filecontent) < 0 && !virTestGetRegenerate())
goto failure;
if (filecontent &&
@ -612,7 +612,7 @@ virtTestCompareToFile(const char *strcontent,
if (STRNEQ_NULLABLE(fixedcontent ? fixedcontent : strcontent,
filecontent)) {
if (regenerate) {
if (virTestGetRegenerate()) {
if (virFileWriteStr(filename, strcontent, 0666) < 0)
goto failure;
goto out;
@ -716,6 +716,14 @@ virTestGetExpensive(void)
return testExpensive;
}
unsigned int
virTestGetRegenerate(void)
{
if (testRegenerate == -1)
testRegenerate = virTestGetFlag("VIR_TEST_REGENERATE_OUTPUT");
return testRegenerate;
}
int virtTestMain(int argc,
char **argv,
int (*func)(void))

View File

@ -77,6 +77,7 @@ int virtTestCompareToFile(const char *strcontent,
unsigned int virTestGetDebug(void);
unsigned int virTestGetVerbose(void);
unsigned int virTestGetExpensive(void);
unsigned int virTestGetRegenerate(void);
# define VIR_TEST_DEBUG(...) \
do { \