diff options
| author | Russell Belfer <rb@github.com> | 2012-10-23 09:53:15 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2012-10-23 09:53:15 -0700 |
| commit | 5b67d145d8f465ed0c7ed9c07d331aae29c2713b (patch) | |
| tree | 17de8c31afbdb3398a391e1fcede5010394dec85 /tests-clar/config/write.c | |
| parent | 8a89aa1f57fc0b352800bc77e228554fe95caddd (diff) | |
| parent | a1abe66aca3625eec1cabb2e93cf8df0be1b63f0 (diff) | |
| download | libgit2-5b67d145d8f465ed0c7ed9c07d331aae29c2713b.tar.gz | |
Merge pull request #923 from yorah/topic/config-store
Add git_config_level support when handling config files
Diffstat (limited to 'tests-clar/config/write.c')
| -rw-r--r-- | tests-clar/config/write.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests-clar/config/write.c b/tests-clar/config/write.c index 13b669cb2..d98d1dd53 100644 --- a/tests-clar/config/write.c +++ b/tests-clar/config/write.c @@ -3,11 +3,15 @@ void test_config_write__initialize(void) { cl_fixture_sandbox("config/config9"); + cl_fixture_sandbox("config/config15"); + cl_fixture_sandbox("config/config17"); } void test_config_write__cleanup(void) { cl_fixture_cleanup("config9"); + cl_fixture_cleanup("config15"); + cl_fixture_cleanup("config17"); } void test_config_write__replace_value(void) @@ -67,6 +71,40 @@ void test_config_write__delete_value(void) git_config_free(cfg); } +/* + * At the beginning of the test: + * - config9 has: core.dummy2=42 + * - config15 has: core.dummy2=7 + */ +void test_config_write__delete_value_at_specific_level(void) +{ + git_config *cfg, *cfg_specific; + int32_t i; + + cl_git_pass(git_config_open_ondisk(&cfg, "config15")); + cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2")); + cl_assert(i == 7); + git_config_free(cfg); + + cl_git_pass(git_config_new(&cfg)); + cl_git_pass(git_config_add_file_ondisk(cfg, "config9", + GIT_CONFIG_LEVEL_LOCAL, 0)); + cl_git_pass(git_config_add_file_ondisk(cfg, "config15", + GIT_CONFIG_LEVEL_GLOBAL, 0)); + + cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL)); + + cl_git_pass(git_config_delete(cfg_specific, "core.dummy2")); + git_config_free(cfg); + + cl_git_pass(git_config_open_ondisk(&cfg, "config15")); + cl_assert(git_config_get_int32(&i, cfg, "core.dummy2") == GIT_ENOTFOUND); + cl_git_pass(git_config_set_int32(cfg, "core.dummy2", 7)); + + git_config_free(cfg_specific); + git_config_free(cfg); +} + void test_config_write__write_subsection(void) { git_config *cfg; @@ -136,3 +174,57 @@ void test_config_write__escape_value(void) cl_assert_equal_s(str, "this \"has\" quotes and \t"); git_config_free(cfg); } + +void test_config_write__add_value_at_specific_level(void) +{ + git_config *cfg, *cfg_specific; + int i; + int64_t l, expected = +9223372036854775803; + const char *s; + + // open config15 as global level config file + cl_git_pass(git_config_new(&cfg)); + cl_git_pass(git_config_add_file_ondisk(cfg, "config9", + GIT_CONFIG_LEVEL_LOCAL, 0)); + cl_git_pass(git_config_add_file_ondisk(cfg, "config15", + GIT_CONFIG_LEVEL_GLOBAL, 0)); + + cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL)); + + cl_git_pass(git_config_set_int32(cfg_specific, "core.int32global", 28)); + cl_git_pass(git_config_set_int64(cfg_specific, "core.int64global", expected)); + cl_git_pass(git_config_set_bool(cfg_specific, "core.boolglobal", true)); + cl_git_pass(git_config_set_string(cfg_specific, "core.stringglobal", "I'm a global config value!")); + git_config_free(cfg_specific); + git_config_free(cfg); + + // open config15 as local level config file + cl_git_pass(git_config_open_ondisk(&cfg, "config15")); + + cl_git_pass(git_config_get_int32(&i, cfg, "core.int32global")); + cl_assert_equal_i(28, i); + cl_git_pass(git_config_get_int64(&l, cfg, "core.int64global")); + cl_assert(l == expected); + cl_git_pass(git_config_get_bool(&i, cfg, "core.boolglobal")); + cl_assert_equal_b(true, i); + cl_git_pass(git_config_get_string(&s, cfg, "core.stringglobal")); + cl_assert_equal_s("I'm a global config value!", s); + + git_config_free(cfg); +} + +void test_config_write__add_value_at_file_with_no_clrf_at_the_end(void) +{ + git_config *cfg; + int i; + + cl_git_pass(git_config_open_ondisk(&cfg, "config17")); + cl_git_pass(git_config_set_int32(cfg, "core.newline", 7)); + git_config_free(cfg); + + cl_git_pass(git_config_open_ondisk(&cfg, "config17")); + cl_git_pass(git_config_get_int32(&i, cfg, "core.newline")); + cl_assert_equal_i(7, i); + + git_config_free(cfg); +} |
