mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-07 07:10:07 +00:00
Add more tests for git_config_get_multivar
The old tests didn't try failing lookups or lookups across multiple config files with some having the pattern and some not having it.
This commit is contained in:
parent
07fba63e9e
commit
7b5c0d1846
@ -1,6 +1,6 @@
|
||||
#include "clar_libgit2.h"
|
||||
|
||||
static const char *_name = "remote.fancy.url";
|
||||
static const char *_name = "remote.ab.url";
|
||||
|
||||
void test_config_multivar__initialize(void)
|
||||
{
|
||||
@ -46,20 +46,60 @@ static int cb(const git_config_entry *entry, void *data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void check_get_multivar(
|
||||
git_config *cfg, int expected, int expected_patterned)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
if (expected > 0) {
|
||||
cl_git_pass(git_config_get_multivar(cfg, _name, NULL, cb, &n));
|
||||
cl_assert_equal_i(expected, n);
|
||||
} else {
|
||||
cl_assert_equal_i(GIT_ENOTFOUND,
|
||||
git_config_get_multivar(cfg, _name, NULL, cb, &n));
|
||||
}
|
||||
|
||||
n = 0;
|
||||
|
||||
if (expected_patterned > 0) {
|
||||
cl_git_pass(git_config_get_multivar(cfg, _name, "example", cb, &n));
|
||||
cl_assert_equal_i(expected_patterned, n);
|
||||
} else {
|
||||
cl_assert_equal_i(GIT_ENOTFOUND,
|
||||
git_config_get_multivar(cfg, _name, "example", cb, &n));
|
||||
}
|
||||
}
|
||||
|
||||
void test_config_multivar__get(void)
|
||||
{
|
||||
git_config *cfg;
|
||||
int n;
|
||||
|
||||
cl_git_pass(git_config_open_ondisk(&cfg, "config/config11"));
|
||||
check_get_multivar(cfg, 2, 1);
|
||||
|
||||
n = 0;
|
||||
cl_git_pass(git_config_get_multivar(cfg, _name, NULL, cb, &n));
|
||||
cl_assert(n == 2);
|
||||
/* add another that has the _name entry */
|
||||
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config9", GIT_CONFIG_LEVEL_SYSTEM, 1));
|
||||
check_get_multivar(cfg, 3, 2);
|
||||
|
||||
n = 0;
|
||||
cl_git_pass(git_config_get_multivar(cfg, _name, "example", cb, &n));
|
||||
cl_assert(n == 1);
|
||||
/* add another that does not have the _name entry */
|
||||
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config0", GIT_CONFIG_LEVEL_GLOBAL, 1));
|
||||
check_get_multivar(cfg, 3, 2);
|
||||
|
||||
/* add another that does not have the _name entry at the end */
|
||||
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config1", GIT_CONFIG_LEVEL_APP, 1));
|
||||
check_get_multivar(cfg, 3, 2);
|
||||
|
||||
/* drop original file */
|
||||
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config2", GIT_CONFIG_LEVEL_LOCAL, 1));
|
||||
check_get_multivar(cfg, 1, 1);
|
||||
|
||||
/* drop other file with match */
|
||||
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config3", GIT_CONFIG_LEVEL_SYSTEM, 1));
|
||||
check_get_multivar(cfg, 0, 0);
|
||||
|
||||
/* reload original file (add different place in order) */
|
||||
cl_git_pass(git_config_add_file_ondisk(cfg, "config/config11", GIT_CONFIG_LEVEL_SYSTEM, 1));
|
||||
check_get_multivar(cfg, 2, 1);
|
||||
|
||||
git_config_free(cfg);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
[remote "fancy"]
|
||||
[remote "ab"]
|
||||
url = git://github.com/libgit2/libgit2
|
||||
url = git://git.example.com/libgit2
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user