diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-12-25 22:27:10 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-12-25 22:33:38 +0000 |
| commit | 46eea7561461c9e5320b36b64015e171b2cb98b9 (patch) | |
| tree | 74599938a5b2b75d31753ca0cbd9ac36ad27eaf5 /tests | |
| parent | tokenize: free content of argv on failure, and reset the argv pointer (diff) | |
test: config: add test_spawn_template() utility function
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test-config.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test-config.c b/tests/test-config.c index 4e0bea87..4c474393 100644 --- a/tests/test-config.c +++ b/tests/test-config.c @@ -222,6 +222,48 @@ test_pt_or_px(struct context *ctx, bool (*parse_fun)(struct context *ctx), } static void +test_spawn_template(struct context *ctx, bool (*parse_fun)(struct context *ctx), + const char *key, const struct config_spawn_template *ptr) +{ + static const char *const args[] = { + "command", "arg1", "arg2", "arg3 has spaces"}; + + ctx->key = key; + ctx->value = "command arg1 arg2 \"arg3 has spaces\""; + + if (!parse_fun(ctx)) + BUG("[%s].%s=%s: failed to parse", ctx->section, ctx->key, ctx->value); + + if (ptr->argv.args == NULL) + BUG("[%s].%s=%s: argv is NULL", ctx->section, ctx->key, ctx->value); + + for (size_t i = 0; i < ALEN(args); i++) { + if (ptr->argv.args[i] == NULL || + strcmp(ptr->argv.args[i], args[i]) != 0) + { + BUG("[%s].%s=%s: set value not the expected one: " + "mismatch of arg #%zu: expected=\"%s\", got=\"%s\"", + ctx->section, ctx->key, ctx->value, i, + args[i], ptr->argv.args[i]); + } + } + + if (ptr->argv.args[ALEN(args)] != NULL) { + BUG("[%s].%s=%s: set value not the expected one: " + "expected NULL terminator at arg #%zu, got=\"%s\"", + ctx->section, ctx->key, ctx->value, + ALEN(args), ptr->argv.args[ALEN(args)]); + } + + /* Trigger parse failure */ + ctx->value = "command with \"unterminated quote"; + if (parse_fun(ctx)) { + BUG("[%s].%s=%s: did not fail to parse as expected", + ctx->section, ctx->key, ctx->value); + } +} + +static void test_section_main(void) { struct config conf = {0}; |
