mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
tests: fix use of fixedcontent variable
Commit 8563560026d192c2cf047b550ffd468692245ed6 switched from hardcoded use of strcontent to hardcoded use of fixedcontent (fixedcontent is *sometimes* a copy of strcontent with a \n appended). This was a problem because sometimes fixedcontent is *not* a copy of strcontent, but is instead NULL, leading to the regenerated test case output being a 0 length file. This patch creates a new const char *cmpcontent initialized to strcontent, but changed to fixedcontent if/when fixedcontent is created, then always uses cmpcontent instead of (str|fixed)content.
This commit is contained in:
parent
381b9d0b0a
commit
4e2d642afb
@ -694,6 +694,7 @@ virTestCompareToFile(const char *strcontent,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *filecontent = NULL;
|
char *filecontent = NULL;
|
||||||
char *fixedcontent = NULL;
|
char *fixedcontent = NULL;
|
||||||
|
const char *cmpcontent = strcontent;
|
||||||
|
|
||||||
if (virTestLoadFile(filename, &filecontent) < 0 && !virTestGetRegenerate())
|
if (virTestLoadFile(filename, &filecontent) < 0 && !virTestGetRegenerate())
|
||||||
goto failure;
|
goto failure;
|
||||||
@ -703,13 +704,13 @@ virTestCompareToFile(const char *strcontent,
|
|||||||
strcontent[strlen(strcontent) - 1] != '\n') {
|
strcontent[strlen(strcontent) - 1] != '\n') {
|
||||||
if (virAsprintf(&fixedcontent, "%s\n", strcontent) < 0)
|
if (virAsprintf(&fixedcontent, "%s\n", strcontent) < 0)
|
||||||
goto failure;
|
goto failure;
|
||||||
|
cmpcontent = fixedcontent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STRNEQ_NULLABLE(fixedcontent ? fixedcontent : strcontent,
|
if (STRNEQ_NULLABLE(cmpcontent, filecontent)) {
|
||||||
filecontent)) {
|
|
||||||
virTestDifferenceFull(stderr,
|
virTestDifferenceFull(stderr,
|
||||||
filecontent, filename,
|
filecontent, filename,
|
||||||
fixedcontent, NULL);
|
cmpcontent, NULL);
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user