diff options
Diffstat (limited to 'tests/parsing.c')
-rw-r--r-- | tests/parsing.c | 99 |
1 files changed, 42 insertions, 57 deletions
diff --git a/tests/parsing.c b/tests/parsing.c index c28df0d..670361a 100644 --- a/tests/parsing.c +++ b/tests/parsing.c @@ -1,68 +1,53 @@ #include "test.h" -#include <dirent.h> #include <stdlib.h> #include <string.h> -void test_parsing(const char *test_dir) { - char *parsing_dir = malloc(strlen(test_dir) + 30); - sprintf(parsing_dir, "%s/parsing", test_dir); - DIR *dir = opendir(parsing_dir); - if (!dir) { - test_fail("Couldn't open test directory %s", parsing_dir); - return; - } - struct dirent *ent; - while ((ent = readdir(dir))) { - const char *name = ent->d_name; - if (strlen(name) >= strlen("x.flat.pom") && - strcmp(name + strlen(name) - strlen(".flat.pom"), ".flat.pom") == 0) { - printf("Testing %s...\n",name); - char *conf_path = malloc(strlen(parsing_dir) + strlen(name) + 30); - char *flat_path = malloc(strlen(parsing_dir) + strlen(name) + 30); - sprintf(conf_path, "%s/parsing/%.*s.pom", test_dir, - (int)(strlen(name) - strlen(".flat.pom")), name); - sprintf(flat_path, "%s/parsing/%s", test_dir, name); - pom_error *error; - pom_conf *conf = pom_load_path(NULL, conf_path, &error); - if (error) { - test_fail("Failed to parse %s\n%s", conf_path, - pom_error_to_string(error)); - continue; - } - pom_conf *flat = pom_load_path(NULL, flat_path, &error); - if (error) { - test_fail("Failed to parse %s\n%s", flat_path, - pom_error_to_string(error)); - continue; +void test_parsing(void) { + char **listing = list_dir("parsing", ".flat.pom"); + for (size_t i = 0; listing[i]; i++) { + const char *flat_path = listing[i]; + printf("Testing %s...\n",flat_path); + char *conf_path = malloc(strlen(flat_path)); + sprintf(conf_path, "%.*s.pom", + (int)(strlen(flat_path) - strlen(".flat.pom")), flat_path); + pom_error *error; + pom_conf *conf = pom_load_path(NULL, conf_path, &error); + if (error) { + test_fail("Failed to parse %s\n%s", conf_path, + pom_error_to_string(error)); + continue; + } + pom_conf *flat = pom_load_path(NULL, flat_path, &error); + if (error) { + test_fail("Failed to parse %s\n%s", flat_path, + pom_error_to_string(error)); + continue; + } + const pom_item *item; + pom_item_iter *iter = NULL; + while ((item = pom_conf_next_item(conf, &iter))) { + if (!pom_conf_has(flat, item->key)) { + test_fail("%s has key '%s' but %s doesn't", + conf_path, item->key, flat_path); } - const pom_item *item; - pom_item_iter *iter = NULL; - while ((item = pom_conf_next_item(conf, &iter))) { - if (!pom_conf_has(flat, item->key)) { - test_fail("%s has key '%s' but %s doesn't", - conf_path, item->key, flat_path); - } + } + while ((item = pom_conf_next_item(flat, &iter))) { + const char *conf_value = pom_conf_get(conf, item->key); + if (!conf_value) { + test_fail("%s has key '%s' but %s doesn't", + flat_path, item->key, conf_path); } - while ((item = pom_conf_next_item(flat, &iter))) { - const char *conf_value = pom_conf_get(conf, item->key); - if (!conf_value) { - test_fail("%s has key '%s' but %s doesn't", - flat_path, item->key, conf_path); - } - if (strcmp(conf_value, item->value) != 0) { - test_fail("Mismatch between %s and %s at key '%s'\n" - "expected: %s\n" - " got: %s\n", - flat_path, conf_path, item->key, item->value, conf_value); - } + if (strcmp(conf_value, item->value) != 0) { + test_fail("Mismatch between %s and %s at key '%s'\n" + "expected: %s\n" + " got: %s\n", + flat_path, conf_path, item->key, item->value, conf_value); } - pom_conf_free(conf); - pom_conf_free(flat); - free(conf_path); - free(flat_path); } + pom_conf_free(conf); + pom_conf_free(flat); + free(conf_path); } - closedir(dir); - free(parsing_dir); + free_listing(listing); } |