mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-21 20:15:17 +00:00
tests: Add VIR_TEST_REGENERATE_OUTPUT
If this enviroment variable is set, the virTestCompareToFile helper will overwrite the file content we are comparing against, if the file doesn't exist or it doesn't match the expected input. This is useful when adding new test cases, or making changes that generate a lot of output churn.
This commit is contained in:
parent
ca32929908
commit
edb27a7048
7
HACKING
7
HACKING
@ -136,6 +136,13 @@ Also, individual tests can be run from inside the "tests/" directory, like:
|
||||
|
||||
./qemuxml2xmltest
|
||||
|
||||
If you are adding new test cases, or making changes that alter existing test
|
||||
output, you can use the environment variable VIR_TEST_REGENERATE_OUTPUT to
|
||||
quickly update the saved test data. Of course you still need to review the
|
||||
changes VERY CAREFULLY to ensure they are correct.
|
||||
|
||||
VIR_TEST_REGENERATE_OUTPUT=1 ./qemuxml2argvtest
|
||||
|
||||
There is also a "./run" script at the top level, to make it easier to run
|
||||
programs that have not yet been installed, as well as to wrap invocations of
|
||||
various tests under gdb or Valgrind.
|
||||
|
@ -164,6 +164,18 @@
|
||||
<pre>
|
||||
./qemuxml2xmltest
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
If you are adding new test cases, or making changes that alter
|
||||
existing test output, you can use the environment variable
|
||||
VIR_TEST_REGENERATE_OUTPUT to quickly update the saved test data.
|
||||
Of course you still need to review the changes VERY CAREFULLY to
|
||||
ensure they are correct.
|
||||
</p>
|
||||
<pre>
|
||||
VIR_TEST_REGENERATE_OUTPUT=1 ./qemuxml2argvtest
|
||||
</pre>
|
||||
|
||||
<p>There is also a <code>./run</code> script at the top level,
|
||||
to make it easier to run programs that have not yet been
|
||||
installed, as well as to wrap invocations of various tests
|
||||
|
@ -91,6 +91,21 @@ bool virtTestOOMActive(void)
|
||||
return testOOMActive;
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
virTestGetFlag(const char *name)
|
||||
{
|
||||
char *flagStr;
|
||||
unsigned int flag;
|
||||
|
||||
if ((flagStr = getenv(name)) == NULL)
|
||||
return 0;
|
||||
|
||||
if (virStrToLong_ui(flagStr, NULL, 10, &flag) < 0)
|
||||
return 0;
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
#ifdef TEST_OOM_TRACE
|
||||
static void virTestAllocHook(int nalloc ATTRIBUTE_UNUSED,
|
||||
void *opaque ATTRIBUTE_UNUSED)
|
||||
@ -607,21 +622,30 @@ 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)
|
||||
if (virtTestLoadFile(filename, &filecontent) < 0 && !regenerate)
|
||||
goto failure;
|
||||
|
||||
if (filecontent[strlen(filecontent) - 1] == '\n' &&
|
||||
if (filecontent &&
|
||||
filecontent[strlen(filecontent) - 1] == '\n' &&
|
||||
strcontent[strlen(strcontent) - 1] != '\n') {
|
||||
if (virAsprintf(&fixedcontent, "%s\n", strcontent) < 0)
|
||||
goto failure;
|
||||
}
|
||||
|
||||
if (STRNEQ(fixedcontent ? fixedcontent : strcontent, filecontent)) {
|
||||
if (STRNEQ_NULLABLE(fixedcontent ? fixedcontent : strcontent,
|
||||
filecontent)) {
|
||||
if (regenerate) {
|
||||
if (virFileWriteStr(filename, strcontent, 0666) < 0)
|
||||
goto failure;
|
||||
goto out;
|
||||
}
|
||||
virtTestDifference(stderr, strcontent, filecontent);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
out:
|
||||
ret = 0;
|
||||
failure:
|
||||
VIR_FREE(fixedcontent);
|
||||
@ -692,21 +716,6 @@ virtTestLogContentAndReset(void)
|
||||
}
|
||||
|
||||
|
||||
static unsigned int
|
||||
virTestGetFlag(const char *name)
|
||||
{
|
||||
char *flagStr;
|
||||
unsigned int flag;
|
||||
|
||||
if ((flagStr = getenv(name)) == NULL)
|
||||
return 0;
|
||||
|
||||
if (virStrToLong_ui(flagStr, NULL, 10, &flag) < 0)
|
||||
return 0;
|
||||
|
||||
return flag;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
virTestGetDebug(void)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user