diff --git a/README.md b/README.md index d1fef1a..abc250a 100644 --- a/README.md +++ b/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 diff --git a/src/cron/vieter_cron_parse.c b/src/cron/vieter_cron_parse.c index a82d1c3..b42e1a9 100644 --- a/src/cron/vieter_cron_parse.c +++ b/src/cron/vieter_cron_parse.c @@ -1,4 +1,4 @@ -#include "vieter_cron.h" +#include "vieter_cron_parse.h" #include #include #include diff --git a/src/cron/vieter_cron_parse.h b/src/cron/vieter_cron_parse.h new file mode 100644 index 0000000..21ccf81 --- /dev/null +++ b/src/cron/vieter_cron_parse.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 diff --git a/test/cron/test_parse.c b/test/cron/test_parse.c index 030c720..6417c40 100644 --- a/test/cron/test_parse.c +++ b/test/cron/test_parse.c @@ -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} }; diff --git a/test/cron/test_parse_part.c b/test/cron/test_parse_part.c new file mode 100644 index 0000000..5c9c10e --- /dev/null +++ b/test/cron/test_parse_part.c @@ -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} +}; diff --git a/test/heap/test_heap.c b/test/heap/test_heap.c index f77b0dc..31ea354 100644 --- a/test/heap/test_heap.c +++ b/test/heap/test_heap.c @@ -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} }; diff --git a/test/heap/test_merge.c b/test/heap/test_merge.c index 10053f2..f0861fe 100644 --- a/test/heap/test_merge.c +++ b/test/heap/test_merge.c @@ -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} }; diff --git a/test/tree/test_binary_tree.c b/test/tree/test_tree.c similarity index 93% rename from test/tree/test_binary_tree.c rename to test/tree/test_tree.c index aa7fc0f..d0ea661 100644 --- a/test/tree/test_binary_tree.c +++ b/test/tree/test_tree.c @@ -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} };