From: Michael Tremer Date: Wed, 30 Nov 2022 13:02:30 +0000 (+0000) Subject: tests: parser: Check if appending variables works X-Git-Tag: 0.9.28~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d5bca0c6426b3b95acf846393cb5dab1dde80006;p=pakfire.git tests: parser: Check if appending variables works Signed-off-by: Michael Tremer --- diff --git a/tests/libpakfire/parser.c b/tests/libpakfire/parser.c index fa5f65993..179aae877 100644 --- a/tests/libpakfire/parser.c +++ b/tests/libpakfire/parser.c @@ -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