diff options
author | Joseph Hunkeler <jhunkeler@users.noreply.github.com> | 2024-07-06 09:49:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-06 09:49:51 -0400 |
commit | 8ce824ac4b2f526331093a7150e643700efd4d20 (patch) | |
tree | 99e27dee24e82d78941ded4c510e1bac57c3f015 /tests | |
parent | abe87056faa6ed02aff3bbf77c1fd78b713a0864 (diff) | |
download | stasis-8ce824ac4b2f526331093a7150e643700efd4d20.tar.gz |
Add github.c and github.h (#9)
* Add github.c and github.h
* Implements get_github_release_notes()
* Remove unused variables
* Fix circular dependency on tplfunc_frame
* Remove predeclaration of tplfunc_frame
* tpl_register_func accepts pointer to void instead
* tpl_register_func sets maximum number of arguments
* Frame is generated within tpl_register_func
* Improve template function error handling and return/output management
* Remove redundant extern statement
* Include github.h and template_func_proto.h in core.h
* Expose get_github_release_notes_tplfunc_entrypoint function to template engine
* Add template_func_proto.c and template_func_proto.h
* Replace free() with guard variant
* Fix test_template::test_tpl_register_func
* Fix tests
* Fix tests
* cmd should be at least PATH_MAX in size.
* Magic number caused failure to install conda with a long installation path
* Implement get_github_release_notes_auto function that bases release note data off test contexts
* Disable overwriting releases by default
* Add automatic release note generation function call to release_notes.md.in
* Fix test_tpl_register_func()
* Add enough space for tar command plus a path
* Fix circular include
* Github functions do not require access to core.h anyway
* Add comments to union
* Update README to mention template function availability
* Add EnvCtl structure
* Add runtime checks to avoid running all the way to the end only to be met with a configuration error.
* Rename GITHUB to GH
* Development docs pre-rough-draft
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_str.c | 18 | ||||
-rw-r--r-- | tests/test_strlist.c | 4 | ||||
-rw-r--r-- | tests/test_template.c | 41 |
3 files changed, 38 insertions, 25 deletions
diff --git a/tests/test_str.c b/tests/test_str.c index be3f3e1..85c3b78 100644 --- a/tests/test_str.c +++ b/tests/test_str.c @@ -204,7 +204,7 @@ void test_split() { for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char **result; result = split(tc[i].data, tc[i].delim, tc[i].max_split); - STASIS_ASSERT(strcmp_array(result, tc[i].expected) == 0, "Split failed"); + STASIS_ASSERT(strcmp_array((const char **) result, tc[i].expected) == 0, "Split failed"); GENERIC_ARRAY_FREE(result); } } @@ -223,7 +223,7 @@ void test_join() { }; for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char *result; - result = join(tc[i].data, tc[i].delim); + result = join((char **) tc[i].data, tc[i].delim); STASIS_ASSERT(strcmp(result ? result : "", tc[i].expected) == 0, "failed to join array"); guard_free(result); } @@ -276,19 +276,19 @@ void test_substring_between() { void test_strdeldup() { struct testcase { - const char **data; + char **data; const char **expected; }; struct testcase tc[] = { {.data = NULL, .expected = NULL}, - {.data = (const char *[]) {"a", "a", "a", "b", "b", "b", "c", "c", "c", NULL}, .expected = (const char *[]) {"a", "b", "c", NULL}}, - {.data = (const char *[]) {"a", "b", "c", "a", "b", "c", "a", "b", "c", NULL}, .expected = (const char *[]) {"a", "b", "c", NULL}}, - {.data = (const char *[]) {"apple", "banana", "coconut", NULL}, .expected = (const char *[]) {"apple", "banana", "coconut", NULL}}, - {.data = (const char *[]) {"apple", "banana", "apple", "coconut", NULL}, .expected = (const char *[]) {"apple", "banana", "coconut", NULL}}, + {.data = (char *[]) {"a", "a", "a", "b", "b", "b", "c", "c", "c", NULL}, .expected = (const char *[]) {"a", "b", "c", NULL}}, + {.data = (char *[]) {"a", "b", "c", "a", "b", "c", "a", "b", "c", NULL}, .expected = (const char *[]) {"a", "b", "c", NULL}}, + {.data = (char *[]) {"apple", "banana", "coconut", NULL}, .expected = (const char *[]) {"apple", "banana", "coconut", NULL}}, + {.data = (char *[]) {"apple", "banana", "apple", "coconut", NULL}, .expected = (const char *[]) {"apple", "banana", "coconut", NULL}}, }; for (size_t i = 0; i < sizeof(tc) / sizeof(*tc); i++) { char **result = strdeldup(tc[i].data); - STASIS_ASSERT(strcmp_array(result, tc[i].expected) == 0, "incorrect number of duplicates removed"); + STASIS_ASSERT(strcmp_array((const char **) result, tc[i].expected) == 0, "incorrect number of duplicates removed"); GENERIC_ARRAY_FREE(result); } } @@ -374,4 +374,4 @@ int main(int argc, char *argv[]) { }; STASIS_TEST_RUN(tests); STASIS_TEST_END_MAIN(); -}
\ No newline at end of file +} diff --git a/tests/test_strlist.c b/tests/test_strlist.c index 723c904..90219bd 100644 --- a/tests/test_strlist.c +++ b/tests/test_strlist.c @@ -144,7 +144,7 @@ void test_strlist_append_file() { right = expected[z]; STASIS_ASSERT(strcmp(left, right) == 0, "file content is different than expected"); } - STASIS_ASSERT(strcmp_array(list->data, expected) == 0, "file contents does not match expected values"); + STASIS_ASSERT(strcmp_array((const char **) list->data, expected) == 0, "file contents does not match expected values"); guard_strlist_free(&list); } } @@ -614,4 +614,4 @@ int main(int argc, char *argv[]) { }; STASIS_TEST_RUN(tests); STASIS_TEST_END_MAIN(); -}
\ No newline at end of file +} diff --git a/tests/test_template.c b/tests/test_template.c index 05d8242..79fce5e 100644 --- a/tests/test_template.c +++ b/tests/test_template.c @@ -9,28 +9,36 @@ extern unsigned tpl_pool_func_used; static int adder(struct tplfunc_frame *frame, void *result) { int a = (int) strtol(frame->argv[0].t_char_ptr, NULL, 10); int b = (int) strtol(frame->argv[1].t_char_ptr, NULL, 10); - sprintf(result, "%d", a + b); + char **ptr = (char **) result; + *ptr = calloc(100, sizeof(*ptr)); + sprintf(*ptr, "%d", a + b); return 0; } static int subtractor(struct tplfunc_frame *frame, void *result) { int a = (int) strtol(frame->argv[0].t_char_ptr, NULL, 10); int b = (int) strtol(frame->argv[1].t_char_ptr, NULL, 10); - sprintf(result, "%d", a - b); + char **ptr = (char **) result; + *ptr = calloc(100, sizeof(*ptr)); + sprintf(*ptr, "%d", a - b); return 0; } static int multiplier(struct tplfunc_frame *frame, void *result) { int a = (int) strtol(frame->argv[0].t_char_ptr, NULL, 10); int b = (int) strtol(frame->argv[1].t_char_ptr, NULL, 10); - sprintf(result, "%d", a * b); + char **ptr = (char **) result; + *ptr = calloc(100, sizeof(*ptr)); + sprintf(*ptr, "%d", a * b); return 0; } static int divider(struct tplfunc_frame *frame, void *result) { int a = (int) strtol(frame->argv[0].t_char_ptr, NULL, 10); int b = (int) strtol(frame->argv[1].t_char_ptr, NULL, 10); - sprintf(result, "%d", a / b); + char **ptr = (char **) result; + *ptr = calloc(100, sizeof(*ptr)); + sprintf(*ptr, "%d", a / b); return 0; } @@ -59,17 +67,22 @@ void test_tpl_register() { void test_tpl_register_func() { tpl_reset(); - struct tplfunc_frame tasks[] = { - {.key = "add", .argc = 2, .func = adder}, - {.key = "sub", .argc = 2, .func = subtractor}, - {.key = "mul", .argc = 2, .func = multiplier}, - {.key = "div", .argc = 2, .func = divider}, + struct testcase { + const char *key; + int argc; + void *func; }; - tpl_register_func("add", &tasks[0]); - tpl_register_func("sub", &tasks[1]); - tpl_register_func("mul", &tasks[2]); - tpl_register_func("div", &tasks[3]); - STASIS_ASSERT(tpl_pool_func_used == sizeof(tasks) / sizeof(*tasks), "unexpected function pool used"); + struct testcase tc[] = { + {.key = "add", .argc = 2, .func = &adder}, + {.key = "sub", .argc = 2, .func = &subtractor}, + {.key = "mul", .argc = 2, .func = &multiplier}, + {.key = "div", .argc = 2, .func = ÷r}, + }; + tpl_register_func("add", tc[0].func, tc[0].argc, NULL); + tpl_register_func("sub", tc[1].func, tc[1].argc, NULL); + tpl_register_func("mul", tc[2].func, tc[2].argc, NULL); + tpl_register_func("div", tc[3].func, tc[3].argc, NULL); + STASIS_ASSERT(tpl_pool_func_used == sizeof(tc) / sizeof(*tc), "unexpected function pool used"); char *result = NULL; result = tpl_render("{{ func:add(0,3) }}"); |