Skip to content

Commit 490cb84

Browse files
apply smart summary feature
1 parent 1ba1801 commit 490cb84

File tree

2 files changed

+138
-33
lines changed

2 files changed

+138
-33
lines changed

code/logic/fossil/test/testing.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@
2929
#define FOSSIL_TEST_COLOR_PURPLE "\033[35m" // Purple
3030
#define FOSSIL_TEST_COLOR_ORANGE "\033[38;5;208m" // Orange
3131

32+
// Box-drawing characters
33+
#define TOP_LEFT_CORNER "\u2554"
34+
#define TOP_RIGHT_CORNER "\u2557"
35+
#define BOTTOM_LEFT_CORNER "\u255A"
36+
#define BOTTOM_RIGHT_CORNER "\u255D"
37+
#define HORIZONTAL_BORDER "\u2550"
38+
#define VERTICAL_BORDER "\u2551"
39+
3240
#define FOSSIL_TEST_ATTR_BOLD "\033[1m" // Bold
3341
#define FOSSIL_TEST_ATTR_DIM "\033[2m" // Dim
3442
#define FOSSIL_TEST_ATTR_UNDERLINE "\033[4m" // Underline
35-
#define FOSSIL_TEST_ATTR_ITATIC "\033[3m" // Italic
43+
#define FOSSIL_TEST_ATTR_ITALIC "\033[3m" // Italic
3644

3745

3846
#include <setjmp.h>

code/logic/testing.c

Lines changed: 129 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
#include "fossil/test/testing.h"
1616

17-
1817
// Array of messages for each category
1918
const char *sarcastic_messages[] = {
2019
"Wow, no tests were run! What a productive day!",
@@ -226,6 +225,36 @@ const char *timeout_messages[] = {
226225
"Tests are taking too long. Time to find the bottleneck!"
227226
};
228227

228+
// Suggestions arrays based on different outcomes
229+
const char *empty_suite_suggestions[] = {
230+
"Check if your test suite has defined tests.",
231+
"Make sure your test cases are properly configured.",
232+
"Review the test configuration to ensure it’s correct."
233+
};
234+
235+
const char *failure_suggestions[] = {
236+
"Look into the test failures and their root causes.",
237+
"Check for bugs, missing dependencies, or misconfigured tests.",
238+
"Examine the test environment for potential issues.",
239+
"Review the test case logic and expected behavior.",
240+
"Consider adding more edge cases to capture hidden bugs."
241+
};
242+
243+
const char *success_suggestions[] = {
244+
"Great job! Keep adding tests to cover edge cases.",
245+
"Fantastic! Consider adding performance and stress tests.",
246+
"Success! Now, look at adding additional tests for edge cases.",
247+
"Well done! You’re on the right track, keep it up.",
248+
"Good job! Now, consider reviewing code for possible optimizations."
249+
};
250+
251+
const char *timeout_suggestions[] = {
252+
"Check resource usage and adjust timeout values.",
253+
"Investigate slow-running tests and optimize them.",
254+
"Consider breaking large tests into smaller ones to avoid timeouts.",
255+
"Check for any environmental factors affecting test performance."
256+
};
257+
229258
enum {
230259
_FOSSIL_TEST_RESPONSE_LENGTH = 50
231260
};
@@ -284,25 +313,25 @@ fossil_test_options_t fossil_test_init_options(void) {
284313
}
285314

286315
void usage_info(void) {
287-
puts(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Usage: fossil [options] [command]" FOSSIL_TEST_COLOR_RESET);
316+
puts(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC "Usage: fossil [options] [command]" FOSSIL_TEST_COLOR_RESET);
288317
puts(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================" FOSSIL_TEST_COLOR_RESET);
289318
puts(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_BOLD "\tOptions:" FOSSIL_TEST_COLOR_RESET);
290319
for (size_t i = 0; i < sizeof(FOSSIL_TEST_OPTIONS) / sizeof(FOSSIL_TEST_OPTIONS[0]); i++) {
291-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\t>\t%s" FOSSIL_TEST_COLOR_RESET, FOSSIL_TEST_OPTIONS[i]);
320+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC "\t>\t%s" FOSSIL_TEST_COLOR_RESET, FOSSIL_TEST_OPTIONS[i]);
292321
}
293322

294323
puts(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_BOLD "\tCommands:" FOSSIL_TEST_COLOR_RESET);
295324
for (size_t i = 0; i < sizeof(FOSSIL_TEST_COMMANDS) / sizeof(FOSSIL_TEST_COMMANDS[0]); i++) {
296-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\t>\t%s" FOSSIL_TEST_COLOR_RESET, FOSSIL_TEST_COMMANDS[i]);
325+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC "\t>\t%s" FOSSIL_TEST_COLOR_RESET, FOSSIL_TEST_COMMANDS[i]);
297326
}
298327
puts(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================" FOSSIL_TEST_COLOR_RESET);
299328
}
300329

301330
void version_info(void) {
302331
puts(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "Fossil Logic Test Framework");
303-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\tVersion: %s\n", FOSSIL_TEST_VERSION);
304-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\tAuthor: %s\n", FOSSIL_TEST_AUTHOR);
305-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "\tLicense: %s\n", FOSSIL_TEST_LICENSE);
332+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC "\tVersion: %s\n", FOSSIL_TEST_VERSION);
333+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC "\tAuthor: %s\n", FOSSIL_TEST_AUTHOR);
334+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC "\tLicense: %s\n", FOSSIL_TEST_LICENSE);
306335
}
307336

308337
// Parse command-line arguments
@@ -701,30 +730,99 @@ void fossil_test_init(fossil_test_env_t *env, int argc, char **argv) {
701730
}
702731
}
703732

704-
// Function to generate a dynamic message based on the test results
705-
void fossil_test_message(fossil_test_env_t *env) {
706-
// Seed random number generator
707-
srand(time(NULL));
733+
void fossil_test_sanity(fossil_test_env_t *env) {
734+
if (!env) {
735+
return;
736+
}
708737

738+
// Sanity analysis based on results
709739
if (env->pass_count == 0 && env->fail_count == 0 && env->skip_count == 0 && env->timeout_count == 0 && env->empty_count > 0) {
710-
printf(FOSSIL_TEST_COLOR_YELLOW FOSSIL_TEST_ATTR_ITATIC "%s\n" FOSSIL_TEST_COLOR_RESET, sarcastic_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH]);
740+
// Empty test suite: sarcastic tone
741+
const char *message = sarcastic_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH];
742+
printf(FOSSIL_TEST_COLOR_YELLOW FOSSIL_TEST_ATTR_ITALIC "Hmm, seems like we ran an empty test suite: %s\n" FOSSIL_TEST_COLOR_RESET, message);
743+
printf(FOSSIL_TEST_COLOR_CYAN "Suggestion: %s\n" FOSSIL_TEST_COLOR_RESET, empty_suite_suggestions[rand() % 3]);
711744
} else if (env->fail_count > 0) {
712-
printf(FOSSIL_TEST_COLOR_RED FOSSIL_TEST_ATTR_ITATIC "%s\n" FOSSIL_TEST_COLOR_RESET, humorous_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH]);
745+
// Failures occurred: humorous or frustrated tone
746+
const char *message = humorous_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH];
747+
printf(FOSSIL_TEST_COLOR_RED FOSSIL_TEST_ATTR_ITALIC "Whoops! Looks like some tests didn't pass: %s\n" FOSSIL_TEST_COLOR_RESET, message);
748+
749+
// Analysis of failures
750+
printf(FOSSIL_TEST_COLOR_CYAN "Analysis: %d tests failed. Possible causes include code issues, missing dependencies, or misconfigured tests.\n" FOSSIL_TEST_COLOR_RESET, env->fail_count);
751+
752+
// Suggestion for improvement
753+
printf(FOSSIL_TEST_COLOR_CYAN "Suggestion: %s\n" FOSSIL_TEST_COLOR_RESET, failure_suggestions[rand() % 5]);
713754
} else if (env->pass_count > 0) {
714-
printf(FOSSIL_TEST_COLOR_GREEN FOSSIL_TEST_ATTR_ITATIC "%s\n" FOSSIL_TEST_COLOR_RESET, great_news_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH]);
755+
// Success: positive, motivational tone
756+
const char *message = great_news_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH];
757+
printf(FOSSIL_TEST_COLOR_GREEN FOSSIL_TEST_ATTR_ITALIC "Success! All systems go! Tests passed: %s\n" FOSSIL_TEST_COLOR_RESET, message);
758+
759+
// Analysis of success
760+
printf(FOSSIL_TEST_COLOR_CYAN "Analysis: %d tests passed successfully. Great work!\n", env->pass_count);
761+
762+
// Suggestion for improvement
763+
printf(FOSSIL_TEST_COLOR_CYAN "Suggestion: %s\n", success_suggestions[rand() % 5]);
715764
} else if (env->timeout_count > 0) {
716-
printf(FOSSIL_TEST_COLOR_ORANGE FOSSIL_TEST_ATTR_ITATIC "%s\n" FOSSIL_TEST_COLOR_RESET, timeout_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH]);
765+
// Timeout occurred: calm, motivating tone
766+
const char *message = timeout_messages[rand() % _FOSSIL_TEST_RESPONSE_LENGTH];
767+
printf(FOSSIL_TEST_COLOR_ORANGE FOSSIL_TEST_ATTR_ITALIC "Some tests timed out, but we’ll catch them next time: %s\n" FOSSIL_TEST_COLOR_RESET, message);
768+
769+
// Analysis of timeouts
770+
printf(FOSSIL_TEST_COLOR_CYAN "Analysis: %d tests timed out. This might be due to long execution times or heavy resource usage.\n" FOSSIL_TEST_COLOR_RESET, env->timeout_count);
771+
772+
// Suggestion for improvement
773+
printf(FOSSIL_TEST_COLOR_CYAN "Suggestion: %s\n" FOSSIL_TEST_COLOR_RESET, timeout_suggestions[rand() % 4]);
774+
} else {
775+
// Unexpected case: neutral tone
776+
printf(FOSSIL_TEST_COLOR_RESET "We’ve encountered an unexpected result state. Something's off—let’s look into it.\n");
717777
}
778+
779+
// Final remarks based on overall results
780+
printf(FOSSIL_TEST_COLOR_BLUE "\nFinal Analysis:\n" FOSSIL_TEST_COLOR_RESET);
781+
if (env->pass_count > 0) {
782+
printf("Success rate: %.2f%%\n", (double)env->pass_count / (env->pass_count + env->fail_count + env->skip_count + env->timeout_count) * 100);
783+
}
784+
if (env->fail_count > 0) {
785+
printf("Failure rate: %.2f%%\n", (double)env->fail_count / (env->pass_count + env->fail_count + env->skip_count + env->timeout_count) * 100);
786+
}
787+
if (env->skip_count > 0) {
788+
printf("Skipped tests: %d\n", env->skip_count);
789+
}
790+
if (env->timeout_count > 0) {
791+
printf("Timeout tests: %d\n", env->timeout_count);
792+
}
793+
794+
// Provide overall improvement suggestion
795+
printf(FOSSIL_TEST_COLOR_CYAN "Overall Suggestion: %s\n" FOSSIL_TEST_COLOR_RESET, success_suggestions[rand() % 5]);
796+
}
797+
798+
// Function to print a long horizontal top border with a corner
799+
void print_long_horizontal_top_border(int length) {
800+
// Print the top left corner, followed by the horizontal border, and then the top right corner
801+
printf(FOSSIL_TEST_COLOR_BLUE "%s", TOP_LEFT_CORNER);
802+
for (int i = 0; i < length; i++) {
803+
printf("%s", HORIZONTAL_BORDER); // Repeat the horizontal border character
804+
}
805+
printf("%s\n" FOSSIL_TEST_COLOR_RESET, TOP_RIGHT_CORNER); // End with the top right corner
806+
}
807+
808+
// Function to print a long horizontal bottom border with a corner
809+
void print_long_horizontal_bottom_border(int length) {
810+
// Print the bottom left corner, followed by the horizontal border, and then the bottom right corner
811+
printf(FOSSIL_TEST_COLOR_BLUE "%s", BOTTOM_LEFT_CORNER);
812+
for (int i = 0; i < length; i++) {
813+
printf("%s", HORIZONTAL_BORDER); // Repeat the horizontal border character
814+
}
815+
printf("%s\n" FOSSIL_TEST_COLOR_RESET, BOTTOM_RIGHT_CORNER); // End with the bottom right corner
718816
}
719817

720-
// Summary function for test results
818+
// Function to simulate pixel manipulation in the foreground for the test summary
721819
void fossil_test_summary(fossil_test_env_t *env) {
722820
if (!env) {
723821
return;
724822
}
725823

726824
if (env->options.dry_run) {
727-
puts(FOSSIL_TEST_COLOR_PURPLE "Dry run mode enabled. No tests were executed or evaluated." FOSSIL_TEST_COLOR_RESET);
825+
printf(FOSSIL_TEST_COLOR_PURPLE "Dry run mode enabled. No tests were executed or evaluated.\n" FOSSIL_TEST_COLOR_RESET);
728826
return;
729827
}
730828

@@ -737,7 +835,7 @@ void fossil_test_summary(fossil_test_env_t *env) {
737835
} else if (test->status == TEST_STATUS_FAIL) {
738836
env->fail_count++;
739837
if (test->failure_message) {
740-
printf("Test '%s' failed: %s\n", test->name, test->failure_message);
838+
printf(FOSSIL_TEST_COLOR_RED "Test '%s' failed: %s\n" FOSSIL_TEST_COLOR_RESET, test->name, test->failure_message);
741839
}
742840
} else if (test->status == TEST_STATUS_SKIP) {
743841
env->skip_count++;
@@ -753,25 +851,24 @@ void fossil_test_summary(fossil_test_env_t *env) {
753851
}
754852
env->end_execution_time = clock();
755853

756-
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================" FOSSIL_TEST_COLOR_RESET);
757-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_BOLD FOSSIL_TEST_ATTR_ITATIC "\nFossil Test Summary:\n" FOSSIL_TEST_COLOR_RESET);
758-
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================\n" FOSSIL_TEST_COLOR_RESET);
854+
// Manipulate the border pixels using box-drawing characters
855+
int border_length = 80; // Set the length of the horizontal border (adjust as necessary)
856+
print_long_horizontal_top_border(border_length); // Top border
857+
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "%s %s %s\n" FOSSIL_TEST_COLOR_RESET,
858+
VERTICAL_BORDER, "Fossil Test Summary:", VERTICAL_BORDER); // Title
859+
print_long_horizontal_bottom_border(border_length); // Bottom border
759860

760-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Passed: " FOSSIL_TEST_COLOR_ORANGE " %d\n" FOSSIL_TEST_COLOR_RESET, env->pass_count);
761-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Failed: " FOSSIL_TEST_COLOR_ORANGE " %d\n" FOSSIL_TEST_COLOR_RESET, env->fail_count);
762-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Skipped:" FOSSIL_TEST_COLOR_ORANGE " %d\n" FOSSIL_TEST_COLOR_RESET, env->skip_count);
763-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Timeout:" FOSSIL_TEST_COLOR_ORANGE " %d\n" FOSSIL_TEST_COLOR_RESET, env->timeout_count);
764-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Total: %d tests\n" FOSSIL_TEST_COLOR_RESET, env->pass_count + env->fail_count + env->skip_count);
861+
fossil_test_sanity(env); // Add any additional sanity checks or suggestions here
765862

766-
// Optionally, you could add the total execution time summary here
863+
// Total execution time with manipulated borders
767864
double total_execution_time = (double)(env->end_execution_time - env->start_execution_time) / CLOCKS_PER_SEC;
768865
int seconds = (int)total_execution_time;
769866
int milliseconds = (int)((total_execution_time - seconds) * 1000);
770867
int microseconds = (int)((total_execution_time - seconds - milliseconds / 1000.0) * 1000000);
771868

772-
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================\n" FOSSIL_TEST_COLOR_RESET);
773-
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITATIC "Execution time: (%.2d) seconds, (%.2d) milliseconds, (%.3d) microseconds\n" FOSSIL_TEST_COLOR_RESET, seconds, milliseconds, microseconds);
774-
printf(FOSSIL_TEST_COLOR_BLUE FOSSIL_TEST_ATTR_BOLD "===================================================================\n" FOSSIL_TEST_COLOR_RESET);
775-
776-
fossil_test_message(env);
869+
// Display time with additional border manipulation
870+
print_long_horizontal_top_border(border_length); // Custom long horizontal border (top)
871+
printf(FOSSIL_TEST_COLOR_CYAN FOSSIL_TEST_ATTR_ITALIC " Execution time: (%.2d) seconds, (%.2d) milliseconds, (%.3d) microseconds\n" FOSSIL_TEST_COLOR_RESET,
872+
seconds, milliseconds, microseconds); // Time info
873+
print_long_horizontal_bottom_border(border_length); // Custom long horizontal border (bottom)
777874
}

0 commit comments

Comments
 (0)