test: rename some stuff; separate cron part tests
							parent
							
								
									adfdca18da
								
							
						
					
					
						commit
						3bf3150b4a
					
				
							
								
								
									
										11
									
								
								README.md
								
								
								
								
							
							
						
						
									
										11
									
								
								README.md
								
								
								
								
							|  | @ -53,6 +53,17 @@ files defined in its respective module. This allows testing internal functions. | |||
| To run the tests, simply run `make test`. If you wish to only run a specific | ||||
| test binary, you can find them in `build/test`. | ||||
| 
 | ||||
| The name of tests in the `TEST_LIST` variable should be prefixed with the | ||||
| module they're testing. This makes it much easier to distinguish the output of | ||||
| tests in the CLI. For example: | ||||
| 
 | ||||
| ```c | ||||
| TEST_LIST = { | ||||
|     {"cron illegal parts", test_illegal_parts}, | ||||
|     {NULL, NULL} | ||||
| }; | ||||
| ``` | ||||
| 
 | ||||
| ### `compile_commands.json` | ||||
| 
 | ||||
| Clangd requires a `compile_commands.json` to function properly. You can | ||||
|  |  | |||
|  | @ -1,4 +1,4 @@ | |||
| #include "vieter_cron.h" | ||||
| #include "vieter_cron_parse.h" | ||||
| #include <stdbool.h> | ||||
| #include <stdlib.h> | ||||
| #include <string.h> | ||||
|  |  | |||
|  | @ -0,0 +1,11 @@ | |||
| #ifndef VIETER_CRON_PARSE | ||||
| #define VIETER_CRON_PARSE | ||||
| 
 | ||||
| #include "vieter_cron.h" | ||||
| 
 | ||||
| vieter_cron_parse_error vieter_cron_expr_parse_range(uint64_t *out, char *s, | ||||
|                                                      uint8_t min, uint8_t max); | ||||
| 
 | ||||
| vieter_cron_parse_error vieter_cron_expr_parse_part(uint64_t *out, char *s, | ||||
|                                                     uint8_t min, uint8_t max); | ||||
| #endif | ||||
|  | @ -1,7 +1,7 @@ | |||
| #include "acutest.h" | ||||
| #include "vieter_cron.h" | ||||
| 
 | ||||
| void test_not_allowed() { | ||||
| void test_illegal_expressions() { | ||||
|     char *expressions[] = { | ||||
|         "4 *-7", | ||||
|         "4 *-7/4", | ||||
|  | @ -33,6 +33,6 @@ void test_not_allowed() { | |||
| } | ||||
| 
 | ||||
| TEST_LIST = { | ||||
|     {"not_allowed", test_not_allowed}, | ||||
|     {"cron illegal expressions", test_illegal_expressions}, | ||||
|     {NULL, NULL} | ||||
| }; | ||||
|  |  | |||
|  | @ -0,0 +1,43 @@ | |||
| #include "acutest.h" | ||||
| #include "vieter_cron_parse.h" | ||||
| 
 | ||||
| struct parse_test { | ||||
|     char *part; | ||||
|     uint8_t min; | ||||
|     uint8_t max; | ||||
| }; | ||||
| 
 | ||||
| void test_illegal_parts() { | ||||
|     struct parse_test parts[] = { | ||||
|         { "*-7", 0, 23 }, | ||||
|         { "*-7/4", 0, 23 }, | ||||
|         { "7/*", 0, 23 }, | ||||
|         { "/5", 0, 23 }, | ||||
|         { "4~6", 0, 23 }, | ||||
|         { "5/2-5", 0, 23 }, | ||||
|         { "1/2/3", 0, 23 }, | ||||
|         { "*5", 0, 59 }, | ||||
|         { "x", 0, 59 }, | ||||
|         { NULL, 0, 0 } | ||||
|     }; | ||||
| 
 | ||||
|     int i = 0; | ||||
|     uint64_t out; | ||||
|     char *s; | ||||
| 
 | ||||
|     while (parts[i].part != NULL) { | ||||
|         // Function modifies string in-place
 | ||||
|         s = strdup(parts[i].part); | ||||
| 
 | ||||
|         TEST_CHECK_(vieter_cron_expr_parse_part(&out, s, parts[i].min, parts[i].max) != vieter_cron_parse_ok, "%s (%i - %i)", parts[i].part, parts[i].min, parts[i].max); | ||||
| 
 | ||||
|         free(s); | ||||
| 
 | ||||
|         i++; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| TEST_LIST = { | ||||
|     {"cron illegal parts", test_illegal_parts}, | ||||
|     {NULL, NULL} | ||||
| }; | ||||
|  | @ -178,10 +178,10 @@ void test_pop_random() { | |||
| } | ||||
| 
 | ||||
| TEST_LIST = { | ||||
|     {"init", test_init}, | ||||
|     {"insert", test_insert}, | ||||
|     {"insert random", test_insert_random}, | ||||
|     {"pop", test_pop}, | ||||
|     {"pop random", test_pop_random}, | ||||
|     {"heap init", test_init}, | ||||
|     {"heap insert", test_insert}, | ||||
|     {"heap insert random", test_insert_random}, | ||||
|     {"heap pop", test_pop}, | ||||
|     {"heap pop random", test_pop_random}, | ||||
|     {NULL, NULL} | ||||
| }; | ||||
|  |  | |||
|  | @ -23,6 +23,6 @@ void test_merge_same_order() { | |||
| } | ||||
| 
 | ||||
| TEST_LIST = { | ||||
|     {"merge same order", test_merge_same_order}, | ||||
|     {"heap merge same order", test_merge_same_order}, | ||||
|     {NULL, NULL} | ||||
| }; | ||||
|  |  | |||
|  | @ -51,8 +51,8 @@ void test_remove() { | |||
| } | ||||
| 
 | ||||
| TEST_LIST = { | ||||
|     {"test_init", test_init}, | ||||
|     {"test_insert", test_insert}, | ||||
|     {"test_remove", test_remove}, | ||||
|     {"tree init", test_init}, | ||||
|     {"tree insert", test_insert}, | ||||
|     {"tree remove", test_remove}, | ||||
|     {NULL, NULL} | ||||
| }; | ||||
		Loading…
	
		Reference in New Issue