diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2015-05-04 07:36:21 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-05-04 07:41:41 -0500 |
commit | d6b7e40497097e4e540962b8efc6a1661b5739a4 (patch) | |
tree | 2375d581789a77f43ece808cbbbf8a6773216ce9 | |
parent | 0daf998de78b2484eefe47c15e883b7eef7b71a7 (diff) | |
download | libgit2-d6b7e40497097e4e540962b8efc6a1661b5739a4.tar.gz |
config: test all multivars are updated
If a multivar exists within two sections (of the same name)
then they should both be updated in a `set_multivar`. Ensure
that this is the case.
-rw-r--r-- | tests/config/write.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/tests/config/write.c b/tests/config/write.c index f497731b8..2e7b8182a 100644 --- a/tests/config/write.c +++ b/tests/config/write.c @@ -230,12 +230,24 @@ void test_config_write__overwrite_value_with_duplicate_header(void) git_config_free(cfg); } +static int multivar_cb(const git_config_entry *entry, void *data) +{ + int *n = (int *)data; + + cl_assert_equal_s(entry->value, "newurl"); + + (*n)++; + + return 0; +} + void test_config_write__overwrite_multivar_within_duplicate_header(void) { const char *file_name = "config-duplicate-header"; const char *entry_name = "remote.origin.url"; git_config *cfg; git_config_entry *entry; + int n = 0; /* This config can occur after removing and re-adding the origin remote */ const char *file_content = @@ -253,17 +265,15 @@ void test_config_write__overwrite_multivar_within_duplicate_header(void) /* Update that entry */ cl_git_pass(git_config_set_multivar(cfg, entry_name, ".*", "newurl")); - - /* Reopen the file and make sure the entry was updated */ git_config_entry_free(entry); git_config_free(cfg); - cl_git_pass(git_config_open_ondisk(&cfg, file_name)); - cl_git_pass(git_config_get_entry(&entry, cfg, entry_name)); - cl_assert_equal_s("newurl", entry->value); + /* Reopen the file and make sure the entry was updated */ + cl_git_pass(git_config_open_ondisk(&cfg, file_name)); + cl_git_pass(git_config_get_multivar_foreach(cfg, entry_name, NULL, multivar_cb, &n)); + cl_assert_equal_i(2, n); /* Cleanup */ - git_config_entry_free(entry); git_config_free(cfg); } |