Skip to content

Commit 835211d

Browse files
committed
tests: config: assert behaviour around includes
Add a few tests that verify some behaviour centered around includes. The first set of tests verifies that we correctly override values depending on the order of includes and other keys, the second set asserts that we can correctly snapshot configuration files with includes.
1 parent 304e58c commit 835211d

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

tests/config/include.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,33 @@ void test_config_include__included_variables_cannot_be_modified(void)
202202
cl_git_pass(p_unlink("top-level"));
203203
cl_git_pass(p_unlink("included"));
204204
}
205+
206+
void test_config_include__variables_in_included_override_including(void)
207+
{
208+
int i;
209+
210+
cl_git_mkfile("top-level", "[foo]\nbar = 1\n[include]\npath = included");
211+
cl_git_mkfile("included", "[foo]\nbar = 2");
212+
213+
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
214+
cl_git_pass(git_config_get_int32(&i, cfg, "foo.bar"));
215+
cl_assert_equal_i(i, 2);
216+
217+
cl_git_pass(p_unlink("top-level"));
218+
cl_git_pass(p_unlink("included"));
219+
}
220+
221+
void test_config_include__variables_in_including_override_included(void)
222+
{
223+
int i;
224+
225+
cl_git_mkfile("top-level", "[include]\npath = included\n[foo]\nbar = 1");
226+
cl_git_mkfile("included", "[foo]\nbar = 2");
227+
228+
cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
229+
cl_git_pass(git_config_get_int32(&i, cfg, "foo.bar"));
230+
cl_assert_equal_i(i, 1);
231+
232+
cl_git_pass(p_unlink("top-level"));
233+
cl_git_pass(p_unlink("included"));
234+
}

tests/config/snapshot.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,29 @@ void test_config_snapshot__multivar(void)
7474

7575
cl_git_pass(p_unlink("config"));
7676
}
77+
78+
void test_config_snapshot__includes(void)
79+
{
80+
int i;
81+
82+
cl_git_mkfile("including", "[include]\npath = included");
83+
cl_git_mkfile("included", "[section]\nkey = 1\n");
84+
85+
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
86+
cl_git_pass(git_config_snapshot(&snapshot, cfg));
87+
88+
cl_git_pass(git_config_get_int32(&i, snapshot, "section.key"));
89+
cl_assert_equal_i(i, 1);
90+
91+
/* Rewrite "included" config */
92+
cl_git_mkfile("included", "[section]\nkey = 11\n");
93+
94+
/* Assert that the live config changed, but snapshot remained the same */
95+
cl_git_pass(git_config_get_int32(&i, cfg, "section.key"));
96+
cl_assert_equal_i(i, 11);
97+
cl_git_pass(git_config_get_int32(&i, snapshot, "section.key"));
98+
cl_assert_equal_i(i, 1);
99+
100+
cl_git_pass(p_unlink("including"));
101+
cl_git_pass(p_unlink("included"));
102+
}

0 commit comments

Comments
 (0)