]> git.ipfire.org Git - pakfire.git/commitdiff
parser: Move test cases into many smaller files
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 24 Feb 2021 11:35:37 +0000 (11:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 24 Feb 2021 11:35:37 +0000 (11:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
tests/data/parser/test-comments.txt [new file with mode: 0644]
tests/data/parser/test-declarations.txt [new file with mode: 0644]
tests/libpakfire/parser.c

index 50882996956d609a7ff5791e8565bc5e8235ee33..2ace7d7fd11935b1937a04da2f47f771bbc8b9c5 100644 (file)
@@ -645,7 +645,10 @@ TESTS = \
 # Some test data to run tests
 EXTRA_DIST += \
        tests/data/726D8B0B0889B04E.key \
-       tests/data/beep-1.3-2.ip3.x86_64.pfm
+       tests/data/beep-1.3-2.ip3.x86_64.pfm \
+       \
+       tests/data/parser/test-comments.txt \
+       tests/data/parser/test-declarations.txt
 
 .PHONY: clean-local-check
 clean-local-check:
diff --git a/tests/data/parser/test-comments.txt b/tests/data/parser/test-comments.txt
new file mode 100644 (file)
index 0000000..74d7310
--- /dev/null
@@ -0,0 +1 @@
+# This is a comment which should be ignored
diff --git a/tests/data/parser/test-declarations.txt b/tests/data/parser/test-declarations.txt
new file mode 100644 (file)
index 0000000..75b12dc
--- /dev/null
@@ -0,0 +1,13 @@
+a = 1
+b = 2
+c = %{a}%{b}
+
+# Append something
+d = A
+d += BC
+
+# Multi-line
+lines
+       line 1
+       line 2
+end
index f40c28dcfe91022ff475963e399a31a5d98f551b..74f075979bbb3effbfa9e1a8eff2e0993e6abddf 100644 (file)
@@ -103,36 +103,45 @@ static int test_parser(const struct test* t) {
        return EXIT_SUCCESS;
 }
 
-static int test_parser_assign(const struct test* t) {
-       PakfireParser parser = pakfire_parser_create(t->pakfire, NULL, NULL);
+static const char* files[] = {
+       "data/parser/test-comments.txt",
+       "data/parser/test-declarations.txt",
+       NULL,
+};
 
-       static const char* INPUT =
-               "a = 1\n"
-               "b = 2\n"
-               "c = %{a}%{b}\n"
-               "d = A\n"
-               "d += BC\n"
-               "lines\n\tline 1\n\tline 2\nend\n";
+static int test_parser_files(const struct test* t) {
+       const char** file = files;
 
-       int r = pakfire_parser_parse(parser, INPUT, strlen(INPUT));
-       ASSERT(r == 0);
+       while (*file) {
+               char* path = pakfire_path_join(TEST_SRC_PATH, *file);
+               ASSERT(path);
 
-       // Dump the parser
-       char* s = pakfire_parser_dump(parser);
-       printf("%s\n", s);
-       free(s);
+               // Create a new parser
+               PakfireParser parser = pakfire_parser_create(t->pakfire, NULL, NULL);
 
-       char* value = pakfire_parser_get(parser, "d");
-       ASSERT_STRING_EQUALS(value, "ABC");
+               FILE* f = fopen(path, "r");
+               ASSERT(f);
 
-       pakfire_parser_unref(parser);
+               int r = pakfire_parser_read(parser, f);
+               if (r) {
+                       fprintf(stderr, "Could not parse %s\n", path);
+                       return EXIT_FAILURE;
+               }
+
+               fclose(f);
+               pakfire_parser_unref(parser);
+               free(path);
+
+               // Next file
+               file++;
+       }
 
        return EXIT_SUCCESS;
 }
 
 int main(int argc, char** argv) {
        testsuite_add_test(test_parser);
-       testsuite_add_test(test_parser_assign);
+       testsuite_add_test(test_parser_files);
 
        return testsuite_run();
 }