22#include "buffer.h"
33#include "fileops.h"
44
5- void test_config_include__relative (void )
5+ static git_config * cfg ;
6+ static git_buf buf ;
7+
8+ void test_config_include__initialize (void )
69{
7- git_config * cfg ;
8- git_buf buf = GIT_BUF_INIT ;
10+ cfg = NULL ;
11+ git_buf_init (& buf , 0 );
12+ }
913
14+ void test_config_include__cleanup (void )
15+ {
16+ git_config_free (cfg );
17+ git_buf_free (& buf );
18+ }
19+
20+ void test_config_include__relative (void )
21+ {
1022 cl_git_pass (git_config_open_ondisk (& cfg , cl_fixture ("config/config-include" )));
1123
1224 cl_git_pass (git_config_get_string_buf (& buf , cfg , "foo.bar.baz" ));
1325 cl_assert_equal_s ("huzzah" , git_buf_cstr (& buf ));
14-
15- git_buf_free (& buf );
16- git_config_free (cfg );
1726}
1827
1928void test_config_include__absolute (void )
2029{
21- git_config * cfg ;
22- git_buf buf = GIT_BUF_INIT ;
23-
2430 cl_git_pass (git_buf_printf (& buf , "[include]\npath = %s/config-included" , cl_fixture ("config" )));
2531
2632 cl_git_mkfile ("config-include-absolute" , git_buf_cstr (& buf ));
@@ -29,16 +35,10 @@ void test_config_include__absolute(void)
2935
3036 cl_git_pass (git_config_get_string_buf (& buf , cfg , "foo.bar.baz" ));
3137 cl_assert_equal_s ("huzzah" , git_buf_cstr (& buf ));
32-
33- git_buf_free (& buf );
34- git_config_free (cfg );
3538}
3639
3740void test_config_include__homedir (void )
3841{
39- git_config * cfg ;
40- git_buf buf = GIT_BUF_INIT ;
41-
4242 cl_git_pass (git_libgit2_opts (GIT_OPT_SET_SEARCH_PATH , GIT_CONFIG_LEVEL_GLOBAL , cl_fixture ("config" )));
4343 cl_git_mkfile ("config-include-homedir" , "[include]\npath = ~/config-included" );
4444
@@ -47,18 +47,12 @@ void test_config_include__homedir(void)
4747 cl_git_pass (git_config_get_string_buf (& buf , cfg , "foo.bar.baz" ));
4848 cl_assert_equal_s ("huzzah" , git_buf_cstr (& buf ));
4949
50- git_buf_free (& buf );
51- git_config_free (cfg );
52-
5350 cl_sandbox_set_search_path_defaults ();
5451}
5552
5653/* We need to pretend that the variables were defined where the file was included */
5754void test_config_include__ordering (void )
5855{
59- git_config * cfg ;
60- git_buf buf = GIT_BUF_INIT ;
61-
6256 cl_git_mkfile ("included" , "[foo \"bar\"]\nbaz = hurrah\nfrotz = hiya" );
6357 cl_git_mkfile ("including" ,
6458 "[foo \"bar\"]\nfrotz = hello\n"
@@ -72,16 +66,11 @@ void test_config_include__ordering(void)
7266 git_buf_clear (& buf );
7367 cl_git_pass (git_config_get_string_buf (& buf , cfg , "foo.bar.baz" ));
7468 cl_assert_equal_s ("huzzah" , git_buf_cstr (& buf ));
75-
76- git_buf_free (& buf );
77- git_config_free (cfg );
7869}
7970
8071/* We need to pretend that the variables were defined where the file was included */
8172void test_config_include__depth (void )
8273{
83- git_config * cfg ;
84-
8574 cl_git_mkfile ("a" , "[include]\npath = b" );
8675 cl_git_mkfile ("b" , "[include]\npath = a" );
8776
@@ -93,26 +82,17 @@ void test_config_include__depth(void)
9382
9483void test_config_include__missing (void )
9584{
96- git_config * cfg ;
97- git_buf buf = GIT_BUF_INIT ;
98-
9985 cl_git_mkfile ("including" , "[include]\npath = nonexistentfile\n[foo]\nbar = baz" );
10086
10187 giterr_clear ();
10288 cl_git_pass (git_config_open_ondisk (& cfg , "including" ));
10389 cl_assert (giterr_last () == NULL );
10490 cl_git_pass (git_config_get_string_buf (& buf , cfg , "foo.bar" ));
10591 cl_assert_equal_s ("baz" , git_buf_cstr (& buf ));
106-
107- git_buf_free (& buf );
108- git_config_free (cfg );
10992}
11093
11194void test_config_include__missing_homedir (void )
11295{
113- git_config * cfg ;
114- git_buf buf = GIT_BUF_INIT ;
115-
11696 cl_git_pass (git_libgit2_opts (GIT_OPT_SET_SEARCH_PATH , GIT_CONFIG_LEVEL_GLOBAL , cl_fixture ("config" )));
11797 cl_git_mkfile ("including" , "[include]\npath = ~/.nonexistentfile\n[foo]\nbar = baz" );
11898
@@ -122,17 +102,12 @@ void test_config_include__missing_homedir(void)
122102 cl_git_pass (git_config_get_string_buf (& buf , cfg , "foo.bar" ));
123103 cl_assert_equal_s ("baz" , git_buf_cstr (& buf ));
124104
125- git_buf_free (& buf );
126- git_config_free (cfg );
127-
128105 cl_sandbox_set_search_path_defaults ();
129106}
130107
131108#define replicate10 (s ) s s s s s s s s s s
132109void test_config_include__depth2 (void )
133110{
134- git_config * cfg ;
135- git_buf buf = GIT_BUF_INIT ;
136111 const char * content = "[include]\n" replicate10 (replicate10 ("path=bottom\n" ));
137112
138113 cl_git_mkfile ("top-level" , "[include]\npath = middle\n[foo]\nbar = baz" );
@@ -147,7 +122,4 @@ void test_config_include__depth2(void)
147122 git_buf_clear (& buf );
148123 cl_git_pass (git_config_get_string_buf (& buf , cfg , "foo.bar2" ));
149124 cl_assert_equal_s ("baz2" , git_buf_cstr (& buf ));
150-
151- git_buf_free (& buf );
152- git_config_free (cfg );
153125}
0 commit comments