Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR cleanup code #44

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add null checking
dreamer-coding committed Dec 4, 2024

Verified

This commit was signed with the committer’s verified signature.
commit 9735ae81aae36163f32dc63d6fdce70a134bca78
33 changes: 27 additions & 6 deletions code/logic/testing.c
Original file line number Diff line number Diff line change
@@ -463,6 +463,10 @@ void shuffle_test_cases(test_case_t **test_cases) {
// Creates and returns a new test suite
test_suite_t* fossil_test_create_suite(const char *name) {
test_suite_t *suite = (test_suite_t*)malloc(sizeof(test_suite_t));
if (!suite) {
return NULL;
}

suite->name = name;
suite->suite_setup_func = NULL;
suite->suite_teardown_func = NULL;
@@ -473,7 +477,10 @@ test_suite_t* fossil_test_create_suite(const char *name) {

// Registers a test suite in the environment
void fossil_test_register_suite(fossil_test_env_t *env, test_suite_t *suite) {
if (!suite) return;
if (!env || !suite) {
return;
}

suite->next = env->test_suites;
env->test_suites = suite;
if (env->options.show_info) {
@@ -483,15 +490,19 @@ void fossil_test_register_suite(fossil_test_env_t *env, test_suite_t *suite) {

// Adds a test case to a suite
void fossil_test_add_case(test_suite_t *suite, test_case_t *test_case) {
if (!suite || !test_case) return;
if (!suite || !test_case) {
return;
}

test_case->next = suite->tests;
suite->tests = test_case;
}

// Removes and frees a test case from a suite
void fossil_test_remove_case(test_suite_t *suite, test_case_t *test_case) {
if (!suite || !test_case) return;
if (!suite || !test_case) {
return;
}

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

// Run all test cases in a test suite
void fossil_test_run_suite(test_suite_t *suite, fossil_test_env_t *env) {
if (!suite) return;
if (!suite || !env) {
return;
}

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

// Run an individual test case
void fossil_test_run_case(test_case_t *test_case, fossil_test_env_t *env) {
if (!test_case) return;
if (!test_case) {
return;
}

test_case->status = TEST_STATUS_PASS;

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

void fossil_test_run_all(fossil_test_env_t *env) {
if (!env) {
return;
}

test_suite_t *current_suite = env->test_suites;

while (current_suite) {
@@ -666,10 +685,12 @@ void fossil_test_init(fossil_test_env_t *env, int argc, char **argv) {
version_info();
exit(EXIT_SUCCESS);
}

if (env->options.show_help) {
usage_info();
exit(EXIT_SUCCESS);
}

env->pass_count = 0;
env->fail_count = 0;
env->skip_count = 0;
@@ -696,7 +717,7 @@ void fossil_test_message(fossil_test_env_t *env) {
} else if (env->timeout_count > 0) {
printf(FOSSIL_TEST_COLOR_ORANGE FOSSIL_TEST_ATTR_ITATIC "%s\n" FOSSIL_TEST_COLOR_RESET, timeout_messages[rand() % 30]);
} else {
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_ITATIC "Test results are in. Keep pushing, you're getting there! 💪\n" FOSSIL_TEST_COLOR_RESET);
puts(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_ITATIC "Test results are in. Keep pushing, you're getting there!" FOSSIL_TEST_COLOR_RESET);
}
}

Loading