@@ -282,13 +282,14 @@ const char *timeout_messages[] = {
282282static const char * FOSSIL_TEST_OPTIONS [] = {
283283 "--version - Displays the current version of Fossil Test\n" ,
284284 "--help - Shows help message with usage\n" ,
285- "--info - Displays detailed information about the test run\n" ,
285+ "--info - Displays detailed information about the test run\n"
286286};
287287
288288static const char * FOSSIL_TEST_COMMANDS [] = {
289289 "reverse [enable|disable] - Enables or disables reverse order of test execution\n" ,
290290 "repeat [count] - Repeats the test suite a specified number of times\n" ,
291291 "shuffle [enable|disable] - Enables or disables shuffling of test execution order\n" ,
292+ "dry-run [enable|disable] - Enables or disables dry-run mode\n"
292293};
293294
294295static const char * FOSSIL_TEST_VERSION = "1.1.4" ; // Version of Fossil Test
@@ -320,6 +321,7 @@ fossil_options_t init_options(void) {
320321 options .repeat_enabled = false;
321322 options .repeat_count = 1 ;
322323 options .shuffle_enabled = false;
324+ options .dry_run = false;
323325 return options ;
324326}
325327
@@ -359,8 +361,10 @@ fossil_options_t fossil_options_parse(int argc, char **argv) {
359361 } else if (strcmp (argv [i ], "reverse" ) == 0 ) {
360362 if (i + 1 < argc && strcmp (argv [i + 1 ], "enable" ) == 0 ) {
361363 options .reverse = true;
364+ i ++ ;
362365 } else if (i + 1 < argc && strcmp (argv [i + 1 ], "disable" ) == 0 ) {
363366 options .reverse = false;
367+ i ++ ;
364368 }
365369 } else if (strcmp (argv [i ], "repeat" ) == 0 ) {
366370 options .repeat_enabled = true;
@@ -371,8 +375,18 @@ fossil_options_t fossil_options_parse(int argc, char **argv) {
371375 } else if (strcmp (argv [i ], "shuffle" ) == 0 ) {
372376 if (i + 1 < argc && strcmp (argv [i + 1 ], "enable" ) == 0 ) {
373377 options .shuffle_enabled = true;
378+ i ++ ;
374379 } else if (i + 1 < argc && strcmp (argv [i + 1 ], "disable" ) == 0 ) {
375380 options .shuffle_enabled = false;
381+ i ++ ;
382+ }
383+ } else if (strcmp (argv [i ], "dry-run" ) == 0 ) {
384+ if (i + 1 < argc && strcmp (argv [i + 1 ], "enable" ) == 0 ) {
385+ options .dry_run = true;
386+ i ++ ;
387+ } else if (i + 1 < argc && strcmp (argv [i + 1 ], "disable" ) == 0 ) {
388+ options .dry_run = false;
389+ i ++ ;
376390 }
377391 }
378392 }
@@ -462,6 +476,10 @@ void shuffle_test_cases(test_case_t **test_cases) {
462476
463477// Creates and returns a new test suite
464478test_suite_t * fossil_test_create_suite (const char * name ) {
479+ if (!name ) {
480+ return NULL ;
481+ }
482+
465483 test_suite_t * suite = (test_suite_t * )malloc (sizeof (test_suite_t ));
466484 if (!suite ) {
467485 return NULL ;
@@ -610,7 +628,12 @@ void fossil_test_assert_internal(bool condition, const char *message, const char
610628
611629// Run an individual test case
612630void fossil_test_run_case (test_case_t * test_case , fossil_test_env_t * env ) {
613- if (!test_case ) {
631+ if (!test_case || !env ) {
632+ return ;
633+ }
634+
635+ if (env -> options .dry_run ) {
636+ puts (FOSSIL_TEST_COLOR_PURPLE "Dry run mode enabled. No tests will be executed." FOSSIL_TEST_COLOR_RESET );
614637 return ;
615638 }
616639
@@ -624,23 +647,24 @@ void fossil_test_run_case(test_case_t *test_case, fossil_test_env_t *env) {
624647
625648 _ASSERT_COUNT = 0 ; // Reset assertion count before running the test
626649
627- if (setjmp (env -> env ) == 0 ) {
650+ if (setjmp (env -> env ) == 0 ) { // Attempt to run the test case
628651 for (int i = 0 ; i < env -> options .repeat_count ; i ++ ) {
629652 test_case -> test_func ();
630- if (clock () > timeout_limit ) {
653+ if (clock () > timeout_limit ) { // Timeout check
631654 test_case -> status = TEST_STATUS_TTIMEOUT ;
632655 printf (FOSSIL_TEST_COLOR_ORANGE "TIMEOUT: " FOSSIL_TEST_COLOR_BLUE " %s\n" FOSSIL_TEST_COLOR_RESET , test_case -> name );
633656 break ;
634657 }
635658 }
636- } else {
659+ } else { // Handle failure
637660 test_case -> status = TEST_STATUS_FAIL ;
638661 printf (FOSSIL_TEST_COLOR_RED "FAILED: " FOSSIL_TEST_COLOR_BLUE " %s\n" , test_case -> name );
639662 printf ("Failure Message: %s\n" FOSSIL_TEST_COLOR_RESET , test_case -> failure_message );
640663 }
664+
641665 test_case -> execution_time = (double )(clock () - test_start_time ) / CLOCKS_PER_SEC ;
642666
643- // Check if the test case is empty
667+ // Warn if the test case contains no assertions
644668 if (_ASSERT_COUNT == 0 ) {
645669 printf (FOSSIL_TEST_COLOR_YELLOW "WARNING: %s contains no assertions\n" FOSSIL_TEST_COLOR_RESET , test_case -> name );
646670 }
@@ -649,20 +673,24 @@ void fossil_test_run_case(test_case_t *test_case, fossil_test_env_t *env) {
649673 fossil_test_case_teardown (test_case );
650674
651675 // Log result
652- if (test_case -> status == TEST_STATUS_PASS ) {
653- if (env -> options .show_info ) {
654- printf (FOSSIL_TEST_COLOR_GREEN "PASSED: " FOSSIL_TEST_COLOR_BLUE " %s (%.3f seconds)\n" FOSSIL_TEST_COLOR_RESET , test_case -> name , test_case -> execution_time );
655- }
656- } else if (test_case -> status == TEST_STATUS_FAIL ) {
657- env -> fail_count ++ ;
658- } else if (test_case -> status == TEST_STATUS_SKIP ) {
659- env -> skip_count ++ ;
660- } else if (test_case -> status == TEST_STATUS_TTIMEOUT ) {
661- env -> timeout_count ++ ;
662- } else if (test_case -> status == TEST_STATUS_EMPTY ) {
663- env -> empty_count ++ ;
664- } else {
665- env -> unexpected_count ++ ;
676+ switch (test_case -> status ) {
677+ case TEST_STATUS_PASS :
678+ if (env -> options .show_info ) {
679+ printf (FOSSIL_TEST_COLOR_GREEN "PASSED: " FOSSIL_TEST_COLOR_BLUE " %s (%.3f seconds)\n" FOSSIL_TEST_COLOR_RESET , test_case -> name , test_case -> execution_time );
680+ }
681+ break ;
682+ case TEST_STATUS_FAIL :
683+ env -> fail_count ++ ;
684+ break ;
685+ case TEST_STATUS_SKIP :
686+ env -> skip_count ++ ;
687+ break ;
688+ case TEST_STATUS_TTIMEOUT :
689+ env -> timeout_count ++ ;
690+ break ;
691+ default :
692+ env -> unexpected_count ++ ;
693+ break ;
666694 }
667695}
668696
@@ -671,6 +699,11 @@ void fossil_test_run_all(fossil_test_env_t *env) {
671699 return ;
672700 }
673701
702+ if (env -> options .dry_run ) {
703+ puts (FOSSIL_TEST_COLOR_PURPLE "Dry run mode enabled. No tests will be executed." FOSSIL_TEST_COLOR_RESET );
704+ return ;
705+ }
706+
674707 test_suite_t * current_suite = env -> test_suites ;
675708
676709 while (current_suite ) {
@@ -680,6 +713,10 @@ void fossil_test_run_all(fossil_test_env_t *env) {
680713}
681714
682715void fossil_test_init (fossil_test_env_t * env , int argc , char * * argv ) {
716+ if (!env ) {
717+ return ;
718+ }
719+
683720 env -> options = fossil_options_parse (argc , argv );
684721 if (env -> options .show_version ) {
685722 version_info ();
@@ -701,6 +738,11 @@ void fossil_test_init(fossil_test_env_t *env, int argc, char **argv) {
701738 env -> end_execution_time = 0.0 ;
702739 env -> unexpected_count = 0 ;
703740 env -> test_suites = NULL ;
741+
742+ if (env -> options .dry_run ) {
743+ puts (FOSSIL_TEST_COLOR_PURPLE "Dry run mode enabled. No tests will be executed or evaluated." FOSSIL_TEST_COLOR_RESET );
744+ return ;
745+ }
704746}
705747
706748// Function to generate a dynamic message based on the test results
@@ -723,6 +765,15 @@ void fossil_test_message(fossil_test_env_t *env) {
723765
724766// Summary function for test results
725767void fossil_test_summary (fossil_test_env_t * env ) {
768+ if (!env ) {
769+ return ;
770+ }
771+
772+ if (env -> options .dry_run ) {
773+ puts (FOSSIL_TEST_COLOR_PURPLE "Dry run mode enabled. No tests were executed or evaluated." FOSSIL_TEST_COLOR_RESET );
774+ return ;
775+ }
776+
726777 test_suite_t * suite = env -> test_suites ;
727778 while (suite != NULL ) {
728779 test_case_t * test = suite -> tests ;
0 commit comments