Skip to content

Commit 8e8ef9d

Browse files
add cli pasta
1 parent 0e8cbce commit 8e8ef9d

File tree

3 files changed

+57
-60
lines changed

3 files changed

+57
-60
lines changed

code/logic/common.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static void _show_host(void) {
201201

202202
fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
203203
fossil_pizza_pallet_t pallet = {0};
204-
204+
205205
// Parse command-line arguments
206206
for (int i = 1; i < argc; i++) {
207207
if (pizza_io_cstr_compare(argv[i], "--dry-run") == 0) {
@@ -215,6 +215,7 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
215215
} else if (pizza_io_cstr_compare(argv[i], "run") == 0) {
216216
pallet.run.fail_fast = 0;
217217
pallet.run.only = null;
218+
pallet.run.skip = null;
218219
pallet.run.repeat = 1;
219220

220221
for (int j = i + 1; j < argc; j++) {
@@ -223,10 +224,14 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
223224
G_PIZZA_FAIL_FAST = 1;
224225
} else if (pizza_io_cstr_compare(argv[j], "--only") == 0 && j + 1 < argc) {
225226
pallet.run.only = argv[++j];
226-
G_PIZZA_ONLY = pallet.run.only;
227+
} else if (pizza_io_cstr_compare(argv[j], "--skip") == 0 && j + 1 < argc) {
228+
pallet.run.skip = argv[++j];
229+
G_PIZZA_SKIP = 1;
227230
} else if (pizza_io_cstr_compare(argv[j], "--repeat") == 0 && j + 1 < argc) {
228231
pallet.run.repeat = atoi(argv[++j]);
229232
G_PIZZA_REPEAT = pallet.run.repeat;
233+
} else if (pizza_io_cstr_compare(argv[j], "--threads") == 0 && j + 1 < argc) {
234+
G_PIZZA_THREADS = atoi(argv[++j]);
230235
} else if (pizza_io_cstr_compare(argv[j], "--help") == 0) {
231236
_show_subhelp_run();
232237
} else {
@@ -310,23 +315,23 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
310315
pallet.shuffle.by = null;
311316

312317
for (int j = i + 1; j < argc; j++) {
313-
if (pizza_io_cstr_compare(argv[j], "--seed") == 0 && j + 1 < argc) {
314-
pallet.shuffle.seed = argv[++j];
315-
} else if (pizza_io_cstr_compare(argv[j], "--count") == 0 && j + 1 < argc) {
316-
pallet.shuffle.count = atoi(argv[++j]);
317-
} else if (pizza_io_cstr_compare(argv[j], "--by") == 0 && j + 1 < argc) {
318-
pallet.shuffle.by = argv[++j];
319-
} else if (pizza_io_cstr_compare(argv[j], "--help") == 0) {
320-
_show_subhelp_shuffle();
321-
} else if (pizza_io_cstr_compare(argv[j], "--options") == 0) {
322-
pizza_io_printf("{blue}Valid criteria for shuffling:{reset}\n");
323-
for (int k = 0; VALID_CRITERIA[k] != null; k++) {
324-
pizza_io_printf("{cyan} %s{reset}\n", VALID_CRITERIA[k]);
318+
if (pizza_io_cstr_compare(argv[j], "--seed") == 0 && j + 1 < argc) {
319+
pallet.shuffle.seed = argv[++j];
320+
} else if (pizza_io_cstr_compare(argv[j], "--count") == 0 && j + 1 < argc) {
321+
pallet.shuffle.count = atoi(argv[++j]);
322+
} else if (pizza_io_cstr_compare(argv[j], "--by") == 0 && j + 1 < argc) {
323+
pallet.shuffle.by = argv[++j];
324+
} else if (pizza_io_cstr_compare(argv[j], "--help") == 0) {
325+
_show_subhelp_shuffle();
326+
} else if (pizza_io_cstr_compare(argv[j], "--options") == 0) {
327+
pizza_io_printf("{blue}Valid criteria for shuffling:{reset}\n");
328+
for (int k = 0; VALID_CRITERIA[k] != null; k++) {
329+
pizza_io_printf("{cyan} %s{reset}\n", VALID_CRITERIA[k]);
330+
}
331+
exit(EXIT_SUCCESS);
332+
} else {
333+
break;
325334
}
326-
exit(EXIT_SUCCESS);
327-
} else {
328-
break;
329-
}
330335
}
331336
} else if (strncmp(argv[i], "color=", 6) == 0) {
332337
if (pizza_io_cstr_compare(argv[i] + 6, "enable") == 0) {
@@ -363,7 +368,6 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
363368
if (i + 1 < argc && pizza_io_cstr_compare(argv[i + 1], "--help") == 0) {
364369
_show_help();
365370
}
366-
367371
} else if (strncmp(argv[i], "theme=", 6) == 0) {
368372
const char* theme_str = argv[i] + 6;
369373
if (pizza_io_cstr_compare(theme_str, "fossil") == 0) {
@@ -387,7 +391,6 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
387391
} else if (pizza_io_cstr_compare(theme_str, "unity") == 0) {
388392
pallet.theme = PIZZA_THEME_UNITY;
389393
G_PIZZA_THEME = PIZZA_THEME_UNITY;
390-
391394
}
392395
} else if (pizza_io_cstr_compare(argv[i], "theme") == 0) {
393396
if (i + 1 < argc && pizza_io_cstr_compare(argv[i + 1], "--help") == 0) {
@@ -401,7 +404,7 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
401404
} else if (pizza_io_cstr_compare(verbose_str, "ci") == 0) {
402405
pallet.verbose = PIZZA_VERBOSE_CI;
403406
G_PIZZA_VERBOSE = PIZZA_VERBOSE_CI;
404-
} else if (pizza_io_cstr_compare(verbose_str, "doge") == 0) { // means verbose for Pizza Test
407+
} else if (pizza_io_cstr_compare(verbose_str, "doge") == 0) {
405408
pallet.verbose = PIZZA_VERBOSE_DOGE;
406409
G_PIZZA_VERBOSE = PIZZA_VERBOSE_DOGE;
407410
}
@@ -416,9 +419,6 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
416419
_show_help();
417420
exit(EXIT_SUCCESS);
418421
}
419-
} else {
420-
pizza_io_printf("{red}Error: Unknown command or option '%s'.{reset}\n", argv[i]);
421-
exit(EXIT_FAILURE);
422422
}
423423
}
424424

code/logic/fossil/pizza/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ typedef struct {
299299
struct {
300300
int fail_fast; // Flag for --fail-fast
301301
const char* only; // Value for --only
302+
const char* skip; // Value for --skip
302303
int repeat; // Value for --repeat
303304
} run; // Run command flags
304305

code/logic/test.c

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -237,54 +237,50 @@ static uint64_t seconds_to_nanoseconds(uint64_t seconds) {
237237
void fossil_pizza_run_test(const fossil_pizza_engine_t* engine, fossil_pizza_case_t* test_case, fossil_pizza_suite_t* suite) {
238238
if (!test_case || !suite) return;
239239

240-
if (test_case->result != FOSSIL_PIZZA_CASE_SKIPPED) {
241-
// Check if the test case name matches the --only filter
242-
if (engine->pallet.run.only && pizza_io_cstr_compare(engine->pallet.run.only, test_case->name) != 0) {
243-
return;
244-
}
240+
// Check if the test case name matches the --only filter
241+
if (engine->pallet.run.only && pizza_io_cstr_compare(engine->pallet.run.only, test_case->name) != 0) {
242+
return; // Skip this test case if it doesn't match the --only filter
243+
}
244+
245+
// Check if the test case name matches the --skip filter
246+
if (engine->pallet.run.skip && pizza_io_cstr_compare(engine->pallet.run.skip, test_case->name) == 0) {
247+
test_case->result = FOSSIL_PIZZA_CASE_SKIPPED;
248+
return; // Skip this test case if it matches the --skip filter
249+
}
245250

246-
for (int i = 0; i < (engine->pallet.run.repeat ? engine->pallet.run.repeat : 1); ++i) {
247-
if (test_case->setup) test_case->setup();
251+
for (int i = 0; i < (engine->pallet.run.repeat ? engine->pallet.run.repeat : 1); ++i) {
252+
if (test_case->setup) test_case->setup();
248253

249-
uint64_t start_time = fossil_pizza_now_ns();
254+
uint64_t start_time = fossil_pizza_now_ns();
250255

251-
if (test_case->run) {
252-
if (setjmp(test_jump_buffer) == 0) {
253-
test_case->run();
254-
uint64_t elapsed_time = fossil_pizza_now_ns() - start_time;
256+
if (test_case->run) {
257+
if (setjmp(test_jump_buffer) == 0) {
258+
test_case->run();
259+
uint64_t elapsed_time = fossil_pizza_now_ns() - start_time;
255260

256-
if (elapsed_time > seconds_to_nanoseconds(G_PIZZA_TIMEOUT)) { // 1 minute in nanoseconds
257-
test_case->result = FOSSIL_PIZZA_CASE_TIMEOUT;
258-
} else {
259-
test_case->result = FOSSIL_PIZZA_CASE_PASS;
260-
}
261+
if (elapsed_time > seconds_to_nanoseconds(G_PIZZA_TIMEOUT)) { // 1 minute in nanoseconds
262+
test_case->result = FOSSIL_PIZZA_CASE_TIMEOUT;
261263
} else {
262-
test_case->result = FOSSIL_PIZZA_CASE_FAIL;
263-
if (engine->pallet.run.fail_fast) {
264-
fossil_pizza_test_output(test_case);
265-
return; // Exit immediately if --fail-fast is enabled
266-
}
264+
test_case->result = FOSSIL_PIZZA_CASE_PASS;
267265
}
268266
} else {
269-
test_case->result = FOSSIL_PIZZA_CASE_EMPTY;
267+
test_case->result = FOSSIL_PIZZA_CASE_FAIL;
268+
if (engine->pallet.run.fail_fast) {
269+
fossil_pizza_test_output(test_case);
270+
return; // Exit immediately if --fail-fast is enabled
271+
}
270272
}
271-
test_case->elapsed_ns = fossil_pizza_now_ns() - start_time;
272-
273-
if (test_case->teardown) test_case->teardown();
273+
} else {
274+
test_case->result = FOSSIL_PIZZA_CASE_EMPTY;
274275
}
276+
test_case->elapsed_ns = fossil_pizza_now_ns() - start_time;
275277

276-
// Output test case result
277-
fossil_pizza_test_output(test_case);
278-
} else if (test_case->result == FOSSIL_PIZZA_CASE_SKIPPED) {
279-
// Output skipped test case result
280-
test_case->elapsed_ns = 0; // No time elapsed for skipped tests
281-
fossil_pizza_test_output(test_case);
282-
} else {
283-
// Handle unexpected cases
284-
test_case->result = FOSSIL_PIZZA_CASE_UNEXPECTED;
285-
fossil_pizza_test_output(test_case);
278+
if (test_case->teardown) test_case->teardown();
286279
}
287280

281+
// Output test case result
282+
fossil_pizza_test_output(test_case);
283+
288284
// Update scores based on result
289285
fossil_pizza_update_score(test_case, suite);
290286
_ASSERT_COUNT = 0; // Reset the assertion count for the next test case

0 commit comments

Comments
 (0)