summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-09-15 13:52:32 -0400
committerpommicket <pommicket@gmail.com>2025-09-15 13:52:32 -0400
commitee88497b4451225c3140f56d98ebcbc166175407 (patch)
tree39cd720c4840c2872fb065088b91658ef6d8d3d1 /tests
parent969bf523b7039c7038b66edde5776278c27941ac (diff)
Errors tests; fix some non-errors
Diffstat (limited to 'tests')
-rw-r--r--tests/errors.c38
-rw-r--r--tests/main.c13
-rw-r--r--tests/parsing.c3
-rw-r--r--tests/test.h1
4 files changed, 51 insertions, 4 deletions
diff --git a/tests/errors.c b/tests/errors.c
new file mode 100644
index 0000000..8a255ab
--- /dev/null
+++ b/tests/errors.c
@@ -0,0 +1,38 @@
+#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);
+ 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(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);
+ }
+ }
+ free(errors_dir);
+// pom_conf *conf = pom_load_path("../tests");
+}
diff --git a/tests/main.c b/tests/main.c
index 7b791cd..ff68df3 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -2,6 +2,8 @@
#include <stdarg.h>
#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
static bool any_failure = false;
@@ -15,12 +17,19 @@ void test_fail(const char *fmt, ...) {
fprintf(stderr, "\n");
}
-int main(void) {
- const char *test_dir = "../tests";
+int main(int argc, char **argv) {
+ if (argc > 2 || (argc == 2 && strcmp(argv[1], "--help") == 0)) {
+ printf("usage: tests [TEST DIRECTORY]\n");
+ return EXIT_FAILURE;
+ }
+ const char *test_dir = argc == 2 ? argv[1] : "../tests";
test_parsing(test_dir);
+ test_errors(test_dir);
if (any_failure) {
fprintf(stderr, "\x1b[1m\x1b[91mSome tests failed.\x1b[0m\n");
+ return EXIT_FAILURE;
} else {
printf("\x1b[1m\x1b[92mAll tests OK\x1b[0m\n");
+ return 0;
}
}
diff --git a/tests/parsing.c b/tests/parsing.c
index 2b953db..3c321c6 100644
--- a/tests/parsing.c
+++ b/tests/parsing.c
@@ -9,7 +9,7 @@ void test_parsing(const char *test_dir) {
sprintf(parsing_dir, "%s/parsing", test_dir);
DIR *dir = opendir(parsing_dir);
if (!dir) {
- test_fail("Couldn't open test directory %s", test_dir);
+ test_fail("Couldn't open test directory %s", parsing_dir);
return;
}
struct dirent *ent;
@@ -64,5 +64,4 @@ void test_parsing(const char *test_dir) {
}
}
free(parsing_dir);
-// pom_conf *conf = pom_load_path("../tests");
}
diff --git a/tests/test.h b/tests/test.h
index 5e0b8e5..cd19482 100644
--- a/tests/test.h
+++ b/tests/test.h
@@ -15,3 +15,4 @@
void test_fail(PRINTF_FORMAT_STRING const char *, ...) ATTRIBUTE_PRINTF(1, 2);
void test_parsing(const char *test_dir);
+void test_errors(const char *test_dir);