mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-21 19:02:25 +00:00
testutils: Introduce helper for stripping bulilddir/srcdir from test outputs
In certain cases we want to be able to compare test output containing real paths against a static output file and thus we need a helper which strips srcdir/builddir from given path. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
aea559fa74
commit
de59c4bba2
@ -1117,3 +1117,33 @@ const char
|
||||
|
||||
return virtTestCounterStr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virTestStablePath:
|
||||
* @path: path to make stable
|
||||
*
|
||||
* If @path starts with the absolute source directory path, the prefix
|
||||
* is replaced with the string "ABS_SRCDIR" and similarly the build directory
|
||||
* is replaced by "ABS_BUILDDIR". This is useful when paths e.g. in output
|
||||
* test files need to be made stable.
|
||||
*
|
||||
* If @path is NULL the equivalent to NULLSTR(path) is returned.
|
||||
*
|
||||
* The caller is responsible for freeing the returned buffer.
|
||||
*/
|
||||
char *
|
||||
virTestStablePath(const char *path)
|
||||
{
|
||||
const char *tmp;
|
||||
|
||||
path = NULLSTR(path);
|
||||
|
||||
if ((tmp = STRSKIP(path, abs_srcdir)))
|
||||
return g_strdup_printf("ABS_SRCDIR%s", tmp);
|
||||
|
||||
if ((tmp = STRSKIP(path, abs_builddir)))
|
||||
return g_strdup_printf("ABS_BUILDDIR%s", tmp);
|
||||
|
||||
return g_strdup(path);
|
||||
}
|
||||
|
@ -170,3 +170,6 @@ int testCompareDomXML2XMLFiles(virCaps *caps,
|
||||
bool live,
|
||||
unsigned int parseFlags,
|
||||
testCompareDomXML2XMLResult expectResult);
|
||||
|
||||
char *
|
||||
virTestStablePath(const char *path);
|
||||
|
Loading…
x
Reference in New Issue
Block a user