Skip to content

Commit f49e570

Browse files
committed
test: Add option to display all available tests
Useful option to avoid opening the large tests.c file just to find the test case you want to run.
1 parent a8382f2 commit f49e570

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/unit_test.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ static void help(void) {
9292
printf("Run the test suite for the project with optional configuration.\n\n");
9393
printf("Options:\n");
9494
printf(" -help Show this help message\n");
95+
printf(" -print_tests Display list of available tests\n");
9596
printf(" -j=<num>, -jobs=<num> Number of parallel worker processes (default: 0 = sequential)\n");
9697
printf(" -iter=<num>, -iterations=<num> Number of iterations for each test (default: 64)\n");
9798
printf(" -seed=<hex> Set a specific RNG seed (default: random)\n");
@@ -104,6 +105,17 @@ static void help(void) {
104105
printf(" - The first two positional arguments (iterations and seed) are also supported for backward compatibility.\n");
105106
}
106107

108+
static void print_test_list(void) {
109+
int i;
110+
printf("Available tests (%d):\n", (int) NUM_TESTS);
111+
printf("--------------------------------------------------\n");
112+
for (i = 0; i < (int) NUM_TESTS; i++) {
113+
printf(" [%3d] %s\n", i + 1, tests[i].name);
114+
}
115+
printf("--------------------------------------------------\n");
116+
printf("Run with: ./tests <test_name>\n");
117+
}
118+
107119
static int parse_jobs_count(const char* key, const char* value, struct Args* out) {
108120
char* ptr_val;
109121
long val = strtol(value, &ptr_val, 10); /* base 10 */
@@ -327,6 +339,12 @@ int main(int argc, char** argv) {
327339
_exit(EXIT_SUCCESS);
328340
}
329341

342+
/* Check if we need to print the available tests */
343+
if (argv[1] && strcmp(argv[1], "-print_tests") == 0) {
344+
print_test_list();
345+
_exit(EXIT_SUCCESS);
346+
}
347+
330348
/* Compatibility Note: The first two args were the number of iterations and the seed. */
331349
/* If provided, parse them and adjust the starting index for named arguments accordingly. */
332350
if (argv[1] && argv[1][0] != '-') {

0 commit comments

Comments
 (0)