test: rename some stuff; separate cron part tests
ci/woodpecker/pr/lint Pipeline was successful Details
ci/woodpecker/pr/test Pipeline was successful Details
ci/woodpecker/pr/test-mem Pipeline was successful Details

pull/5/head
Jef Roosens 2023-01-28 09:30:35 +01:00
parent adfdca18da
commit 3bf3150b4a
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
8 changed files with 77 additions and 12 deletions

View File

@ -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 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`. 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` ### `compile_commands.json`
Clangd requires a `compile_commands.json` to function properly. You can Clangd requires a `compile_commands.json` to function properly. You can

View File

@ -1,4 +1,4 @@
#include "vieter_cron.h" #include "vieter_cron_parse.h"
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@ -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

View File

@ -1,7 +1,7 @@
#include "acutest.h" #include "acutest.h"
#include "vieter_cron.h" #include "vieter_cron.h"
void test_not_allowed() { void test_illegal_expressions() {
char *expressions[] = { char *expressions[] = {
"4 *-7", "4 *-7",
"4 *-7/4", "4 *-7/4",
@ -33,6 +33,6 @@ void test_not_allowed() {
} }
TEST_LIST = { TEST_LIST = {
{"not_allowed", test_not_allowed}, {"cron illegal expressions", test_illegal_expressions},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -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}
};

View File

@ -178,10 +178,10 @@ void test_pop_random() {
} }
TEST_LIST = { TEST_LIST = {
{"init", test_init}, {"heap init", test_init},
{"insert", test_insert}, {"heap insert", test_insert},
{"insert random", test_insert_random}, {"heap insert random", test_insert_random},
{"pop", test_pop}, {"heap pop", test_pop},
{"pop random", test_pop_random}, {"heap pop random", test_pop_random},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -23,6 +23,6 @@ void test_merge_same_order() {
} }
TEST_LIST = { TEST_LIST = {
{"merge same order", test_merge_same_order}, {"heap merge same order", test_merge_same_order},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -51,8 +51,8 @@ void test_remove() {
} }
TEST_LIST = { TEST_LIST = {
{"test_init", test_init}, {"tree init", test_init},
{"test_insert", test_insert}, {"tree insert", test_insert},
{"test_remove", test_remove}, {"tree remove", test_remove},
{NULL, NULL} {NULL, NULL}
}; };