summaryrefslogtreecommitdiff
path: root/tests/errors.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/errors.c')
-rw-r--r--tests/errors.c43
1 files changed, 14 insertions, 29 deletions
diff --git a/tests/errors.c b/tests/errors.c
index d1dec96..1411d0e 100644
--- a/tests/errors.c
+++ b/tests/errors.c
@@ -1,39 +1,24 @@
#include "test.h"
-#include <dirent.h>
#include <stdlib.h>
#include <string.h>
-void test_errors(const char *test_dir) {
- char *errors_dir = malloc(strlen(test_dir) + 30);
- sprintf(errors_dir, "%s/errors", test_dir);
- DIR *dir = opendir(errors_dir);
- if (!dir) {
- test_fail("Couldn't open test directory %s", errors_dir);
+void test_errors(void) {
+ char **listing = list_dir("errors", ".pom");
+ if (!listing)
return;
- }
- struct dirent *ent;
- while ((ent = readdir(dir))) {
- const char *name = ent->d_name;
- if (strlen(name) >= strlen("x.pom") &&
- strcmp(name + strlen(name) - strlen(".pom"), ".pom") == 0) {
- printf("Testing %s...\n",name);
- char *conf_path = malloc(strlen(errors_dir) + strlen(name) + 30);
- sprintf(conf_path, "%s/errors/%s", test_dir, name);
- pom_error *error;
- pom_conf *conf = pom_load_path(NULL, conf_path, &error);
- if (error) {
- free(error);
- free(conf_path);
- continue;
- }
- test_fail("Parsing %s didn't produce an error but it should have.",
- conf_path);
- pom_conf_free(conf);
- free(conf_path);
+ for (size_t i = 0; listing[i]; i++) {
+ const char *conf_path = listing[i];
+ printf("Testing %s...\n",conf_path);
+ pom_error *error;
+ pom_conf *conf = pom_load_path(NULL, conf_path, &error);
+ if (error) {
+ free(error);
+ continue;
}
+ test_fail("Parsing %s didn't produce an error but it should have.", conf_path);
+ pom_conf_free(conf);
}
- closedir(dir);
- free(errors_dir);
+ free_listing(listing);
// pom_conf *conf = pom_load_path("../tests");
}