From f8ede94808348ac12db1d5dd91e5f66624d8b40d Mon Sep 17 00:00:00 2001 From: yorah Date: Tue, 18 Sep 2012 14:10:40 +0200 Subject: Fix adding variable to config file with no trailing newline This can occur after a manual modification of a config file. --- tests-clar/config/write.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests-clar/config/write.c') diff --git a/tests-clar/config/write.c b/tests-clar/config/write.c index 13b669cb2..eeda4d66a 100644 --- a/tests-clar/config/write.c +++ b/tests-clar/config/write.c @@ -3,11 +3,13 @@ void test_config_write__initialize(void) { cl_fixture_sandbox("config/config9"); + cl_fixture_sandbox("config/config17"); } void test_config_write__cleanup(void) { cl_fixture_cleanup("config9"); + cl_fixture_cleanup("config17"); } void test_config_write__replace_value(void) @@ -136,3 +138,19 @@ 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_in_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); +} -- cgit v1.2.1 From a1abe66aca3625eec1cabb2e93cf8df0be1b63f0 Mon Sep 17 00:00:00 2001 From: yorah Date: Mon, 10 Sep 2012 12:11:02 +0200 Subject: Add config level support in the config API Added `struct git_config_entry`: a git_config_entry contains the key, the value, and the config file level from which a config element was found. Added `git_config_open_level`: build a single-level focused config object from a multi-level one. We are now storing `git_config_entry`s in the khash of the config_file --- tests-clar/config/write.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) (limited to 'tests-clar/config/write.c') diff --git a/tests-clar/config/write.c b/tests-clar/config/write.c index eeda4d66a..d98d1dd53 100644 --- a/tests-clar/config/write.c +++ b/tests-clar/config/write.c @@ -3,12 +3,14 @@ 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"); } @@ -69,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; @@ -139,7 +175,45 @@ void test_config_write__escape_value(void) git_config_free(cfg); } -void test_config_write__add_value_in_file_with_no_clrf_at_the_end(void) +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; -- cgit v1.2.1