diff options
author | EuAndreh <eu@euandre.org> | 2024-04-06 11:37:04 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-04-06 11:37:04 -0300 |
commit | 3b32f5a1abbec9655a93a184ed0a3c5e6e5134fd (patch) | |
tree | 03969b7b76835f2507ccd1a8aeb057bb1d7f7201 /tests | |
parent | src/: Remove unused "infallible" tag (diff) | |
download | pindaiba-3b32f5a1abbec9655a93a184ed0a3c5e6e5134fd.tar.gz pindaiba-3b32f5a1abbec9655a93a184ed0a3c5e6e5134fd.tar.xz |
Start "rc = -1" instead of 0
Diffstat (limited to 'tests')
-rw-r--r-- | tests/catalog.c | 39 | ||||
-rw-r--r-- | tests/i18n.c | 4 | ||||
-rw-r--r-- | tests/logerr.c | 26 | ||||
-rw-r--r-- | tests/random.c | 10 | ||||
-rw-r--r-- | tests/slurp.c | 9 | ||||
-rw-r--r-- | tests/testing.c | 6 |
6 files changed, 28 insertions, 66 deletions
diff --git a/tests/catalog.c b/tests/catalog.c index d357175..5e5a430 100644 --- a/tests/catalog.c +++ b/tests/catalog.c @@ -28,7 +28,7 @@ TEST_MSGS[] = { static int test_i18n_init(void) { - int rc = 0; + int rc = -1; test_start("i18n_init()"); @@ -39,19 +39,18 @@ test_i18n_init(void) { if (setenv(NLSPATH_KEY, "src/%N.en.cat", should_overwrite)) { logerr("setenv(\"%s\", \"src/%%N.en.cat\", 1): %s\n", NLSPATH_KEY, strerror(errno)); - rc = -1; goto out; } if (i18n_init()) { logerr("i18n_init()\n"); - rc = -1; goto out; } test_ok(); } + rc = 0; out: if (i18n_destroy()) { logerr("i18n_destroy()\n"); @@ -62,7 +61,7 @@ out: static int test_s_print_msgs(void) { - int rc = 0; + int rc = -1; test_start("s_print_msgs()"); FILE *file = NULL; @@ -74,13 +73,11 @@ test_s_print_msgs(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } if (s_print_msgs(TEST_MSGS, file, MSG_X_FIRST, MSG_X_LAST)) { logerr("print_msgs(TEST_MSGS, file, MSG_X_FIRST, MSG_X_LAST)\n"); - rc = -1; goto out; } @@ -88,13 +85,11 @@ test_s_print_msgs(void) { file = NULL; if (ret) { logerr("fclose(file): %s\n", strerror(errno)); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { logerr("slurp_for_tests(FNAME, &str)\n"); - rc = -1; goto out; } @@ -118,13 +113,11 @@ test_s_print_msgs(void) { file = fopen(FNAME, "w"); if (!file) { logerr("fopen(FNAME, \"w\"): %s\n", strerror(errno)); - rc = -1; goto out; } if (s_print_msgs(TEST_MSGS, file, MSG_X_FIRST, MSG_X_FIRST)) { logerr("s_print_msgs(TEST_MSGS, file, MSG_X_FIRST, MSG_X_FIRST)\n"); - rc = -1; goto out; } @@ -132,13 +125,11 @@ test_s_print_msgs(void) { file = NULL; if (ret) { logerr("fclose(file): %s\n", strerror(errno)); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { logerr("slurp_for_tests(FNAME, &str)\n"); - rc = -1; goto out; } @@ -153,6 +144,7 @@ test_s_print_msgs(void) { test_ok(); } + rc = 0; out: if (str) { free(str); @@ -168,7 +160,7 @@ out: static int test_s(void) { - int rc = 0; + int rc = -1; test_start("_()"); FILE *file = NULL; @@ -180,7 +172,6 @@ test_s(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } @@ -191,6 +182,7 @@ test_s(void) { test_ok(); } + rc = 0; out: if (str) { free(str); @@ -206,7 +198,7 @@ out: static int test_i18n_destroy(void) { - int rc = 0; + int rc = -1; test_start("i18n_destroy()"); @@ -215,20 +207,20 @@ test_i18n_destroy(void) { if (i18n_destroy()) { logerr("i18n_destroy()\n"); - rc = -1; goto out; } test_ok(); } + rc = 0; out: return rc; } static int test_s_print_msg(void) { - int rc = 0; + int rc = -1; test_start("s_print_msg()"); FILE *file = NULL; @@ -240,13 +232,11 @@ test_s_print_msg(void) { file = fopen(FNAME, "w"); if (!file) { logerr("fopen(FNAME, \"w\"): %s\n"); - rc = -1; goto out; } if (s_print_msg(TEST_MSGS, file, MSG_STANDALONE)) { logerr("s_print_msg(TEST_MSGS, file, MSG_STANDALONE)\n"); - rc = -1; goto out; } @@ -254,13 +244,11 @@ test_s_print_msg(void) { file = NULL; if (ret) { logerr("fopen(file): %s\n", strerror(errno)); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { logerr("slurp_for_tests(FNAME, &str)\n"); - rc = -1; goto out; } @@ -275,6 +263,7 @@ test_s_print_msg(void) { test_ok(); } + rc = 0; out: if (str) { free(str); @@ -290,38 +279,34 @@ out: int main(void) { - int rc = 0; + int rc = -1; if (test_i18n_init()) { logerr("test_i18n_init()\n"); - rc = -1; goto out; } if (test_i18n_destroy()) { logerr("test_i18n_destroy()\n"); - rc = -1; goto out; } if (test_s()) { logerr("test_s()\n"); - rc = -1; goto out; } if (test_s_print_msgs()) { logerr("test_s_print_msgs()\n"); - rc = -1; goto out; } if (test_s_print_msg()) { logerr("test_s_print_msg()\n"); - rc = -1; goto out; } + rc = 0; out: return !!rc; } diff --git a/tests/i18n.c b/tests/i18n.c index 60e4620..369a63d 100644 --- a/tests/i18n.c +++ b/tests/i18n.c @@ -8,16 +8,16 @@ int main(void) { - int rc = 0; + int rc = -1; if (getenv("DUMP_TRANSLATABLE_STRINGS")) { if (dump_translatable_strings(MSGS)) { logerr("dump_translatable_strings(MSGS)\n"); - rc = -1; goto out; } } + rc = 0; out: return !!rc; } diff --git a/tests/logerr.c b/tests/logerr.c index 78cdf10..86b6b1c 100644 --- a/tests/logerr.c +++ b/tests/logerr.c @@ -14,7 +14,7 @@ FNAME = __FILE__ ".txt"; static int test_vlogerr(void) { - int rc = 0; + int rc = -1; test_start("vlogerr()"); FILE *file = NULL; @@ -26,7 +26,6 @@ test_vlogerr(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } @@ -38,13 +37,11 @@ test_vlogerr(void) { file = NULL; if (ret) { perror("fclose(file)"); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { perror("slurp_for_tests(FNAME, &str)"); - rc = -1; goto out; } @@ -63,7 +60,6 @@ test_vlogerr(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } @@ -75,13 +71,11 @@ test_vlogerr(void) { file = NULL; if (ret) { perror("fclose(file)"); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { perror("slurp_for_tests(FNAME, &str)"); - rc = -1; goto out; } @@ -100,7 +94,6 @@ test_vlogerr(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } @@ -112,13 +105,11 @@ test_vlogerr(void) { file = NULL; if (ret) { perror("fclose(file)"); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { perror("slurp_for_tests(FNAME, &str)"); - rc = -1; goto out; } @@ -137,7 +128,6 @@ test_vlogerr(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } @@ -149,13 +139,11 @@ test_vlogerr(void) { file = NULL; if (ret) { perror("fclose(file)"); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { perror("slurp_for_tests(FNAME, &str)"); - rc = -1; goto out; } @@ -174,7 +162,6 @@ test_vlogerr(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } @@ -189,13 +176,11 @@ test_vlogerr(void) { file = NULL; if (ret) { perror("fclose(file)"); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { perror("slurp_for_tests(FNAME, &str)"); - rc = -1; goto out; } @@ -210,6 +195,7 @@ test_vlogerr(void) { test_ok(); } + rc = 0; out: if (str) { free(str); @@ -225,7 +211,7 @@ out: static int test_logerr(void) { - int rc = 0; + int rc = -1; test_start("logerr()"); @@ -258,26 +244,26 @@ test_logerr(void) { test_ok(); } + rc = 0; return rc; } int main(void) { - int rc = 0; + int rc = -1; if (test_vlogerr()) { perror("test_vlogerr()"); - rc = -1; goto out; } if (test_logerr()) { perror("test_logerr()"); - rc = -1; goto out; } + rc = 0; out: return !!rc; } diff --git a/tests/random.c b/tests/random.c index eec83c5..e56e747 100644 --- a/tests/random.c +++ b/tests/random.c @@ -4,7 +4,7 @@ static int test_urandom_bytes(void) { - int rc = 0; + int rc = -1; test_start("urandom_bytes()"); @@ -17,7 +17,6 @@ test_urandom_bytes(void) { for (size_t n = 0; n < LEN; n++) { if (urandom_bytes(n, &arr)) { logerr("urandom_bytes(n, &arr);\n"); - rc = -1; goto out; } for (size_t i = n; i < LEN; i++) { @@ -37,7 +36,6 @@ test_urandom_bytes(void) { if (urandom_bytes(LEN, &arr1)) { logerr("urandom_bytes(LEN, &arr1);\n"); - rc = -1; goto out; } @@ -45,7 +43,6 @@ test_urandom_bytes(void) { for (size_t n = 0; n < attempts; n++) { if (urandom_bytes(LEN, &arr2)) { logerr("urandom_bytes(LEN, &arr2);\n"); - rc = -1; goto out; } assert(memcmp(arr1, arr2, LEN) != 0); @@ -54,20 +51,21 @@ test_urandom_bytes(void) { test_ok(); } + rc = 0; out: return rc; } int main(void) { - int rc = 0; + int rc = -1; if (test_urandom_bytes()) { logerr("test_urandom_bytes();\n"); - rc = -1; goto out; } + rc = 0; out: return !!rc; } diff --git a/tests/slurp.c b/tests/slurp.c index 7b5936f..6ea8618 100644 --- a/tests/slurp.c +++ b/tests/slurp.c @@ -7,7 +7,7 @@ int slurp_for_tests(const char *const FNAME, char **strref) { - int rc = 0; + int rc = -1; FILE *file = NULL; char *str = NULL; @@ -15,45 +15,40 @@ slurp_for_tests(const char *const FNAME, char **strref) { file = fopen(FNAME, "r"); if (!file) { perror("fopen(FNAME, \"r\")"); - rc = -1; goto out; } if (fseek(file, 0L, SEEK_END)) { perror("fseek(file, 0L, SEEK_END)"); - rc = -1; goto out; } const long lsize = ftell(file); if (lsize == -1) { perror("ftell(file)"); - rc = -1; goto out; } const size_t size = (size_t)lsize + sizeof(char); if (fseek(file, 0L, SEEK_SET)) { perror("fseek(file, 0L, SEEK_SET)"); - rc = -1; goto out; } str = malloc(size); if (!str) { perror("malloc(...)"); - rc = -1; goto out; } if (fread(str, sizeof(char), size - 1, file) != size - 1) { perror("fread(...)"); - rc = -1; goto out; } str[size - 1] = '\0'; *strref = str; + rc = 0; out: if (file) { if (fclose(file)) { diff --git a/tests/testing.c b/tests/testing.c index 65012f9..eeb0a39 100644 --- a/tests/testing.c +++ b/tests/testing.c @@ -3,14 +3,13 @@ int main(void) { - int rc = 0; + int rc = -1; test_start("testing.c"); const int should_overwrite = 1; if (unsetenv(ENVVAR_NAME)) { perror("unsetenv(\"NO_COLOR\")"); - rc = -1; goto out; } { @@ -20,7 +19,6 @@ main(void) { if (setenv(ENVVAR_NAME, "", should_overwrite)) { perror("setenv(\"NO_COLOR\", \"\", 1)"); - rc = -1; goto out; } { @@ -30,7 +28,6 @@ main(void) { if (setenv(ENVVAR_NAME, "something", should_overwrite)) { perror("setenv(\"NO_COLOR\", \"something\", 1)"); - rc = -1; goto out; } { @@ -38,6 +35,7 @@ main(void) { test_ok(); } + rc = 0; out: return !!rc; } |