diff options
author | Nelson Elhage <nelhage@nelhage.com> | 2018-08-14 04:22:14 +0000 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2018-10-26 14:58:51 +0200 |
commit | f4a7652a6fecd2758cb589ff6567254e17aefa41 (patch) | |
tree | b897a272fa19e3e58dce53705f5a3af67ba3ec64 | |
parent | ef52371200e0ff74c71c33f85fdbc21031a1adcd (diff) | |
download | libgit2-f4a7652a6fecd2758cb589ff6567254e17aefa41.tar.gz |
Fix the test and comment.
(cherry picked from commit 6698e0562d0f782903f28c224c879da7c2abf674)
-rw-r--r-- | tests/config/read.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/config/read.c b/tests/config/read.c index 8a447d3af..646567134 100644 --- a/tests/config/read.c +++ b/tests/config/read.c @@ -749,16 +749,34 @@ void test_config_read__bom(void) git_buf_free(&buf); } +static int read_nosection_cb(const git_config_entry *entry, void *payload) { + int *seen = (int*)payload; + if (strcmp(entry->name, "key") == 0) { + (*seen)++; + } + return 0; +} + /* This would ideally issue a warning, if we had a way to do so. */ void test_config_read__nosection(void) { git_config *cfg; git_buf buf = GIT_BUF_INIT; + int seen = 0; cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-nosection"))); - cl_git_pass(git_config_get_string_buf(&buf, cfg, "key")); - cl_assert_equal_s(buf.ptr, "value"); + /* + * Given a key with no section, we do not allow reading it, + * but we do include it in an iteration over the config + * store. This appears to match how git's own APIs (and + * git-config(1)) behave. + */ + + cl_git_fail_with(git_config_get_string_buf(&buf, cfg, "key"), GIT_EINVALIDSPEC); + + cl_git_pass(git_config_foreach(cfg, read_nosection_cb, &seen)); + cl_assert_equal_i(seen, 1); git_buf_free(&buf); git_config_free(cfg); |