]> git.proxmox.com Git - libgit2.git/blame - tests/config/configlevel.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / config / configlevel.c
CommitLineData
a1abe66a 1#include "clar_libgit2.h"
2
3void test_config_configlevel__adding_the_same_level_twice_returns_EEXISTS(void)
4{
5 int error;
6 git_config *cfg;
7
8 cl_git_pass(git_config_new(&cfg));
9 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"),
eae0bfdc 10 GIT_CONFIG_LEVEL_LOCAL, NULL, 0));
a1abe66a 11 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"),
eae0bfdc 12 GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
a1abe66a 13 error = git_config_add_file_ondisk(cfg, cl_fixture("config/config16"),
eae0bfdc 14 GIT_CONFIG_LEVEL_GLOBAL, NULL, 0);
a1abe66a 15
16 cl_git_fail(error);
17 cl_assert_equal_i(GIT_EEXISTS, error);
18
19 git_config_free(cfg);
20}
21
22void test_config_configlevel__can_replace_a_config_file_at_an_existing_level(void)
23{
24 git_config *cfg;
e579e0f7 25 git_buf buf = GIT_BUF_INIT;
a1abe66a 26
27 cl_git_pass(git_config_new(&cfg));
28 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
eae0bfdc 29 GIT_CONFIG_LEVEL_LOCAL, NULL, 1));
a1abe66a 30 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
eae0bfdc 31 GIT_CONFIG_LEVEL_LOCAL, NULL, 1));
a1abe66a 32
9a97f49e
CMN
33 cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.stringglobal"));
34 cl_assert_equal_s("don't find me!", buf.ptr);
a1abe66a 35
ac3d33df 36 git_buf_dispose(&buf);
a1abe66a 37 git_config_free(cfg);
38}
39
40void test_config_configlevel__can_read_from_a_single_level_focused_file_after_parent_config_has_been_freed(void)
41{
42 git_config *cfg;
43 git_config *single_level_cfg;
9a97f49e 44 git_buf buf = {0};
a1abe66a 45
46 cl_git_pass(git_config_new(&cfg));
47 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"),
eae0bfdc 48 GIT_CONFIG_LEVEL_GLOBAL, NULL, 0));
a1abe66a 49 cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"),
eae0bfdc 50 GIT_CONFIG_LEVEL_LOCAL, NULL, 0));
a1abe66a 51
52 cl_git_pass(git_config_open_level(&single_level_cfg, cfg, GIT_CONFIG_LEVEL_LOCAL));
53
54 git_config_free(cfg);
55
9a97f49e
CMN
56 cl_git_pass(git_config_get_string_buf(&buf, single_level_cfg, "core.stringglobal"));
57 cl_assert_equal_s("don't find me!", buf.ptr);
a1abe66a 58
ac3d33df 59 git_buf_dispose(&buf);
a1abe66a 60 git_config_free(single_level_cfg);
61}
55f9837f 62
63void test_config_configlevel__fetching_a_level_from_an_empty_compound_config_returns_ENOTFOUND(void)
64{
65 git_config *cfg;
66 git_config *local_cfg;
55f9837f 67
68 cl_git_pass(git_config_new(&cfg));
69
70 cl_assert_equal_i(GIT_ENOTFOUND, git_config_open_level(&local_cfg, cfg, GIT_CONFIG_LEVEL_LOCAL));
71
72 git_config_free(cfg);
73}