Skip to content

Commit 5f7e45e

Browse files
Merge pull request #44 from dreamer-coding/pr_cleanup
PR cleanup code
2 parents d9cf45d + 9735ae8 commit 5f7e45e

File tree

1 file changed

+59
-21
lines changed

1 file changed

+59
-21
lines changed

code/logic/testing.c

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,22 @@ const char *timeout_messages[] = {
279279

280280
#endif
281281

282+
static const char *FOSSIL_TEST_OPTIONS[] = {
283+
"--version - Displays the current version of Fossil Test\n",
284+
"--help - Shows help message with usage\n",
285+
"--info - Displays detailed information about the test run\n",
286+
};
287+
288+
static const char *FOSSIL_TEST_COMMANDS[] = {
289+
"reverse [enable|disable] - Enables or disables reverse order of test execution\n",
290+
"repeat [count] - Repeats the test suite a specified number of times\n",
291+
"shuffle [enable|disable] - Enables or disables shuffling of test execution order\n",
292+
};
293+
294+
static const char *FOSSIL_TEST_VERSION = "1.1.4"; // Version of Fossil Test
295+
static const char *FOSSIL_TEST_AUTHOR = "Michael Gene Brockus (Dreamer)"; // Author of Fossil Test
296+
static const char *FOSSIL_TEST_LICENSE = "Mozilla Public License 2.0"; // License of Fossil Test
297+
282298
jmp_buf test_jump_buffer; // This will hold the jump buffer for longjmp
283299
static int _ASSERT_COUNT = 0; // Counter for the number of assertions
284300

@@ -308,24 +324,25 @@ fossil_options_t init_options(void) {
308324
}
309325

310326
void usage_info(void) {
311-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Usage: fossil [options] [command]\n" FOSSIL_TEST_COLOR_RESET);
312-
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================\n" FOSSIL_TEST_COLOR_RESET);
313-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_BOLD "Options:\n" FOSSIL_TEST_COLOR_RESET);
314-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC " --version\t\tDisplays the current version of Fossil Test\n" FOSSIL_TEST_COLOR_RESET);
315-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC " --help\t\tShows help message with usage\n" FOSSIL_TEST_COLOR_RESET);
316-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC " --info\t\tDisplays detailed information about the test run.\n" FOSSIL_TEST_COLOR_RESET);
317-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_BOLD "Commands:\n" FOSSIL_TEST_COLOR_RESET);
318-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC " reverse [enable|disable]\tEnables or disables reverse order of test execution\n" FOSSIL_TEST_COLOR_RESET);
319-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC " repeat [count]\t\tRepeats the test suite a specified number of times\n" FOSSIL_TEST_COLOR_RESET);
320-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC " shuffle [enable|disable]\tEnables or disables shuffling of test execution order\n" FOSSIL_TEST_COLOR_RESET);
321-
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================\n" FOSSIL_TEST_COLOR_RESET);
327+
puts(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Usage: fossil [options] [command]" FOSSIL_TEST_COLOR_RESET);
328+
puts(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================" FOSSIL_TEST_COLOR_RESET);
329+
puts(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_BOLD "\tOptions:" FOSSIL_TEST_COLOR_RESET);
330+
for (size_t i = 0; i < sizeof(FOSSIL_TEST_OPTIONS) / sizeof(FOSSIL_TEST_OPTIONS[0]); i++) {
331+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\t>\t%s" FOSSIL_TEST_COLOR_RESET, FOSSIL_TEST_OPTIONS[i]);
332+
}
333+
334+
puts(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_BOLD "\tCommands:" FOSSIL_TEST_COLOR_RESET);
335+
for (size_t i = 0; i < sizeof(FOSSIL_TEST_COMMANDS) / sizeof(FOSSIL_TEST_COMMANDS[0]); i++) {
336+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\t>\t%s" FOSSIL_TEST_COLOR_RESET, FOSSIL_TEST_COMMANDS[i]);
337+
}
338+
puts(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================" FOSSIL_TEST_COLOR_RESET);
322339
}
323340

324341
void version_info(void) {
325-
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "Fossil Logic Test Framework\n");
326-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Version: 1.1.4\n");
327-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Author: Michael Gene Brockus (Dreamer)\n");
328-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "License: Mozila Public License 2.0\n");
342+
puts(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "Fossil Logic Test Framework");
343+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\tVersion: %s\n", FOSSIL_TEST_VERSION);
344+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\tAuthor: %s\n", FOSSIL_TEST_AUTHOR);
345+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\tLicense: %s\n", FOSSIL_TEST_LICENSE);
329346
}
330347

331348
// Parse command-line arguments
@@ -446,6 +463,10 @@ void shuffle_test_cases(test_case_t **test_cases) {
446463
// Creates and returns a new test suite
447464
test_suite_t* fossil_test_create_suite(const char *name) {
448465
test_suite_t *suite = (test_suite_t*)malloc(sizeof(test_suite_t));
466+
if (!suite) {
467+
return NULL;
468+
}
469+
449470
suite->name = name;
450471
suite->suite_setup_func = NULL;
451472
suite->suite_teardown_func = NULL;
@@ -456,7 +477,10 @@ test_suite_t* fossil_test_create_suite(const char *name) {
456477

457478
// Registers a test suite in the environment
458479
void fossil_test_register_suite(fossil_test_env_t *env, test_suite_t *suite) {
459-
if (!suite) return;
480+
if (!env || !suite) {
481+
return;
482+
}
483+
460484
suite->next = env->test_suites;
461485
env->test_suites = suite;
462486
if (env->options.show_info) {
@@ -466,15 +490,19 @@ void fossil_test_register_suite(fossil_test_env_t *env, test_suite_t *suite) {
466490

467491
// Adds a test case to a suite
468492
void fossil_test_add_case(test_suite_t *suite, test_case_t *test_case) {
469-
if (!suite || !test_case) return;
493+
if (!suite || !test_case) {
494+
return;
495+
}
470496

471497
test_case->next = suite->tests;
472498
suite->tests = test_case;
473499
}
474500

475501
// Removes and frees a test case from a suite
476502
void fossil_test_remove_case(test_suite_t *suite, test_case_t *test_case) {
477-
if (!suite || !test_case) return;
503+
if (!suite || !test_case) {
504+
return;
505+
}
478506

479507
test_case_t *prev = NULL;
480508
test_case_t *curr = suite->tests;
@@ -510,7 +538,9 @@ void fossil_test_case_teardown(test_case_t *test_case) {
510538

511539
// Run all test cases in a test suite
512540
void fossil_test_run_suite(test_suite_t *suite, fossil_test_env_t *env) {
513-
if (!suite) return;
541+
if (!suite || !env) {
542+
return;
543+
}
514544

515545
if (env->options.show_info) {
516546
printf(FOSSIL_TEST_COLOR_BLUE "Running suite: %s\n" FOSSIL_TEST_COLOR_RESET, suite->name);
@@ -580,7 +610,9 @@ void fossil_test_assert_internal(bool condition, const char *message, const char
580610

581611
// Run an individual test case
582612
void fossil_test_run_case(test_case_t *test_case, fossil_test_env_t *env) {
583-
if (!test_case) return;
613+
if (!test_case) {
614+
return;
615+
}
584616

585617
test_case->status = TEST_STATUS_PASS;
586618

@@ -635,6 +667,10 @@ void fossil_test_run_case(test_case_t *test_case, fossil_test_env_t *env) {
635667
}
636668

637669
void fossil_test_run_all(fossil_test_env_t *env) {
670+
if (!env) {
671+
return;
672+
}
673+
638674
test_suite_t *current_suite = env->test_suites;
639675

640676
while (current_suite) {
@@ -649,10 +685,12 @@ void fossil_test_init(fossil_test_env_t *env, int argc, char **argv) {
649685
version_info();
650686
exit(EXIT_SUCCESS);
651687
}
688+
652689
if (env->options.show_help) {
653690
usage_info();
654691
exit(EXIT_SUCCESS);
655692
}
693+
656694
env->pass_count = 0;
657695
env->fail_count = 0;
658696
env->skip_count = 0;
@@ -679,7 +717,7 @@ void fossil_test_message(fossil_test_env_t *env) {
679717
} else if (env->timeout_count > 0) {
680718
printf(FOSSIL_TEST_COLOR_ORANGE FOSSIL_TEST_ATTR_ITATIC "%s\n" FOSSIL_TEST_COLOR_RESET, timeout_messages[rand() % 30]);
681719
} else {
682-
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_ITATIC "Test results are in. Keep pushing, you're getting there! 💪\n" FOSSIL_TEST_COLOR_RESET);
720+
puts(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_ITATIC "Test results are in. Keep pushing, you're getting there!" FOSSIL_TEST_COLOR_RESET);
683721
}
684722
}
685723

0 commit comments

Comments
 (0)