# 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:
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();
}