In some cases we have directories with mixed XML files in the test
suite. Adding regex filtering will allow testing subsets of the XML
files against schema.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
tests/virschematest.c | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/tests/virschematest.c b/tests/virschematest.c
index e6e176eef3..7d7db3e354 100644
--- a/tests/virschematest.c
+++ b/tests/virschematest.c
@@ -32,6 +32,10 @@ VIR_LOG_INIT("tests.schematest");
struct testSchemaEntry {
const char *dir;
+ /* if dirRegex is non-NULL the provided regular expression is used to match
+ * the file names in a directory (without path prefixed) and only matching
+ * files are validated */
+ const char *dirRegex;
const char *file;
};
@@ -79,18 +83,29 @@ testSchemaFile(const char *schema,
static int
testSchemaDir(const char *schema,
virXMLValidatorPtr validator,
- const char *dir_path)
+ const char *dir_path,
+ const char *filterstr)
{
DIR *dir = NULL;
struct dirent *ent;
int ret = 0;
int rc;
+ g_autoptr(GRegex) filter = NULL;
if (virDirOpen(&dir, dir_path) < 0) {
virTestPropagateLibvirtError();
return -1;
}
+ if (filterstr) {
+ g_autoptr(GError) err = NULL;
+
+ if (!(filter = g_regex_new(filterstr, 0, 0, &err))) {
+ VIR_TEST_VERBOSE("\nfailed to compile regex '%s': %s",
filterstr, err->message);
+ return -1;
+ }
+ }
+
while ((rc = virDirRead(dir, &ent, dir_path)) > 0) {
g_autofree char *xml_path = NULL;
@@ -98,6 +113,9 @@ testSchemaDir(const char *schema,
continue;
if (ent->d_name[0] == '.')
continue;
+ if (filter &&
+ !g_regex_match(filter, ent->d_name, 0, NULL))
+ continue;
xml_path = g_strdup_printf("%s/%s", dir_path, ent->d_name);
@@ -176,7 +194,7 @@ testSchemaEntries(const char *schema,
if (entry->dir) {
g_autofree char *path = g_strdup_printf("%s/%s", abs_top_srcdir,
entry->dir);
- if (testSchemaDir(schema, validator, path) < 0)
+ if (testSchemaDir(schema, validator, path, entry->dirRegex) < 0)
ret = -1;
}
--
2.26.2