Skip to content

Commit

Permalink
config: add tests for DT_ON_STARTUP
Browse files Browse the repository at this point in the history
Some config variables may only be set during the startup of NeoMutt.
  • Loading branch information
flatcap committed Nov 8, 2023
1 parent 466a3fa commit 6f95fdb
Show file tree
Hide file tree
Showing 11 changed files with 411 additions and 36 deletions.
63 changes: 46 additions & 17 deletions test/config/bool.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,27 @@
#include "common.h" // IWYU pragma: keep
#include "test_common.h"

// clang-format off
static struct ConfigDef Vars[] = {
{ "Apple", DT_BOOL, 0, 0, NULL, }, /* test_initial_values */
{ "Banana", DT_BOOL, 1, 0, NULL, },
{ "Cherry", DT_BOOL, 0, 0, NULL, },
{ "Damson", DT_BOOL, 0, 0, NULL, }, /* test_string_set */
{ "Elderberry", DT_BOOL, 0, 0, NULL, }, /* test_string_get */
{ "Fig", DT_BOOL, 0, 0, NULL, }, /* test_native_set */
{ "Guava", DT_BOOL, 0, 0, NULL, }, /* test_native_get */
{ "Hawthorn", DT_BOOL, 0, 0, NULL, }, /* test_reset */
{ "Ilama", DT_BOOL, 0, 0, validator_fail, },
{ "Jackfruit", DT_BOOL, 0, 0, validator_succeed, }, /* test_validator */
{ "Kumquat", DT_BOOL, 0, 0, validator_warn, },
{ "Lemon", DT_BOOL, 0, 0, validator_fail, },
{ "Mango", DT_BOOL, 0, 0, NULL, }, /* test_inherit */
{ "Nectarine", DT_BOOL, 0, 0, NULL, }, /* test_toggle */
{ "Olive", DT_QUAD, 0, 0, NULL, },
// clang-format off
{ "Apple", DT_BOOL, 0, 0, NULL, }, /* test_initial_values */
{ "Banana", DT_BOOL, 1, 0, NULL, },
{ "Cherry", DT_BOOL, 0, 0, NULL, },
{ "Damson", DT_BOOL, 0, 0, NULL, }, /* test_string_set */
{ "Elderberry", DT_BOOL, 0, 0, NULL, }, /* test_string_get */
{ "Fig", DT_BOOL, 0, 0, NULL, }, /* test_native_set */
{ "Guava", DT_BOOL, 0, 0, NULL, }, /* test_native_get */
{ "Hawthorn", DT_BOOL, 0, 0, NULL, }, /* test_reset */
{ "Ilama", DT_BOOL, 0, 0, validator_fail, },
{ "Jackfruit", DT_BOOL, 0, 0, validator_succeed, }, /* test_validator */
{ "Kumquat", DT_BOOL, 0, 0, validator_warn, },
{ "Lemon", DT_BOOL, 0, 0, validator_fail, },
{ "Mango", DT_BOOL, 0, 0, NULL, }, /* test_inherit */
{ "Nectarine", DT_BOOL, 0, 0, NULL, }, /* test_toggle */
{ "Olive", DT_QUAD, 0, 0, NULL, },
{ "Papaya", DT_BOOL | DT_ON_STARTUP, 1, 0, NULL, }, /* startup */
{ NULL },
// clang-format on
};
// clang-format on

static bool test_initial_values(struct ConfigSubset *sub, struct Buffer *err)
{
Expand Down Expand Up @@ -219,6 +220,13 @@ static bool test_string_set(struct ConfigSubset *sub, struct Buffer *err)
short_line();
}

name = "Papaya";
rc = cs_str_string_set(cs, name, "1", err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);

rc = cs_str_string_set(cs, name, "0", err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

log_line(__func__);
return true;
}
Expand Down Expand Up @@ -329,6 +337,13 @@ static bool test_native_set(struct ConfigSubset *sub, struct Buffer *err)
}
}

name = "Papaya";
rc = cs_str_native_set(cs, name, 1, err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);

rc = cs_str_native_set(cs, name, 0, err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

log_line(__func__);
return true;
}
Expand Down Expand Up @@ -426,6 +441,18 @@ static bool test_reset(struct ConfigSubset *sub, struct Buffer *err)

TEST_MSG("Reset: %s = %d", name, VarIlama);

name = "Papaya";
rc = cs_str_reset(cs, name, err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);

StartupComplete = false;
rc = cs_str_native_set(cs, name, 0, err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);
StartupComplete = true;

rc = cs_str_reset(cs, name, err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

log_line(__func__);
return true;
}
Expand Down Expand Up @@ -791,10 +818,12 @@ void test_config_bool(void)
struct ConfigSubset *sub = NeoMutt->sub;
struct ConfigSet *cs = sub->cs;

StartupComplete = false;
dont_fail = true;
if (!TEST_CHECK(cs_register_variables(cs, Vars, DT_NO_FLAGS)))
return;
dont_fail = false;
StartupComplete = true;

notify_observer_add(NeoMutt->notify, NT_CONFIG, log_observer, 0);

Expand Down
29 changes: 29 additions & 0 deletions test/config/enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static struct ConfigDef Vars[] = {
{ "Mango", DT_ENUM, ANIMAL_ANTELOPE, IP &AnimalDef, validator_warn, },
{ "Nectarine", DT_ENUM, ANIMAL_ANTELOPE, IP &AnimalDef, validator_fail, },
{ "Olive", DT_ENUM, ANIMAL_ANTELOPE, IP &AnimalDef, NULL, }, /* test_inherit */
{ "Papaya", DT_ENUM | DT_ON_STARTUP, ANIMAL_ANTELOPE, IP &AnimalDef, NULL, }, /* startup */
{ NULL },
};
// clang-format on
Expand Down Expand Up @@ -251,6 +252,13 @@ static bool test_string_set(struct ConfigSubset *sub, struct Buffer *err)
return false;
}

name = "Papaya";
rc = cs_str_string_set(cs, name, "Antelope", err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);

rc = cs_str_string_set(cs, name, "Badger", err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

log_line(__func__);
return true;
}
Expand Down Expand Up @@ -377,6 +385,13 @@ static bool test_native_set(struct ConfigSubset *sub, struct Buffer *err)
return false;
}

name = "Papaya";
rc = cs_str_native_set(cs, name, ANIMAL_ANTELOPE, err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);

rc = cs_str_native_set(cs, name, ANIMAL_BADGER, err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

log_line(__func__);
return true;
}
Expand Down Expand Up @@ -473,6 +488,18 @@ static bool test_reset(struct ConfigSubset *sub, struct Buffer *err)
return false;
}

name = "Papaya";
rc = cs_str_reset(cs, name, err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);

StartupComplete = false;
rc = cs_str_native_set(cs, name, ANIMAL_BADGER, err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);
StartupComplete = true;

rc = cs_str_reset(cs, name, err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

log_line(__func__);
return true;
}
Expand Down Expand Up @@ -671,8 +698,10 @@ void test_config_enum(void)
struct ConfigSubset *sub = NeoMutt->sub;
struct ConfigSet *cs = sub->cs;

StartupComplete = false;
if (!TEST_CHECK(cs_register_variables(cs, Vars, DT_NO_FLAGS)))
return;
StartupComplete = true;

notify_observer_add(NeoMutt->notify, NT_CONFIG, log_observer, 0);

Expand Down
37 changes: 37 additions & 0 deletions test/config/long.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static struct ConfigDef Vars[] = {
{ "Mango", DT_LONG, 0, 0, validator_warn, },
{ "Nectarine", DT_LONG, 0, 0, validator_fail, },
{ "Olive", DT_LONG, 0, 0, NULL, }, /* test_inherit */
{ "Papaya", DT_LONG | DT_ON_STARTUP, 1, 0, NULL, }, /* startup */
{ NULL },
};
// clang-format on
Expand Down Expand Up @@ -220,6 +221,13 @@ static bool test_string_set(struct ConfigSubset *sub, struct Buffer *err)
return false;
}

name = "Papaya";
rc = cs_str_string_set(cs, name, "1", err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);

rc = cs_str_string_set(cs, name, "0", err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

log_line(__func__);
return true;
}
Expand Down Expand Up @@ -333,6 +341,10 @@ static bool test_string_plus_equals(struct ConfigSubset *sub, struct Buffer *err
return false;
}

name = "Papaya";
rc = cs_str_string_plus_equals(cs, name, "1", err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

log_line(__func__);
return true;
}
Expand Down Expand Up @@ -414,6 +426,10 @@ static bool test_string_minus_equals(struct ConfigSubset *sub, struct Buffer *er
return false;
}

name = "Papaya";
rc = cs_str_string_minus_equals(cs, name, "1", err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

log_line(__func__);
return true;
}
Expand Down Expand Up @@ -472,6 +488,13 @@ static bool test_native_set(struct ConfigSubset *sub, struct Buffer *err)
return false;
}

name = "Papaya";
rc = cs_str_native_set(cs, name, 1, err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);

rc = cs_str_native_set(cs, name, 0, err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

log_line(__func__);
return true;
}
Expand Down Expand Up @@ -557,6 +580,18 @@ static bool test_reset(struct ConfigSubset *sub, struct Buffer *err)

TEST_MSG("Reset: %s = %ld", name, VarKumquat);

name = "Papaya";
rc = cs_str_reset(cs, name, err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);

StartupComplete = false;
rc = cs_str_native_set(cs, name, 0, err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);
StartupComplete = true;

rc = cs_str_reset(cs, name, err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

log_line(__func__);
return true;
}
Expand Down Expand Up @@ -831,10 +866,12 @@ void test_config_long(void)
struct ConfigSubset *sub = NeoMutt->sub;
struct ConfigSet *cs = sub->cs;

StartupComplete = false;
dont_fail = true;
if (!TEST_CHECK(cs_register_variables(cs, Vars, DT_NO_FLAGS)))
return;
dont_fail = false;
StartupComplete = true;

notify_observer_add(NeoMutt->notify, NT_CONFIG, log_observer, 0);

Expand Down
73 changes: 55 additions & 18 deletions test/config/mbtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,25 @@

// clang-format off
static struct ConfigDef Vars[] = {
{ "Apple", DT_MBTABLE, IP "apple", 0, NULL, }, /* test_initial_values */
{ "Banana", DT_MBTABLE, IP "banana", 0, NULL, },
{ "Cherry", DT_MBTABLE, IP "cherry", 0, NULL, },
{ "Damson", DT_MBTABLE, 0, 0, NULL, }, /* test_mbtable_set */
{ "Elderberry", DT_MBTABLE, IP "elderberry", 0, NULL, },
{ "Fig", DT_MBTABLE, 0, 0, NULL, }, /* test_mbtable_get */
{ "Guava", DT_MBTABLE, IP "guava", 0, NULL, },
{ "Hawthorn", DT_MBTABLE, 0, 0, NULL, },
{ "Ilama", DT_MBTABLE, 0, 0, NULL, }, /* test_native_set */
{ "Jackfruit", DT_MBTABLE, IP "jackfruit", 0, NULL, },
{ "Kumquat", DT_MBTABLE, 0, 0, NULL, }, /* test_native_get */
{ "Lemon", DT_MBTABLE, IP "lemon", 0, NULL, }, /* test_reset */
{ "Mango", DT_MBTABLE, IP "mango", 0, validator_fail, },
{ "Nectarine", DT_MBTABLE, IP "nectarine", 0, validator_succeed, }, /* test_validator */
{ "Olive", DT_MBTABLE, IP "olive", 0, validator_warn, },
{ "Papaya", DT_MBTABLE, IP "papaya", 0, validator_fail, },
{ "Quince", DT_MBTABLE, 0, 0, NULL, }, /* test_inherit */
{ NULL },
{ "Apple", DT_MBTABLE, IP "apple", 0, NULL, }, /* test_initial_values */
{ "Banana", DT_MBTABLE, IP "banana", 0, NULL, },
{ "Cherry", DT_MBTABLE, IP "cherry", 0, NULL, },
{ "Damson", DT_MBTABLE, 0, 0, NULL, }, /* test_mbtable_set */
{ "Elderberry", DT_MBTABLE, IP "elderberry", 0, NULL, },
{ "Fig", DT_MBTABLE, 0, 0, NULL, }, /* test_mbtable_get */
{ "Guava", DT_MBTABLE, IP "guava", 0, NULL, },
{ "Hawthorn", DT_MBTABLE, 0, 0, NULL, },
{ "Ilama", DT_MBTABLE, 0, 0, NULL, }, /* test_native_set */
{ "Jackfruit", DT_MBTABLE, IP "jackfruit", 0, NULL, },
{ "Kumquat", DT_MBTABLE, 0, 0, NULL, }, /* test_native_get */
{ "Lemon", DT_MBTABLE, IP "lemon", 0, NULL, }, /* test_reset */
{ "Mango", DT_MBTABLE, IP "mango", 0, validator_fail, },
{ "Nectarine", DT_MBTABLE, IP "nectarine", 0, validator_succeed, }, /* test_validator */
{ "Olive", DT_MBTABLE, IP "olive", 0, validator_warn, },
{ "Papaya", DT_MBTABLE, IP "papaya", 0, validator_fail, },
{ "Quince", DT_MBTABLE, 0, 0, NULL, }, /* test_inherit */
{ "Raspberry", DT_MBTABLE|DT_ON_STARTUP, IP "raspberry", 0, NULL, }, /* startup */
{ NULL },
};
// clang-format on

Expand Down Expand Up @@ -226,6 +227,13 @@ static bool test_string_set(struct ConfigSubset *sub, struct Buffer *err)
return false;
}

name = "Raspberry";
rc = cs_str_string_set(cs, name, "raspberry", err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);

rc = cs_str_string_set(cs, name, "banana", err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

log_line(__func__);
return true;
}
Expand Down Expand Up @@ -325,6 +333,19 @@ static bool test_native_set(struct ConfigSubset *sub, struct Buffer *err)
mb = VarJackfruit ? VarJackfruit->orig_str : NULL;
TEST_MSG("%s = '%s', set by NULL", name, NONULL(mb));

mbtable_free(&t);
t = mbtable_parse("raspberry");

name = "Raspberry";
rc = cs_str_native_set(cs, name, (intptr_t) t, err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);

mbtable_free(&t);
t = mbtable_parse("apple");

rc = cs_str_native_set(cs, name, (intptr_t) t, err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

result = true;
tns_out:
mbtable_free(&t);
Expand Down Expand Up @@ -429,6 +450,18 @@ static bool test_reset(struct ConfigSubset *sub, struct Buffer *err)

TEST_MSG("Reset: %s = '%s'", name, VarMango->orig_str);

name = "Raspberry";
rc = cs_str_reset(cs, name, err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);

StartupComplete = false;
rc = cs_str_string_set(cs, name, "banana", err);
TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS);
StartupComplete = true;

rc = cs_str_reset(cs, name, err);
TEST_CHECK(CSR_RESULT(rc) != CSR_SUCCESS);

log_line(__func__);
return true;
}
Expand Down Expand Up @@ -674,15 +707,19 @@ void test_config_mbtable(void)
struct ConfigSubset *sub = NeoMutt->sub;
struct ConfigSet *cs = sub->cs;

StartupComplete = false;
dont_fail = true;
if (!TEST_CHECK(cs_register_variables(cs, Vars, DT_NO_FLAGS)))
return;
dont_fail = false;
StartupComplete = true;

notify_observer_add(NeoMutt->notify, NT_CONFIG, log_observer, 0);

set_list(cs);

mbtable_compare(NULL, NULL);

struct Buffer *err = buf_pool_get();
TEST_CHECK(test_initial_values(sub, err));
TEST_CHECK(test_string_set(sub, err));
Expand Down
Loading

0 comments on commit 6f95fdb

Please sign in to comment.