]> git.ipfire.org Git - pakfire.git/commitdiff
tests: parser: Check if appending variables works
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Nov 2022 13:02:30 +0000 (13:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 30 Nov 2022 13:02:30 +0000 (13:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/parser.c

index fa5f6599372d352d0f200c56c9588c3eb8327214..179aae877fc705b668107a1e3ebdee6975345529 100644 (file)
@@ -149,6 +149,54 @@ FAIL:
        return r;
 }
 
+static int test_append(const struct test* t) {
+       int r = EXIT_FAILURE;
+
+       // Create a new parser
+       struct pakfire_parser* parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0);
+
+       const char* str1 =
+               "a  = 1\n"
+               "a += 2\n";
+
+       // Parse something
+       ASSERT_SUCCESS(pakfire_parser_parse(parser, str1, strlen(str1), NULL));
+
+       ASSERT_STRING_EQUALS(pakfire_parser_get(parser, NULL, "a"), "1 2");
+
+       const char* str2 =
+               "build\n"
+
+               // Append something to a variable that exists outside of this block
+               "       a += 3\n"
+
+               // Check if we can inherit a local value correctly
+               "       b = %{a}\n"
+
+               // Define a new variable in this block and append something
+               "       c = 10\n"
+               "       c += 20\n"
+               "end\n";
+
+       ASSERT_SUCCESS(pakfire_parser_parse(parser, str2, strlen(str2), NULL));
+
+       ASSERT_STRING_EQUALS(pakfire_parser_get(parser, "build", "a"), "1 2 3");
+       ASSERT_STRING_EQUALS(pakfire_parser_get(parser, "build", "b"), "1 2 3");
+       ASSERT_STRING_EQUALS(pakfire_parser_get(parser, "build", "c"), "10 20");
+
+       // Dump the parser
+       char* s = pakfire_parser_dump(parser);
+       printf("%s\n", s);
+
+       // Everything passed
+       r = EXIT_SUCCESS;
+
+FAIL:
+       if (parser)
+               pakfire_parser_unref(parser);
+
+       return r;
+}
 #if 0
 static int test_parser_command(const struct test* t) {
        const char* command = "%(echo \"ABC\")";
@@ -179,6 +227,7 @@ FAIL:
 int main(int argc, const char* argv[]) {
        testsuite_add_test(test_parser);
        testsuite_add_test(test_parser_files);
+       testsuite_add_test(test_append);
 #if 0
        testsuite_add_test(test_parser_command);
 #endif