Skip to content

Commit b50620d

Browse files
Merge pull request #104 from dreamer-coding/add_skip_flags
Added skip flags
2 parents 44e8736 + b7d4a96 commit b50620d

File tree

4 files changed

+70
-62
lines changed

4 files changed

+70
-62
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ The Pizza Test CLI provides an efficient way to run and manage tests directly fr
8686
|----------------------|-----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
8787
| `--fail-fast` | Stop on the first failure. | Useful for quickly identifying and addressing critical issues. |
8888
| `--only <test>` | Run only the specified test. | Focuses execution on a single test for debugging or validation purposes. |
89+
| `--skip <test>` | Skip the specified test. | Allows excluding specific tests from execution. |
8990
| `--repeat <count>` | Repeat the test a specified number of times. | Useful for stress testing or verifying consistency across multiple runs. |
9091
| `--help` | Show help for the run command. | Provides detailed usage instructions for the `run` command. |
9192
### Filter Command Options

code/logic/common.c

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static void _show_subhelp_run(void) {
9191
pizza_io_printf("{blue}Run command options:{reset}\n");
9292
pizza_io_printf("{cyan} --fail-fast Stop on the first failure{reset}\n");
9393
pizza_io_printf("{cyan} --only <test> Run only the specified test{reset}\n");
94+
pizza_io_printf("{cyan} --skip <test> Skip the specified test{reset}\n");
9495
pizza_io_printf("{cyan} --repeat <count> Repeat the test a specified number of times{reset}\n");
9596
pizza_io_printf("{cyan} --help Show help for run command{reset}\n");
9697
exit(EXIT_SUCCESS);
@@ -201,6 +202,7 @@ static void _show_host(void) {
201202

202203
fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
203204
fossil_pizza_pallet_t pallet = {0};
205+
int is_command = 0; // Variable to track if a command is being processed
204206

205207
// Parse command-line arguments
206208
for (int i = 1; i < argc; i++) {
@@ -213,32 +215,41 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
213215
} else if (pizza_io_cstr_compare(argv[i], "--host") == 0) {
214216
_show_host();
215217
} else if (pizza_io_cstr_compare(argv[i], "run") == 0) {
218+
is_command = 1;
216219
pallet.run.fail_fast = 0;
217220
pallet.run.only = null;
221+
pallet.run.skip = null;
218222
pallet.run.repeat = 1;
219223

220224
for (int j = i + 1; j < argc; j++) {
225+
if (!is_command) break;
221226
if (pizza_io_cstr_compare(argv[j], "--fail-fast") == 0) {
222227
pallet.run.fail_fast = 1;
223228
G_PIZZA_FAIL_FAST = 1;
224229
} else if (pizza_io_cstr_compare(argv[j], "--only") == 0 && j + 1 < argc) {
225230
pallet.run.only = argv[++j];
226-
G_PIZZA_ONLY = pallet.run.only;
231+
} else if (pizza_io_cstr_compare(argv[j], "--skip") == 0 && j + 1 < argc) {
232+
pallet.run.skip = argv[++j];
233+
G_PIZZA_SKIP = 1;
227234
} else if (pizza_io_cstr_compare(argv[j], "--repeat") == 0 && j + 1 < argc) {
228235
pallet.run.repeat = atoi(argv[++j]);
229236
G_PIZZA_REPEAT = pallet.run.repeat;
237+
} else if (pizza_io_cstr_compare(argv[j], "--threads") == 0 && j + 1 < argc) {
238+
G_PIZZA_THREADS = atoi(argv[++j]);
230239
} else if (pizza_io_cstr_compare(argv[j], "--help") == 0) {
231240
_show_subhelp_run();
232241
} else {
233-
break;
242+
is_command = 0;
234243
}
235244
}
236245
} else if (pizza_io_cstr_compare(argv[i], "filter") == 0) {
246+
is_command = 1;
237247
pallet.filter.test_name = null;
238248
pallet.filter.suite_name = null;
239249
pallet.filter.tag = null;
240250

241251
for (int j = i + 1; j < argc; j++) {
252+
if (!is_command) break;
242253
if (pizza_io_cstr_compare(argv[j], "--test-name") == 0 && j + 1 < argc) {
243254
pallet.filter.test_name = argv[++j];
244255
} else if (pizza_io_cstr_compare(argv[j], "--suite-name") == 0 && j + 1 < argc) {
@@ -267,14 +278,16 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
267278
}
268279
exit(EXIT_SUCCESS);
269280
} else {
270-
break;
281+
is_command = 0;
271282
}
272283
}
273284
} else if (pizza_io_cstr_compare(argv[i], "sort") == 0) {
285+
is_command = 1;
274286
pallet.sort.by = null;
275287
pallet.sort.order = null;
276288

277289
for (int j = i + 1; j < argc; j++) {
290+
if (!is_command) break;
278291
if (pizza_io_cstr_compare(argv[j], "--by") == 0 && j + 1 < argc) {
279292
const char* criteria = argv[++j];
280293
int is_valid_criteria = 0;
@@ -301,32 +314,34 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
301314
}
302315
exit(EXIT_SUCCESS);
303316
} else {
304-
break;
317+
is_command = 0;
305318
}
306319
}
307320
} else if (pizza_io_cstr_compare(argv[i], "shuffle") == 0) {
321+
is_command = 1;
308322
pallet.shuffle.seed = null;
309323
pallet.shuffle.count = 0;
310324
pallet.shuffle.by = null;
311325

312326
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]);
327+
if (!is_command) break;
328+
if (pizza_io_cstr_compare(argv[j], "--seed") == 0 && j + 1 < argc) {
329+
pallet.shuffle.seed = argv[++j];
330+
} else if (pizza_io_cstr_compare(argv[j], "--count") == 0 && j + 1 < argc) {
331+
pallet.shuffle.count = atoi(argv[++j]);
332+
} else if (pizza_io_cstr_compare(argv[j], "--by") == 0 && j + 1 < argc) {
333+
pallet.shuffle.by = argv[++j];
334+
} else if (pizza_io_cstr_compare(argv[j], "--help") == 0) {
335+
_show_subhelp_shuffle();
336+
} else if (pizza_io_cstr_compare(argv[j], "--options") == 0) {
337+
pizza_io_printf("{blue}Valid criteria for shuffling:{reset}\n");
338+
for (int k = 0; VALID_CRITERIA[k] != null; k++) {
339+
pizza_io_printf("{cyan} %s{reset}\n", VALID_CRITERIA[k]);
340+
}
341+
exit(EXIT_SUCCESS);
342+
} else {
343+
is_command = 0;
325344
}
326-
exit(EXIT_SUCCESS);
327-
} else {
328-
break;
329-
}
330345
}
331346
} else if (strncmp(argv[i], "color=", 6) == 0) {
332347
if (pizza_io_cstr_compare(argv[i] + 6, "enable") == 0) {
@@ -363,7 +378,6 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
363378
if (i + 1 < argc && pizza_io_cstr_compare(argv[i + 1], "--help") == 0) {
364379
_show_help();
365380
}
366-
367381
} else if (strncmp(argv[i], "theme=", 6) == 0) {
368382
const char* theme_str = argv[i] + 6;
369383
if (pizza_io_cstr_compare(theme_str, "fossil") == 0) {
@@ -387,7 +401,6 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
387401
} else if (pizza_io_cstr_compare(theme_str, "unity") == 0) {
388402
pallet.theme = PIZZA_THEME_UNITY;
389403
G_PIZZA_THEME = PIZZA_THEME_UNITY;
390-
391404
}
392405
} else if (pizza_io_cstr_compare(argv[i], "theme") == 0) {
393406
if (i + 1 < argc && pizza_io_cstr_compare(argv[i + 1], "--help") == 0) {
@@ -401,7 +414,7 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
401414
} else if (pizza_io_cstr_compare(verbose_str, "ci") == 0) {
402415
pallet.verbose = PIZZA_VERBOSE_CI;
403416
G_PIZZA_VERBOSE = PIZZA_VERBOSE_CI;
404-
} else if (pizza_io_cstr_compare(verbose_str, "doge") == 0) { // means verbose for Pizza Test
417+
} else if (pizza_io_cstr_compare(verbose_str, "doge") == 0) {
405418
pallet.verbose = PIZZA_VERBOSE_DOGE;
406419
G_PIZZA_VERBOSE = PIZZA_VERBOSE_DOGE;
407420
}
@@ -416,9 +429,6 @@ fossil_pizza_pallet_t fossil_pizza_pallet_create(int argc, char** argv) {
416429
_show_help();
417430
exit(EXIT_SUCCESS);
418431
}
419-
} else {
420-
pizza_io_printf("{red}Error: Unknown command or option '%s'.{reset}\n", argv[i]);
421-
exit(EXIT_FAILURE);
422432
}
423433
}
424434

code/logic/fossil/pizza/common.h

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

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)