Skip to content

Commit f5353ea

Browse files
Merge pull request #46 from dreamer-coding/pr_new_commands
Pull Request for Dry Run
2 parents 3df1cc0 + 2259a3c commit f5353ea

File tree

4 files changed

+174
-66
lines changed

4 files changed

+174
-66
lines changed

README.md

Lines changed: 80 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ To integrate Fossil Test into your project, follow these steps:
5252
# ======================
5353
[wrap-git]
5454
url = https://github.com/fossillogic/fossil-test.git
55-
revision = v1.1.4
55+
revision = v1.1.5
5656

5757
[provide]
5858
fossil-test = fossil_test_dep
@@ -74,31 +74,85 @@ The Fossil Test CLI provides an efficient way to run and manage tests directly f
7474

7575
### Commands and Options
7676

77-
| Command | Description |
78-
|----------------------------------|-----------------------------------------------------------------------------------------------|
79-
| `--version` | Displays the current version of Fossil Test. |
80-
| `--help` | Shows help message with usage instructions. |
81-
| `--info` | Displays detailed information about the test run. |
82-
| `reverse [enable/disable]` | Enables or disables reverse order of test execution. |
83-
| `repeat=<number>` | Repeats the test suite a specified number of times. |
84-
| `shuffle [enable/disable]` | Enables or disables shuffling of test execution order. |
85-
86-
### Example Usage
87-
88-
- Display the version:
89-
```sh
90-
fossil_cli --version
91-
```
92-
93-
- Enable reverse order of test execution:
94-
```sh
95-
fossil_cli reverse enable
96-
```
97-
98-
- Repeat the test suite 5 times:
99-
```sh
100-
fossil_cli repeat=5
101-
```
77+
| Command | Description | Notes |
78+
|----------------------------------|-----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
79+
| `--version` | Displays the current version of Fossil Test. | Useful for verifying the version of the tool in use. |
80+
| `--help` | Shows help message with usage instructions. | Provides a quick reference for all available commands. |
81+
| `--info` | Displays detailed information about the test run. | Includes information such as test count, duration, and configuration. |
82+
| `reverse [enable/disable]` | Enables or disables reverse order of test execution. | Useful for debugging or ensuring the tests don't depend on execution order. |
83+
| `shuffle [enable/disable]` | Enables or disables shuffling of test execution order. | Helps identify order-dependent issues in the test suite. |
84+
| `dry-run [enable/disable]` | Enables or disables dry run mode, showing which tests will execute without running them. | Ideal for verifying test selection criteria before actual execution. |
85+
| `repeat=<number>` | Repeats the test suite a specified number of times. | Handy for stress-testing or reproducing intermittent failures. |
86+
87+
### Key Notes Summary:
88+
- **Version**: Quickly check the installed version of Fossil Test.
89+
- **Help**: Access usage instructions and command references.
90+
- **Info**: Get detailed insights about the test run, including test count and duration.
91+
- **Reverse and Shuffle**: Help debug issues by manipulating test execution order.
92+
- **Repeat**: Ideal for reliability testing by repeatedly executing tests.
93+
- **Dry Run**: Provides a preview of the test plan without running the tests, useful for preparation and validation.
94+
95+
### Usage
96+
97+
To use the Fossil Test CLI, navigate to your project directory and run the desired command. For example, to check the version of Fossil Test, use:
98+
99+
```sh
100+
fossil-test --version
101+
```
102+
103+
To display help information, use:
104+
105+
```sh
106+
fossil-test --help
107+
```
108+
109+
For detailed information about the test run, use:
110+
111+
```sh
112+
fossil-test --info
113+
```
114+
115+
To enable reverse order of test execution, use:
116+
117+
```sh
118+
fossil-test reverse enable
119+
```
120+
121+
To disable reverse order of test execution, use:
122+
123+
```sh
124+
fossil-test reverse disable
125+
```
126+
127+
To enable shuffling of test execution order, use:
128+
129+
```sh
130+
fossil-test shuffle enable
131+
```
132+
133+
To disable shuffling of test execution order, use:
134+
135+
```sh
136+
fossil-test shuffle disable
137+
```
138+
139+
To perform a dry run, use:
140+
141+
```sh
142+
fossil-test dry-run enable
143+
```
144+
145+
To disable dry run mode, use:
146+
147+
```sh
148+
fossil-test dry-run disable
149+
```
150+
151+
To repeat the test suite a specified number of times, use:
152+
153+
```sh
154+
fossil-test repeat=<number>
155+
```
102156

103157
---
104158

code/logic/fossil/test/testing.h

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,35 @@ extern "C" {
4949
#endif
5050

5151
/**
52-
* @struct fossil_options
53-
* @brief Structure to hold the configuration options for the test environment.
52+
* @struct fossil_options_t
53+
* @brief Structure to hold various options for fossil testing.
5454
*
55-
* This structure contains various fields to manage the configuration options for
56-
* the test environment, including flags to show version and help information, as
57-
* well as options to reverse the order of tests, repeat tests, and shuffle tests.
55+
* This structure contains various flags and parameters that control the behavior of the fossil testing framework.
5856
*
59-
* @var fossil_options::show_version
60-
* Flag to show version information.
57+
* @var fossil_options_t::show_version
58+
* Flag to indicate if the version information should be displayed.
6159
*
62-
* @var fossil_options::show_help
63-
* Flag to show help information.
60+
* @var fossil_options_t::show_help
61+
* Flag to indicate if the help information should be displayed.
6462
*
65-
* @var fossil_options::show_info
66-
* Flag to show additional information.
63+
* @var fossil_options_t::show_info
64+
* Flag to indicate if additional information should be displayed.
6765
*
68-
* @var fossil_options::reverse
69-
* Flag to reverse the order of tests.
66+
* @var fossil_options_t::reverse
67+
* Flag to indicate if the order of tests should be reversed.
7068
*
71-
* @var fossil_options::repeat_enabled
72-
* Flag to enable repeating tests.
69+
* @var fossil_options_t::repeat_enabled
70+
* Flag to indicate if test repetition is enabled.
7371
*
74-
* @var fossil_options::repeat_count
75-
* Number of times to repeat tests.
72+
* @var fossil_options_t::repeat_count
73+
* Number of times to repeat the tests if repetition is enabled.
74+
*
75+
* @var fossil_options_t::shuffle_enabled
76+
* Flag to indicate if the tests should be shuffled.
77+
*
78+
* @var fossil_options_t::dry_run
79+
* Flag to indicate if the tests should be run in dry-run mode (no actual execution).
7680
*
77-
* @var fossil_options::shuffle_enabled
78-
* Flag to enable shuffling of tests.
7981
*/
8082
typedef struct {
8183
bool show_version;
@@ -85,6 +87,7 @@ typedef struct {
8587
bool repeat_enabled;
8688
int repeat_count;
8789
bool shuffle_enabled;
90+
bool dry_run;
8891
} fossil_options_t;
8992

9093
/**

code/logic/testing.c

Lines changed: 71 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,14 @@ const char *timeout_messages[] = {
282282
static 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

288288
static 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

294295
static 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
464478
test_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
612630
void 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

682715
void 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
725767
void 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;

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project('Fossil Test', 'c', 'cpp',
22
meson_version: '>=1.3.0',
33
license: 'MPL-2.0',
4-
version: '1.1.4',
4+
version: '1.1.5',
55
default_options: ['c_std=c11,c18', 'cpp_std=c++20'])
66

77
subdir('code')

0 commit comments

Comments
 (0)