summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2019-08-01 13:23:16 +0200
committerPatrick Steinhardt <ps@pks.im>2019-08-01 13:35:51 +0200
commit835211dc4b6afef650222ca2e24545938e28e0cb (patch)
treef122732757ced3d298c229b3895fedab5da855e7 /tests
parent304e58c00487466aa5bd129b1eeb5169d75005e7 (diff)
downloadlibgit2-835211dc4b6afef650222ca2e24545938e28e0cb.tar.gz
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/config/include.c30
-rw-r--r--tests/config/snapshot.c26
2 files changed, 56 insertions, 0 deletions
diff --git a/tests/config/include.c b/tests/config/include.c
index 48261dd92..e2b0fc96c 100644
--- a/tests/config/include.c
+++ b/tests/config/include.c
@@ -202,3 +202,33 @@ void test_config_include__included_variables_cannot_be_modified(void)
cl_git_pass(p_unlink("top-level"));
cl_git_pass(p_unlink("included"));
}
+
+void test_config_include__variables_in_included_override_including(void)
+{
+ int i;
+
+ cl_git_mkfile("top-level", "[foo]\nbar = 1\n[include]\npath = included");
+ cl_git_mkfile("included", "[foo]\nbar = 2");
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
+ cl_git_pass(git_config_get_int32(&i, cfg, "foo.bar"));
+ cl_assert_equal_i(i, 2);
+
+ cl_git_pass(p_unlink("top-level"));
+ cl_git_pass(p_unlink("included"));
+}
+
+void test_config_include__variables_in_including_override_included(void)
+{
+ int i;
+
+ cl_git_mkfile("top-level", "[include]\npath = included\n[foo]\nbar = 1");
+ cl_git_mkfile("included", "[foo]\nbar = 2");
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "top-level"));
+ cl_git_pass(git_config_get_int32(&i, cfg, "foo.bar"));
+ cl_assert_equal_i(i, 1);
+
+ cl_git_pass(p_unlink("top-level"));
+ cl_git_pass(p_unlink("included"));
+}
diff --git a/tests/config/snapshot.c b/tests/config/snapshot.c
index 2e0679e25..61562d206 100644
--- a/tests/config/snapshot.c
+++ b/tests/config/snapshot.c
@@ -74,3 +74,29 @@ void test_config_snapshot__multivar(void)
cl_git_pass(p_unlink("config"));
}
+
+void test_config_snapshot__includes(void)
+{
+ int i;
+
+ cl_git_mkfile("including", "[include]\npath = included");
+ cl_git_mkfile("included", "[section]\nkey = 1\n");
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "including"));
+ cl_git_pass(git_config_snapshot(&snapshot, cfg));
+
+ cl_git_pass(git_config_get_int32(&i, snapshot, "section.key"));
+ cl_assert_equal_i(i, 1);
+
+ /* Rewrite "included" config */
+ cl_git_mkfile("included", "[section]\nkey = 11\n");
+
+ /* Assert that the live config changed, but snapshot remained the same */
+ cl_git_pass(git_config_get_int32(&i, cfg, "section.key"));
+ cl_assert_equal_i(i, 11);
+ cl_git_pass(git_config_get_int32(&i, snapshot, "section.key"));
+ cl_assert_equal_i(i, 1);
+
+ cl_git_pass(p_unlink("including"));
+ cl_git_pass(p_unlink("included"));
+}