From 931ee28eb9c5b5e3c2b0d3008f5f65d810dc9b0c Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Thu, 20 Jun 2024 15:10:56 -0400 Subject: Unit tests (#6) * Initial commit of unit tests [WIP] * Address shortcomings and bugs flushed out by unit tests * Enable unit testing in CI workflow * Enable verbose ctests * Handle lack of __FILE_NAME__ define * Only podman support `run --arch` argument * Skip docker build testing if CI system cannot pull an image * Remove errant call to puts() * Identify local repo user * Fix missing xmllint * NULL terminate arrays * Fix filename assignment in is_url mode * Break loop when expected lines are exhausted * strcmp_array expects NULL terminated array. Iterating by size in this case passes NULL to strcmp leading to an invalid read * Remove debug printf statements * Disable a few warnings for tests * Workaround for ctest junit xml truncation * Update checkout@v4 * Prevent false-positive result * Return zero on error * Fix strlist_remove function * Value argument can be constant * Fix test to match changes to startswith and endswith * Add test_ini.c * Fix redaction code to accept NULL pointers in array * And let the caller specify the length of the array of strings to redact. * Redactions now occur directly on authentication strings rather than their command line arguments * Fix BUILD_TESTING_DEBUG * Adds missing -D argument --- include/str.h | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) (limited to 'include/str.h') diff --git a/include/str.h b/include/str.h index 8018cc0..595a055 100644 --- a/include/str.h +++ b/include/str.h @@ -29,7 +29,7 @@ int num_chars(const char *sptr, int ch); * * @param sptr string to scan * @param pattern string to search for - * @return 1 = found, 0 = not found, -1 = error + * @return 1 = found, 0 = not found / error */ int startswith(const char *sptr, const char *pattern); @@ -38,7 +38,7 @@ int startswith(const char *sptr, const char *pattern); * * @param sptr string to scan * @param pattern string to search for - * @return 1 = found, 0 = not found, -1 = error + * @return 1 = found, 0 = not found / error */ int endswith(const char *sptr, const char *pattern); @@ -50,33 +50,6 @@ int endswith(const char *sptr, const char *pattern); */ void strchrdel(char *sptr, const char *chars); -/** - * Find the integer offset of the first occurrence of `ch` in `sptr` - * - * ~~~{.c} - * char buffer[255]; - * char string[] = "abc=123"; - * long int separator_offset = strchroff(string, '='); - * for (long int i = 0; i < separator_offset); i++) { - * buffer[i] = string[i]; - * } - * ~~~ - * - * @param sptr string to scan - * @param ch character to find - * @return offset to character in string, or 0 on failure - */ -long int strchroff(const char *sptr, int ch); - -/** - * This function scans `sptr` from right to left removing any matches to `suffix` - * from the string. - * - * @param sptr string to be modified - * @param suffix string to be removed from `sptr` - */ -void strdelsuffix(char *sptr, const char *suffix); - /** * Split a string by every delimiter in `delim` string. * -- cgit