diff options
| author | Carlos Martín Nieto <cmn@dwim.me> | 2015-01-14 15:05:43 +0100 |
|---|---|---|
| committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-01-14 19:36:50 +0100 |
| commit | eac773d92bccc7d3fc7ce1b18578d374873e0d7a (patch) | |
| tree | eb165d11a1a30274ed7ff40d27bd461640067bc3 /tests/config | |
| parent | 4d6f55acce14eeec55729e55335635375e9026df (diff) | |
| download | libgit2-eac773d92bccc7d3fc7ce1b18578d374873e0d7a.tar.gz | |
config: add parsing and getter for pathscmn/config-get-path
Diffstat (limited to 'tests/config')
| -rw-r--r-- | tests/config/read.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/config/read.c b/tests/config/read.c index 25672729f..1799970fb 100644 --- a/tests/config/read.c +++ b/tests/config/read.c @@ -1,4 +1,6 @@ #include "clar_libgit2.h" +#include "buffer.h" +#include "path.h" void test_config_read__simple_read(void) { @@ -567,3 +569,47 @@ void test_config_read__override_variable(void) git_config_free(cfg); } + +void test_config_read__path(void) +{ + git_config *cfg; + git_buf path = GIT_BUF_INIT; + git_buf old_path = GIT_BUF_INIT; + git_buf home_path = GIT_BUF_INIT; + git_buf expected_path = GIT_BUF_INIT; + + cl_git_pass(p_mkdir("fakehome", 0777)); + cl_git_pass(git_path_prettify(&home_path, "fakehome", NULL)); + cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &old_path)); + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, home_path.ptr)); + cl_git_mkfile("./testconfig", "[some]\n path = ~/somefile"); + cl_git_pass(git_path_join_unrooted(&expected_path, "somefile", home_path.ptr, NULL)); + + cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig")); + cl_git_pass(git_config_get_path(&path, cfg, "some.path")); + cl_assert_equal_s(expected_path.ptr, path.ptr); + git_buf_free(&path); + + cl_git_mkfile("./testconfig", "[some]\n path = ~/"); + cl_git_pass(git_path_join_unrooted(&expected_path, "", home_path.ptr, NULL)); + + cl_git_pass(git_config_get_path(&path, cfg, "some.path")); + cl_assert_equal_s(expected_path.ptr, path.ptr); + git_buf_free(&path); + + cl_git_mkfile("./testconfig", "[some]\n path = ~"); + cl_git_pass(git_buf_sets(&expected_path, home_path.ptr)); + + cl_git_pass(git_config_get_path(&path, cfg, "some.path")); + cl_assert_equal_s(expected_path.ptr, path.ptr); + git_buf_free(&path); + + cl_git_mkfile("./testconfig", "[some]\n path = ~user/foo"); + cl_git_fail(git_config_get_path(&path, cfg, "some.path")); + + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, old_path.ptr)); + git_buf_free(&old_path); + git_buf_free(&home_path); + git_buf_free(&expected_path); + git_config_free(cfg); +} |
