]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
testutils: Introduce helper for stripping bulilddir/srcdir from test outputs
authorPeter Krempa <pkrempa@redhat.com>
Tue, 7 Sep 2021 13:31:42 +0000 (15:31 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 9 Sep 2021 13:29:00 +0000 (15:29 +0200)
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>
tests/testutils.c
tests/testutils.h

index 5e9835ee89d0e2b63e7e28a1a9aa46c6a08dcd8c..185d281e96c1969c53897db0d6b740ef23417457 100644 (file)
@@ -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);
+}
index 48de864131698e8ede1713512664826ea80e1d81..27d135fc02f20fed10ad1e96b9b2116f45dd95bd 100644 (file)
@@ -170,3 +170,6 @@ int testCompareDomXML2XMLFiles(virCaps *caps,
                                bool live,
                                unsigned int parseFlags,
                                testCompareDomXML2XMLResult expectResult);
+
+char *
+virTestStablePath(const char *path);