diff options
author | Patrick Steinhardt <ps@pks.im> | 2017-06-06 09:45:11 +0200 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2017-07-15 14:14:50 +0200 |
commit | 6f7aab0cd210666dc314bf1f213b6f35dd707ec8 (patch) | |
tree | f5be42f26cf63bd22eb716a5963b6a639b210a4a | |
parent | 8149f850ca98e56cc56f7f66aa9fbb6c04801152 (diff) | |
download | libgit2-6f7aab0cd210666dc314bf1f213b6f35dd707ec8.tar.gz |
tests: config::include: use init and cleanup functions
-rw-r--r-- | tests/config/include.c | 58 |
1 files changed, 15 insertions, 43 deletions
diff --git a/tests/config/include.c b/tests/config/include.c index 0a07c9b85..0696f285e 100644 --- a/tests/config/include.c +++ b/tests/config/include.c @@ -2,25 +2,31 @@ #include "buffer.h" #include "fileops.h" -void test_config_include__relative(void) +static git_config *cfg; +static git_buf buf; + +void test_config_include__initialize(void) { - git_config *cfg; - git_buf buf = GIT_BUF_INIT; + cfg = NULL; + git_buf_init(&buf, 0); +} +void test_config_include__cleanup(void) +{ + git_config_free(cfg); + git_buf_free(&buf); +} + +void test_config_include__relative(void) +{ cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-include"))); cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz")); cl_assert_equal_s("huzzah", git_buf_cstr(&buf)); - - git_buf_free(&buf); - git_config_free(cfg); } void test_config_include__absolute(void) { - git_config *cfg; - git_buf buf = GIT_BUF_INIT; - cl_git_pass(git_buf_printf(&buf, "[include]\npath = %s/config-included", cl_fixture("config"))); cl_git_mkfile("config-include-absolute", git_buf_cstr(&buf)); @@ -29,16 +35,10 @@ void test_config_include__absolute(void) cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz")); cl_assert_equal_s("huzzah", git_buf_cstr(&buf)); - - git_buf_free(&buf); - git_config_free(cfg); } void test_config_include__homedir(void) { - git_config *cfg; - git_buf buf = GIT_BUF_INIT; - cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config"))); cl_git_mkfile("config-include-homedir", "[include]\npath = ~/config-included"); @@ -47,18 +47,12 @@ void test_config_include__homedir(void) cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz")); cl_assert_equal_s("huzzah", git_buf_cstr(&buf)); - git_buf_free(&buf); - git_config_free(cfg); - cl_sandbox_set_search_path_defaults(); } /* We need to pretend that the variables were defined where the file was included */ void test_config_include__ordering(void) { - git_config *cfg; - git_buf buf = GIT_BUF_INIT; - cl_git_mkfile("included", "[foo \"bar\"]\nbaz = hurrah\nfrotz = hiya"); cl_git_mkfile("including", "[foo \"bar\"]\nfrotz = hello\n" @@ -72,16 +66,11 @@ void test_config_include__ordering(void) git_buf_clear(&buf); cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar.baz")); cl_assert_equal_s("huzzah", git_buf_cstr(&buf)); - - git_buf_free(&buf); - git_config_free(cfg); } /* We need to pretend that the variables were defined where the file was included */ void test_config_include__depth(void) { - git_config *cfg; - cl_git_mkfile("a", "[include]\npath = b"); cl_git_mkfile("b", "[include]\npath = a"); @@ -93,9 +82,6 @@ void test_config_include__depth(void) void test_config_include__missing(void) { - git_config *cfg; - git_buf buf = GIT_BUF_INIT; - cl_git_mkfile("including", "[include]\npath = nonexistentfile\n[foo]\nbar = baz"); giterr_clear(); @@ -103,16 +89,10 @@ void test_config_include__missing(void) cl_assert(giterr_last() == NULL); cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar")); cl_assert_equal_s("baz", git_buf_cstr(&buf)); - - git_buf_free(&buf); - git_config_free(cfg); } void test_config_include__missing_homedir(void) { - git_config *cfg; - git_buf buf = GIT_BUF_INIT; - cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config"))); cl_git_mkfile("including", "[include]\npath = ~/.nonexistentfile\n[foo]\nbar = baz"); @@ -122,17 +102,12 @@ void test_config_include__missing_homedir(void) cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar")); cl_assert_equal_s("baz", git_buf_cstr(&buf)); - git_buf_free(&buf); - git_config_free(cfg); - cl_sandbox_set_search_path_defaults(); } #define replicate10(s) s s s s s s s s s s void test_config_include__depth2(void) { - git_config *cfg; - git_buf buf = GIT_BUF_INIT; const char *content = "[include]\n" replicate10(replicate10("path=bottom\n")); cl_git_mkfile("top-level", "[include]\npath = middle\n[foo]\nbar = baz"); @@ -147,7 +122,4 @@ void test_config_include__depth2(void) git_buf_clear(&buf); cl_git_pass(git_config_get_string_buf(&buf, cfg, "foo.bar2")); cl_assert_equal_s("baz2", git_buf_cstr(&buf)); - - git_buf_free(&buf); - git_config_free(cfg); } |