Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ The Pizza Test CLI provides an efficient way to run and manage tests directly fr
| `color=<mode>` | Set color mode (enable, disable, auto). | Enhances readability in supported terminals. |
| `theme=<name>` | Set the theme (pizza, catch, doctest, etc.). | Customizes the appearance of test output. |
| `verbose=<level>` | Set verbosity level (plain, ci, doge). | Adjusts the level of detail in test output. |
| `timeout=<seconds>` | Set a timeout for test execution. | Ensures tests do not exceed the specified duration, helping to identify long-running tests. |

### Run Command Options
| Option | Description | Notes |
Expand Down
12 changes: 12 additions & 0 deletions code/logic/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
// exported flags
// *****************************************************************************

uint64_t G_PIZZA_TIMEOUT = 60; // Default timeout in seconds
int G_PIZZA_DRY_RUN = 0;
int G_PIZZA_FAIL_FAST = 0;
int G_PIZZA_SKIP = 0;
Expand Down Expand Up @@ -77,6 +78,7 @@ static void _show_help(void) {
pizza_io_printf("{cyan} color=<mode> Set color mode (enable, disable, auto){reset}\n");
pizza_io_printf("{cyan} theme=<name> Set the theme (fossil, catch, doctest, etc.){reset}\n");
pizza_io_printf("{cyan} verbose=<level> Set verbosity level (plain, ci, doge){reset}\n");
pizza_io_printf("{cyan} timeout=<seconds> Set the timeout for commands (default: 60 seconds){reset}\n");
exit(EXIT_SUCCESS);
}

Expand Down Expand Up @@ -365,6 +367,16 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
if (i + 1 < argc && pizza_io_cstr_compare(argv[i + 1], "--help") == 0) {
_show_subhelp_verbose();
}
} else if (strncmp(argv[i], "timeout=", 8) == 0) {
G_PIZZA_TIMEOUT = atoi(argv[i] + 8);
} else if (pizza_io_cstr_compare(argv[i], "timeout") == 0) {
if (i + 1 < argc && pizza_io_cstr_compare(argv[i + 1], "--help") == 0) {
_show_help();
exit(EXIT_SUCCESS);
}
} else {
pizza_io_printf("{red}Error: Unknown command or option '%s'.{reset}\n", argv[i]);
exit(EXIT_FAILURE);
}
}

Expand Down
1 change: 1 addition & 0 deletions code/logic/fossil/pizza/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ typedef struct {
// exported flags
// *****************************************************************************

extern uint64_t G_PIZZA_TIMEOUT;
extern int G_PIZZA_DRY_RUN;
extern int G_PIZZA_FAIL_FAST;
extern int G_PIZZA_SKIP;
Expand Down
33 changes: 29 additions & 4 deletions code/logic/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ void fossil_pizza_test_output(const fossil_pizza_case_t* test_case) {
if (!test_case) return;

const char* result_str =
(test_case->result == FOSSIL_PIZZA_CASE_EMPTY) ? "EMPTY" :
(test_case->result == FOSSIL_PIZZA_CASE_PASS) ? "PASS" :
(test_case->result == FOSSIL_PIZZA_CASE_FAIL) ? "FAIL" :
(test_case->result == FOSSIL_PIZZA_CASE_EMPTY) ? "EMPTY" : "UNKNOWN";
(test_case->result == FOSSIL_PIZZA_CASE_TIMEOUT) ? "TIMEOUT" :
(test_case->result == FOSSIL_PIZZA_CASE_SKIPPED) ? "SKIPPED" :
(test_case->result == FOSSIL_PIZZA_CASE_UNEXPECTED) ? "UNEXPECTED" : "UNKNOWN";

switch (G_PIZZA_THEME) {
case PIZZA_THEME_FOSSIL:
Expand All @@ -118,8 +121,10 @@ void fossil_pizza_test_output(const fossil_pizza_case_t* test_case) {
test_case->name, result_str, test_case->elapsed_ns);
} else if (G_PIZZA_VERBOSE == PIZZA_VERBOSE_DOGE) {
pizza_io_printf("{blue}========================================{reset}\n");
pizza_io_printf("{cyan}Test Case:{reset} %s\n", test_case->name);
pizza_io_printf("{cyan}Given Result:{reset} %s\n", result_str);
pizza_io_printf("{cyan}Test Case :{reset} %s\n", test_case->name);
pizza_io_printf("{cyan}Given Tags :{reset} %s\n", test_case->tags);
pizza_io_printf("{cyan}Given Criteria:{reset} %s\n", test_case->criteria);
pizza_io_printf("{cyan}Given Result :{reset} %s\n", result_str);
pizza_io_printf("{cyan}With Timestamp:{reset} %llu ns\n", test_case->elapsed_ns);
pizza_io_printf("{blue}========================================{reset}\n");
}
Expand All @@ -133,6 +138,8 @@ void fossil_pizza_test_output(const fossil_pizza_case_t* test_case) {
} else if (G_PIZZA_VERBOSE == PIZZA_VERBOSE_DOGE) {
pizza_io_printf("{cyan}========================================{reset}\n");
pizza_io_printf("{cyan}Test Case:{reset} %s\n", test_case->name);
pizza_io_printf("{cyan}Given Tags:{reset} %s\n", test_case->tags);
pizza_io_printf("{cyan}Given Criteria:{reset} %s\n", test_case->criteria);
pizza_io_printf("{cyan}Given Result:{reset} %s\n", result_str);
pizza_io_printf("{cyan}With Timestamp:{reset} %llu ns\n", test_case->elapsed_ns);
pizza_io_printf("{cyan}========================================{reset}\n");
Expand All @@ -146,6 +153,8 @@ void fossil_pizza_test_output(const fossil_pizza_case_t* test_case) {
} else if (G_PIZZA_VERBOSE == PIZZA_VERBOSE_DOGE) {
pizza_io_printf("{blue}[========================================]{reset}\n");
pizza_io_printf("{blue}[Test Case]:{reset} %s\n", test_case->name);
pizza_io_printf("{blue}[Given Tags]:{reset} %s\n", test_case->tags);
pizza_io_printf("{blue}[Given Criteria]:{reset} %s\n", test_case->criteria);
pizza_io_printf("{blue}[Given Result]:{reset} %s\n", result_str);
pizza_io_printf("{blue}[With Timestamp]:{reset} %llu ns\n", test_case->elapsed_ns);
pizza_io_printf("{blue}[========================================]{reset}\n");
Expand All @@ -159,6 +168,8 @@ void fossil_pizza_test_output(const fossil_pizza_case_t* test_case) {
} else if (G_PIZZA_VERBOSE == PIZZA_VERBOSE_DOGE) {
pizza_io_printf("{green}# ========================================{reset}\n");
pizza_io_printf("{green}# Test Case:{reset} %s\n", test_case->name);
pizza_io_printf("{green}# Given Tags:{reset} %s\n", test_case->tags);
pizza_io_printf("{green}# Given Criteria:{reset} %s\n", test_case->criteria);
pizza_io_printf("{green}# Given Result:{reset} %s\n", result_str);
pizza_io_printf("{green}# With Timestamp:{reset} %llu ns\n", test_case->elapsed_ns);
pizza_io_printf("{green}# ========================================{reset}\n");
Expand All @@ -172,6 +183,8 @@ void fossil_pizza_test_output(const fossil_pizza_case_t* test_case) {
} else if (G_PIZZA_VERBOSE == PIZZA_VERBOSE_DOGE) {
pizza_io_printf("{blue}[========================================]{reset}\n");
pizza_io_printf("{blue}[Test Case]:{reset} %s\n", test_case->name);
pizza_io_printf("{blue}[Given Tags]:{reset} %s\n", test_case->tags);
pizza_io_printf("{blue}[Given Criteria]:{reset} %s\n", test_case->criteria);
pizza_io_printf("{blue}[Given Result]:{reset} %s\n", result_str);
pizza_io_printf("{blue}[With Timestamp]:{reset} %llu ns\n", test_case->elapsed_ns);
pizza_io_printf("{blue}[========================================]{reset}\n");
Expand All @@ -185,6 +198,8 @@ void fossil_pizza_test_output(const fossil_pizza_case_t* test_case) {
} else if (G_PIZZA_VERBOSE == PIZZA_VERBOSE_DOGE) {
pizza_io_printf("{magenta}========================================{reset}\n");
pizza_io_printf("{magenta}Test Case:{reset} %s\n", test_case->name);
pizza_io_printf("{magenta}Given Tags:{reset} %s\n", test_case->tags);
pizza_io_printf("{magenta}Given Criteria:{reset} %s\n", test_case->criteria);
pizza_io_printf("{magenta}Given Result:{reset} %s\n", result_str);
pizza_io_printf("{magenta}With Timestamp:{reset} %llu ns\n", test_case->elapsed_ns);
pizza_io_printf("{magenta}========================================{reset}\n");
Expand All @@ -198,13 +213,19 @@ void fossil_pizza_test_output(const fossil_pizza_case_t* test_case) {
} else if (G_PIZZA_VERBOSE == PIZZA_VERBOSE_DOGE) {
pizza_io_printf("{cyan}========================================{reset}\n");
pizza_io_printf("{cyan}Test Case:{reset} %s\n", test_case->name);
pizza_io_printf("{cyan}Given Tags:{reset} %s\n", test_case->tags);
pizza_io_printf("{cyan}Given Criteria:{reset} %s\n", test_case->criteria);
pizza_io_printf("{cyan}Given Result:{reset} %s\n", result_str);
pizza_io_printf("{cyan}With Timestamp:{reset} %llu ns\n", test_case->elapsed_ns);
pizza_io_printf("{cyan}========================================{reset}\n");
}
break;
}
}
// Utility function to convert seconds to nanoseconds
static uint64_t seconds_to_nanoseconds(uint64_t seconds) {
return seconds * 1000000000ULL;
}

void fossil_pizza_run_test(const fossil_pizza_engine_t* engine, fossil_pizza_case_t* test_case, fossil_pizza_suite_t* suite) {
if (!test_case || !suite) return;
Expand All @@ -225,7 +246,7 @@ void fossil_pizza_run_test(const fossil_pizza_engine_t* engine, fossil_pizza_cas
test_case->run();
uint64_t elapsed_time = fossil_pizza_now_ns() - start_time;

if (1000000ULL > 0 && elapsed_time > 1000000ULL) {
if (elapsed_time > seconds_to_nanoseconds(G_PIZZA_TIMEOUT)) { // 1 minute in nanoseconds
test_case->result = FOSSIL_PIZZA_CASE_TIMEOUT;
} else {
test_case->result = FOSSIL_PIZZA_CASE_PASS;
Expand All @@ -247,6 +268,10 @@ void fossil_pizza_run_test(const fossil_pizza_engine_t* engine, fossil_pizza_cas

// Output test case result
fossil_pizza_test_output(test_case);
} else if (test_case->result == FOSSIL_PIZZA_CASE_SKIPPED) {
// Output skipped test case result
test_case->elapsed_ns = 0; // No time elapsed for skipped tests
fossil_pizza_test_output(test_case);
} else {
// Handle unexpected cases
test_case->result = FOSSIL_PIZZA_CASE_UNEXPECTED;
Expand Down