diff options
Diffstat (limited to 'tests-clar/config')
| -rw-r--r-- | tests-clar/config/add.c | 37 | ||||
| -rw-r--r-- | tests-clar/config/backend.c | 24 | ||||
| -rw-r--r-- | tests-clar/config/config_helpers.c | 37 | ||||
| -rw-r--r-- | tests-clar/config/config_helpers.h | 9 | ||||
| -rw-r--r-- | tests-clar/config/configlevel.c | 71 | ||||
| -rw-r--r-- | tests-clar/config/global.c | 72 | ||||
| -rw-r--r-- | tests-clar/config/include.c | 109 | ||||
| -rw-r--r-- | tests-clar/config/multivar.c | 288 | ||||
| -rw-r--r-- | tests-clar/config/new.c | 32 | ||||
| -rw-r--r-- | tests-clar/config/read.c | 569 | ||||
| -rw-r--r-- | tests-clar/config/refresh.c | 67 | ||||
| -rw-r--r-- | tests-clar/config/stress.c | 92 | ||||
| -rw-r--r-- | tests-clar/config/validkeyname.c | 68 | ||||
| -rw-r--r-- | tests-clar/config/write.c | 305 |
14 files changed, 0 insertions, 1780 deletions
diff --git a/tests-clar/config/add.c b/tests-clar/config/add.c deleted file mode 100644 index 405f1e2c9..000000000 --- a/tests-clar/config/add.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "clar_libgit2.h" - -void test_config_add__initialize(void) -{ - cl_fixture_sandbox("config/config10"); -} - -void test_config_add__cleanup(void) -{ - cl_fixture_cleanup("config10"); -} - -void test_config_add__to_existing_section(void) -{ - git_config *cfg; - int32_t i; - - cl_git_pass(git_config_open_ondisk(&cfg, "config10")); - cl_git_pass(git_config_set_int32(cfg, "empty.tmp", 5)); - cl_git_pass(git_config_get_int32(&i, cfg, "empty.tmp")); - cl_assert(i == 5); - cl_git_pass(git_config_delete_entry(cfg, "empty.tmp")); - git_config_free(cfg); -} - -void test_config_add__to_new_section(void) -{ - git_config *cfg; - int32_t i; - - cl_git_pass(git_config_open_ondisk(&cfg, "config10")); - cl_git_pass(git_config_set_int32(cfg, "section.tmp", 5)); - cl_git_pass(git_config_get_int32(&i, cfg, "section.tmp")); - cl_assert(i == 5); - cl_git_pass(git_config_delete_entry(cfg, "section.tmp")); - git_config_free(cfg); -} diff --git a/tests-clar/config/backend.c b/tests-clar/config/backend.c deleted file mode 100644 index 3fd6eb114..000000000 --- a/tests-clar/config/backend.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "clar_libgit2.h" -#include "git2/sys/config.h" - -void test_config_backend__checks_version(void) -{ - git_config *cfg; - git_config_backend backend = GIT_CONFIG_BACKEND_INIT; - const git_error *err; - - backend.version = 1024; - - cl_git_pass(git_config_new(&cfg)); - cl_git_fail(git_config_add_backend(cfg, &backend, 0, false)); - err = giterr_last(); - cl_assert_equal_i(GITERR_INVALID, err->klass); - - giterr_clear(); - backend.version = 1024; - cl_git_fail(git_config_add_backend(cfg, &backend, 0, false)); - err = giterr_last(); - cl_assert_equal_i(GITERR_INVALID, err->klass); - - git_config_free(cfg); -} diff --git a/tests-clar/config/config_helpers.c b/tests-clar/config/config_helpers.c deleted file mode 100644 index 53bd945a0..000000000 --- a/tests-clar/config/config_helpers.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "clar_libgit2.h" -#include "config_helpers.h" -#include "repository.h" - -void assert_config_entry_existence( - git_repository *repo, - const char *name, - bool is_supposed_to_exist) -{ - git_config *config; - const char *out; - int result; - - cl_git_pass(git_repository_config__weakptr(&config, repo)); - - result = git_config_get_string(&out, config, name); - - if (is_supposed_to_exist) - cl_git_pass(result); - else - cl_assert_equal_i(GIT_ENOTFOUND, result); -} - -void assert_config_entry_value( - git_repository *repo, - const char *name, - const char *expected_value) -{ - git_config *config; - const char *out; - - cl_git_pass(git_repository_config__weakptr(&config, repo)); - - cl_git_pass(git_config_get_string(&out, config, name)); - - cl_assert_equal_s(expected_value, out); -} diff --git a/tests-clar/config/config_helpers.h b/tests-clar/config/config_helpers.h deleted file mode 100644 index b887b3d38..000000000 --- a/tests-clar/config/config_helpers.h +++ /dev/null @@ -1,9 +0,0 @@ -extern void assert_config_entry_existence( - git_repository *repo, - const char *name, - bool is_supposed_to_exist); - -extern void assert_config_entry_value( - git_repository *repo, - const char *name, - const char *expected_value); diff --git a/tests-clar/config/configlevel.c b/tests-clar/config/configlevel.c deleted file mode 100644 index 1c22e8d9f..000000000 --- a/tests-clar/config/configlevel.c +++ /dev/null @@ -1,71 +0,0 @@ -#include "clar_libgit2.h" - -void test_config_configlevel__adding_the_same_level_twice_returns_EEXISTS(void) -{ - int error; - git_config *cfg; - - cl_git_pass(git_config_new(&cfg)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), - GIT_CONFIG_LEVEL_LOCAL, 0)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"), - GIT_CONFIG_LEVEL_GLOBAL, 0)); - error = git_config_add_file_ondisk(cfg, cl_fixture("config/config16"), - GIT_CONFIG_LEVEL_GLOBAL, 0); - - cl_git_fail(error); - cl_assert_equal_i(GIT_EEXISTS, error); - - git_config_free(cfg); -} - -void test_config_configlevel__can_replace_a_config_file_at_an_existing_level(void) -{ - git_config *cfg; - const char *s; - - cl_git_pass(git_config_new(&cfg)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"), - GIT_CONFIG_LEVEL_LOCAL, 1)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"), - GIT_CONFIG_LEVEL_LOCAL, 1)); - - cl_git_pass(git_config_get_string(&s, cfg, "core.stringglobal")); - cl_assert_equal_s("don't find me!", s); - - git_config_free(cfg); -} - -void test_config_configlevel__can_read_from_a_single_level_focused_file_after_parent_config_has_been_freed(void) -{ - git_config *cfg; - git_config *single_level_cfg; - const char *s; - - cl_git_pass(git_config_new(&cfg)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"), - GIT_CONFIG_LEVEL_GLOBAL, 0)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"), - GIT_CONFIG_LEVEL_LOCAL, 0)); - - cl_git_pass(git_config_open_level(&single_level_cfg, cfg, GIT_CONFIG_LEVEL_LOCAL)); - - git_config_free(cfg); - - cl_git_pass(git_config_get_string(&s, single_level_cfg, "core.stringglobal")); - cl_assert_equal_s("don't find me!", s); - - git_config_free(single_level_cfg); -} - -void test_config_configlevel__fetching_a_level_from_an_empty_compound_config_returns_ENOTFOUND(void) -{ - git_config *cfg; - git_config *local_cfg; - - cl_git_pass(git_config_new(&cfg)); - - cl_assert_equal_i(GIT_ENOTFOUND, git_config_open_level(&local_cfg, cfg, GIT_CONFIG_LEVEL_LOCAL)); - - git_config_free(cfg); -} diff --git a/tests-clar/config/global.c b/tests-clar/config/global.c deleted file mode 100644 index d5f95f504..000000000 --- a/tests-clar/config/global.c +++ /dev/null @@ -1,72 +0,0 @@ -#include "clar_libgit2.h" -#include "buffer.h" -#include "fileops.h" - -void test_config_global__initialize(void) -{ - git_buf path = GIT_BUF_INIT; - - cl_assert_equal_i(0, p_mkdir("home", 0777)); - cl_git_pass(git_path_prettify(&path, "home", NULL)); - cl_git_pass(git_libgit2_opts( - GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); - - cl_assert_equal_i(0, p_mkdir("xdg", 0777)); - cl_assert_equal_i(0, p_mkdir("xdg/git", 0777)); - cl_git_pass(git_path_prettify(&path, "xdg/git", NULL)); - cl_git_pass(git_libgit2_opts( - GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr)); - - cl_assert_equal_i(0, p_mkdir("etc", 0777)); - cl_git_pass(git_path_prettify(&path, "etc", NULL)); - cl_git_pass(git_libgit2_opts( - GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr)); - - git_buf_free(&path); -} - -void test_config_global__cleanup(void) -{ - cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES)); - cl_git_pass(git_futils_rmdir_r("xdg", NULL, GIT_RMDIR_REMOVE_FILES)); - cl_git_pass(git_futils_rmdir_r("etc", NULL, GIT_RMDIR_REMOVE_FILES)); - - git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, NULL); - git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, NULL); - git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, NULL); -} - -void test_config_global__open_global(void) -{ - git_config *cfg, *global, *selected, *dummy; - - cl_git_pass(git_config_open_default(&cfg)); - cl_git_pass(git_config_open_level(&global, cfg, GIT_CONFIG_LEVEL_GLOBAL)); - cl_git_fail(git_config_open_level(&dummy, cfg, GIT_CONFIG_LEVEL_XDG)); - cl_git_pass(git_config_open_global(&selected, cfg)); - - git_config_free(selected); - git_config_free(global); - git_config_free(cfg); -} - -void test_config_global__open_xdg(void) -{ - git_config *cfg, *xdg, *selected; - const char *val, *str = "teststring"; - const char *key = "this.variable"; - - cl_git_mkfile("xdg/git/config", "# XDG config\n[core]\n test = 1\n"); - - cl_git_pass(git_config_open_default(&cfg)); - cl_git_pass(git_config_open_level(&xdg, cfg, GIT_CONFIG_LEVEL_XDG)); - cl_git_pass(git_config_open_global(&selected, cfg)); - - cl_git_pass(git_config_set_string(xdg, key, str)); - cl_git_pass(git_config_get_string(&val, selected, key)); - cl_assert_equal_s(str, val); - - git_config_free(selected); - git_config_free(xdg); - git_config_free(cfg); -} diff --git a/tests-clar/config/include.c b/tests-clar/config/include.c deleted file mode 100644 index 535573808..000000000 --- a/tests-clar/config/include.c +++ /dev/null @@ -1,109 +0,0 @@ -#include "clar_libgit2.h" -#include "buffer.h" -#include "fileops.h" - -void test_config_include__relative(void) -{ - git_config *cfg; - const char *str; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config-include"))); - - cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz")); - cl_assert_equal_s(str, "huzzah"); - - git_config_free(cfg); -} - -void test_config_include__absolute(void) -{ - git_config *cfg; - const char *str; - 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)); - git_buf_free(&buf); - cl_git_pass(git_config_open_ondisk(&cfg, "config-include-absolute")); - - cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz")); - cl_assert_equal_s(str, "huzzah"); - - git_config_free(cfg); -} - -void test_config_include__homedir(void) -{ - git_config *cfg; - const char *str; - - 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"); - - cl_git_pass(git_config_open_ondisk(&cfg, "config-include-homedir")); - - cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz")); - cl_assert_equal_s(str, "huzzah"); - - git_config_free(cfg); -} - -void test_config_include__refresh(void) -{ - git_config *cfg; - const char *str; - - cl_fixture_sandbox("config"); - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config-include")); - - cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz")); - cl_assert_equal_s(str, "huzzah"); - - /* Change the included file and see if we refresh */ - cl_git_mkfile("config/config-included", "[foo \"bar\"]\nbaz = hurrah"); - cl_git_pass(git_config_refresh(cfg)); - - cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz")); - cl_assert_equal_s(str, "hurrah"); - - git_config_free(cfg); - cl_fixture_cleanup("config"); -} - -/* We need to pretend that the variables were defined where the file was included */ -void test_config_include__ordering(void) -{ - git_config *cfg; - const char *str; - - cl_git_mkfile("included", "[foo \"bar\"]\nbaz = hurrah\nfrotz = hiya"); - cl_git_mkfile("including", - "[foo \"bar\"]\nfrotz = hello\n" - "[include]\npath = included\n" - "[foo \"bar\"]\nbaz = huzzah\n"); - - cl_git_pass(git_config_open_ondisk(&cfg, "including")); - - cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.frotz")); - cl_assert_equal_s(str, "hiya"); - cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz")); - cl_assert_equal_s(str, "huzzah"); - - 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"); - - cl_git_fail(git_config_open_ondisk(&cfg, "a")); - - unlink("a"); - unlink("b"); -} diff --git a/tests-clar/config/multivar.c b/tests-clar/config/multivar.c deleted file mode 100644 index afdb1e5f4..000000000 --- a/tests-clar/config/multivar.c +++ /dev/null @@ -1,288 +0,0 @@ -#include "clar_libgit2.h" - -static const char *_name = "remote.ab.url"; - -void test_config_multivar__initialize(void) -{ - cl_fixture_sandbox("config"); -} - -void test_config_multivar__cleanup(void) -{ - cl_fixture_cleanup("config"); -} - -static int mv_read_cb(const git_config_entry *entry, void *data) -{ - int *n = (int *) data; - - if (!strcmp(entry->name, _name)) - (*n)++; - - return 0; -} - -void test_config_multivar__foreach(void) -{ - git_config *cfg; - int n = 0; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config11"))); - - cl_git_pass(git_config_foreach(cfg, mv_read_cb, &n)); - cl_assert(n == 2); - - git_config_free(cfg); -} - -static int cb(const git_config_entry *entry, void *data) -{ - int *n = (int *) data; - - GIT_UNUSED(entry); - - (*n)++; - - return 0; -} - -static void check_get_multivar_foreach( - git_config *cfg, int expected, int expected_patterned) -{ - int n = 0; - - if (expected > 0) { - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n)); - cl_assert_equal_i(expected, n); - } else { - cl_assert_equal_i(GIT_ENOTFOUND, - git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n)); - } - - n = 0; - - if (expected_patterned > 0) { - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "example", cb, &n)); - cl_assert_equal_i(expected_patterned, n); - } else { - cl_assert_equal_i(GIT_ENOTFOUND, - git_config_get_multivar_foreach(cfg, _name, "example", cb, &n)); - } -} - -static void check_get_multivar(git_config *cfg, int expected) -{ - git_config_iterator *iter; - git_config_entry *entry; - int n = 0; - - cl_git_pass(git_config_multivar_iterator_new(&iter, cfg, _name, NULL)); - - while (git_config_next(&entry, iter) == 0) - n++; - - cl_assert_equal_i(expected, n); - git_config_iterator_free(iter); - -} - -void test_config_multivar__get(void) -{ - git_config *cfg; - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); - check_get_multivar_foreach(cfg, 2, 1); - - /* add another that has the _name entry */ - cl_git_pass(git_config_add_file_ondisk(cfg, "config/config9", GIT_CONFIG_LEVEL_SYSTEM, 1)); - check_get_multivar_foreach(cfg, 3, 2); - - /* add another that does not have the _name entry */ - cl_git_pass(git_config_add_file_ondisk(cfg, "config/config0", GIT_CONFIG_LEVEL_GLOBAL, 1)); - check_get_multivar_foreach(cfg, 3, 2); - - /* add another that does not have the _name entry at the end */ - cl_git_pass(git_config_add_file_ondisk(cfg, "config/config1", GIT_CONFIG_LEVEL_APP, 1)); - check_get_multivar_foreach(cfg, 3, 2); - - /* drop original file */ - cl_git_pass(git_config_add_file_ondisk(cfg, "config/config2", GIT_CONFIG_LEVEL_LOCAL, 1)); - check_get_multivar_foreach(cfg, 1, 1); - - /* drop other file with match */ - cl_git_pass(git_config_add_file_ondisk(cfg, "config/config3", GIT_CONFIG_LEVEL_SYSTEM, 1)); - check_get_multivar_foreach(cfg, 0, 0); - - /* reload original file (add different place in order) */ - cl_git_pass(git_config_add_file_ondisk(cfg, "config/config11", GIT_CONFIG_LEVEL_SYSTEM, 1)); - check_get_multivar_foreach(cfg, 2, 1); - - check_get_multivar(cfg, 2); - - git_config_free(cfg); -} - -void test_config_multivar__add(void) -{ - git_config *cfg; - int n; - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); - cl_git_pass(git_config_set_multivar(cfg, _name, "nonexistant", "git://git.otherplace.org/libgit2")); - - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n)); - cl_assert_equal_i(n, 3); - - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "otherplace", cb, &n)); - cl_assert_equal_i(n, 1); - - git_config_free(cfg); - - /* We know it works in memory, let's see if the file is written correctly */ - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); - - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n)); - cl_assert_equal_i(n, 3); - - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "otherplace", cb, &n)); - cl_assert_equal_i(n, 1); - - git_config_free(cfg); -} - -void test_config_multivar__add_new(void) -{ - const char *var = "a.brand.new"; - git_config *cfg; - int n; - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); - - cl_git_pass(git_config_set_multivar(cfg, var, "", "variable")); - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, var, NULL, cb, &n)); - cl_assert_equal_i(n, 1); - - git_config_free(cfg); -} - -void test_config_multivar__replace(void) -{ - git_config *cfg; - int n; - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); - - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n)); - cl_assert(n == 2); - - cl_git_pass(git_config_set_multivar(cfg, _name, "github", "git://git.otherplace.org/libgit2")); - - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n)); - cl_assert(n == 2); - - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); - - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n)); - cl_assert(n == 2); - - git_config_free(cfg); -} - -void test_config_multivar__replace_multiple(void) -{ - git_config *cfg; - int n; - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); - cl_git_pass(git_config_set_multivar(cfg, _name, "git://", "git://git.otherplace.org/libgit2")); - - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "otherplace", cb, &n)); - cl_assert_equal_i(n, 2); - - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); - - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, "otherplace", cb, &n)); - cl_assert_equal_i(n, 2); - - git_config_free(cfg); -} - -void test_config_multivar__delete(void) -{ - git_config *cfg; - int n; - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); - - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n)); - cl_assert(n == 2); - - cl_git_pass(git_config_delete_multivar(cfg, _name, "github")); - - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n)); - cl_assert(n == 1); - - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); - - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n)); - cl_assert(n == 1); - - git_config_free(cfg); -} - -void test_config_multivar__delete_multiple(void) -{ - git_config *cfg; - int n; - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); - - n = 0; - cl_git_pass(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n)); - cl_assert(n == 2); - - cl_git_pass(git_config_delete_multivar(cfg, _name, "git")); - - n = 0; - cl_git_fail_with(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n), GIT_ENOTFOUND); - - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); - - n = 0; - cl_git_fail_with(git_config_get_multivar_foreach(cfg, _name, NULL, cb, &n), GIT_ENOTFOUND); - - git_config_free(cfg); -} - -void test_config_multivar__delete_notfound(void) -{ - git_config *cfg; - - cl_git_pass(git_config_open_ondisk(&cfg, "config/config11")); - - cl_git_fail_with(git_config_delete_multivar(cfg, "remote.ab.noturl", "git"), GIT_ENOTFOUND); - - git_config_free(cfg); -} diff --git a/tests-clar/config/new.c b/tests-clar/config/new.c deleted file mode 100644 index dd6dbca9e..000000000 --- a/tests-clar/config/new.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "clar_libgit2.h" - -#include "filebuf.h" -#include "fileops.h" -#include "posix.h" - -#define TEST_CONFIG "git-new-config" - -void test_config_new__write_new_config(void) -{ - const char *out; - git_config *config; - - cl_git_mkfile(TEST_CONFIG, ""); - cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); - - cl_git_pass(git_config_set_string(config, "color.ui", "auto")); - cl_git_pass(git_config_set_string(config, "core.editor", "ed")); - - git_config_free(config); - - cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); - - cl_git_pass(git_config_get_string(&out, config, "color.ui")); - cl_assert_equal_s(out, "auto"); - cl_git_pass(git_config_get_string(&out, config, "core.editor")); - cl_assert_equal_s(out, "ed"); - - git_config_free(config); - - p_unlink(TEST_CONFIG); -} diff --git a/tests-clar/config/read.c b/tests-clar/config/read.c deleted file mode 100644 index abc088d59..000000000 --- a/tests-clar/config/read.c +++ /dev/null @@ -1,569 +0,0 @@ -#include "clar_libgit2.h" - -void test_config_read__simple_read(void) -{ - git_config *cfg; - int32_t i; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config0"))); - - cl_git_pass(git_config_get_int32(&i, cfg, "core.repositoryformatversion")); - cl_assert(i == 0); - cl_git_pass(git_config_get_bool(&i, cfg, "core.filemode")); - cl_assert(i == 1); - cl_git_pass(git_config_get_bool(&i, cfg, "core.bare")); - cl_assert(i == 0); - cl_git_pass(git_config_get_bool(&i, cfg, "core.logallrefupdates")); - cl_assert(i == 1); - - git_config_free(cfg); -} - -void test_config_read__case_sensitive(void) -{ - git_config *cfg; - int i; - const char *str; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config1"))); - - cl_git_pass(git_config_get_string(&str, cfg, "this.that.other")); - cl_assert_equal_s(str, "true"); - cl_git_pass(git_config_get_string(&str, cfg, "this.That.other")); - cl_assert_equal_s(str, "yes"); - - cl_git_pass(git_config_get_bool(&i, cfg, "this.that.other")); - cl_assert(i == 1); - cl_git_pass(git_config_get_bool(&i, cfg, "this.That.other")); - cl_assert(i == 1); - - /* This one doesn't exist */ - cl_must_fail(git_config_get_bool(&i, cfg, "this.thaT.other")); - - git_config_free(cfg); -} - -/* - * If \ is the last non-space character on the line, we read the next - * one, separating each line with SP. - */ -void test_config_read__multiline_value(void) -{ - git_config *cfg; - const char *str; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config2"))); - - cl_git_pass(git_config_get_string(&str, cfg, "this.That.and")); - cl_assert_equal_s(str, "one one one two two three three"); - - git_config_free(cfg); -} - -/* - * This kind of subsection declaration is case-insensitive - */ -void test_config_read__subsection_header(void) -{ - git_config *cfg; - const char *str; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config3"))); - - cl_git_pass(git_config_get_string(&str, cfg, "section.subsection.var")); - cl_assert_equal_s(str, "hello"); - - /* The subsection is transformed to lower-case */ - cl_must_fail(git_config_get_string(&str, cfg, "section.subSectIon.var")); - - git_config_free(cfg); -} - -void test_config_read__lone_variable(void) -{ - git_config *cfg; - const char *str; - int i; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config4"))); - - cl_git_fail(git_config_get_int32(&i, cfg, "some.section.variable")); - - cl_git_pass(git_config_get_string(&str, cfg, "some.section.variable")); - cl_assert_equal_s(str, ""); - - cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variable")); - cl_assert(i == 1); - - cl_git_pass(git_config_get_string(&str, cfg, "some.section.variableeq")); - cl_assert_equal_s(str, ""); - - cl_git_pass(git_config_get_bool(&i, cfg, "some.section.variableeq")); - cl_assert(i == 0); - - git_config_free(cfg); -} - -void test_config_read__number_suffixes(void) -{ - git_config *cfg; - int64_t i; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config5"))); - - cl_git_pass(git_config_get_int64(&i, cfg, "number.simple")); - cl_assert(i == 1); - - cl_git_pass(git_config_get_int64(&i, cfg, "number.k")); - cl_assert(i == 1 * 1024); - - cl_git_pass(git_config_get_int64(&i, cfg, "number.kk")); - cl_assert(i == 1 * 1024); - - cl_git_pass(git_config_get_int64(&i, cfg, "number.m")); - cl_assert(i == 1 * 1024 * 1024); - - cl_git_pass(git_config_get_int64(&i, cfg, "number.mm")); - cl_assert(i == 1 * 1024 * 1024); - - cl_git_pass(git_config_get_int64(&i, cfg, "number.g")); - cl_assert(i == 1 * 1024 * 1024 * 1024); - - cl_git_pass(git_config_get_int64(&i, cfg, "number.gg")); - cl_assert(i == 1 * 1024 * 1024 * 1024); - - git_config_free(cfg); -} - -void test_config_read__blank_lines(void) -{ - git_config *cfg; - int i; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config6"))); - - cl_git_pass(git_config_get_bool(&i, cfg, "valid.subsection.something")); - cl_assert(i == 1); - - cl_git_pass(git_config_get_bool(&i, cfg, "something.else.something")); - cl_assert(i == 0); - - git_config_free(cfg); -} - -void test_config_read__invalid_ext_headers(void) -{ - git_config *cfg; - cl_must_fail(git_config_open_ondisk(&cfg, cl_fixture("config/config7"))); -} - -void test_config_read__empty_files(void) -{ - git_config *cfg; - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config8"))); - git_config_free(cfg); -} - -void test_config_read__symbol_headers(void) -{ - git_config *cfg; - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config20"))); - git_config_free(cfg); -} - -void test_config_read__header_in_last_line(void) -{ - git_config *cfg; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config10"))); - git_config_free(cfg); -} - -void test_config_read__prefixes(void) -{ - git_config *cfg; - const char *str; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9"))); - cl_git_pass(git_config_get_string(&str, cfg, "remote.ab.url")); - cl_assert_equal_s(str, "http://example.com/git/ab"); - - cl_git_pass(git_config_get_string(&str, cfg, "remote.abba.url")); - cl_assert_equal_s(str, "http://example.com/git/abba"); - - git_config_free(cfg); -} - -void test_config_read__escaping_quotes(void) -{ - git_config *cfg; - const char *str; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config13"))); - cl_git_pass(git_config_get_string(&str, cfg, "core.editor")); - cl_assert_equal_s("\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"", str); - - git_config_free(cfg); -} - -static int count_cfg_entries_and_compare_levels( - const git_config_entry *entry, void *payload) -{ - int *count = payload; - - if (!strcmp(entry->value, "7") || !strcmp(entry->value, "17")) - cl_assert(entry->level == GIT_CONFIG_LEVEL_GLOBAL); - else - cl_assert(entry->level == GIT_CONFIG_LEVEL_SYSTEM); - - (*count)++; - return 0; -} - -static int cfg_callback_countdown(const git_config_entry *entry, void *payload) -{ - int *count = payload; - GIT_UNUSED(entry); - (*count)--; - if (*count == 0) - return -100; - return 0; -} - -void test_config_read__foreach(void) -{ - git_config *cfg; - int count, ret; - - cl_git_pass(git_config_new(&cfg)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), - GIT_CONFIG_LEVEL_SYSTEM, 0)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"), - GIT_CONFIG_LEVEL_GLOBAL, 0)); - - count = 0; - cl_git_pass(git_config_foreach(cfg, count_cfg_entries_and_compare_levels, &count)); - cl_assert_equal_i(7, count); - - count = 3; - cl_git_fail(ret = git_config_foreach(cfg, cfg_callback_countdown, &count)); - cl_assert_equal_i(GIT_EUSER, ret); - - git_config_free(cfg); -} - -void test_config_read__iterator(void) -{ - git_config *cfg; - git_config_iterator *iter; - git_config_entry *entry; - int count, ret; - - cl_git_pass(git_config_new(&cfg)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), - GIT_CONFIG_LEVEL_SYSTEM, 0)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"), - GIT_CONFIG_LEVEL_GLOBAL, 0)); - - count = 0; - cl_git_pass(git_config_iterator_new(&iter, cfg)); - - while ((ret = git_config_next(&entry, iter)) == 0) { - count++; - } - - git_config_iterator_free(iter); - cl_assert_equal_i(GIT_ITEROVER, ret); - cl_assert_equal_i(7, count); - - count = 3; - cl_git_pass(git_config_iterator_new(&iter, cfg)); - - git_config_iterator_free(iter); - git_config_free(cfg); -} - -static int count_cfg_entries(const git_config_entry *entry, void *payload) -{ - int *count = payload; - GIT_UNUSED(entry); - (*count)++; - return 0; -} - -void test_config_read__foreach_match(void) -{ - git_config *cfg; - int count; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9"))); - - count = 0; - cl_git_pass( - git_config_foreach_match(cfg, "core.*", count_cfg_entries, &count)); - cl_assert_equal_i(3, count); - - count = 0; - cl_git_pass( - git_config_foreach_match(cfg, "remote\\.ab.*", count_cfg_entries, &count)); - cl_assert_equal_i(2, count); - - count = 0; - cl_git_pass( - git_config_foreach_match(cfg, ".*url$", count_cfg_entries, &count)); - cl_assert_equal_i(2, count); - - count = 0; - cl_git_pass( - git_config_foreach_match(cfg, ".*dummy.*", count_cfg_entries, &count)); - cl_assert_equal_i(2, count); - - count = 0; - cl_git_pass( - git_config_foreach_match(cfg, ".*nomatch.*", count_cfg_entries, &count)); - cl_assert_equal_i(0, count); - - git_config_free(cfg); -} - -static void check_glob_iter(git_config *cfg, const char *regexp, int expected) -{ - git_config_iterator *iter; - git_config_entry *entry; - int count, error; - - cl_git_pass(git_config_iterator_glob_new(&iter, cfg, regexp)); - - count = 0; - while ((error = git_config_next(&entry, iter)) == 0) - count++; - - cl_assert_equal_i(GIT_ITEROVER, error); - cl_assert_equal_i(expected, count); - git_config_iterator_free(iter); -} - -void test_config_read__iterator_glob(void) -{ - git_config *cfg; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9"))); - - check_glob_iter(cfg, "core.*", 3); - check_glob_iter(cfg, "remote\\.ab.*", 2); - check_glob_iter(cfg, ".*url$", 2); - check_glob_iter(cfg, ".*dummy.*", 2); - check_glob_iter(cfg, ".*nomatch.*", 0); - - git_config_free(cfg); -} - -void test_config_read__whitespace_not_required_around_assignment(void) -{ - git_config *cfg; - const char *str; - - cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config14"))); - - cl_git_pass(git_config_get_string(&str, cfg, "a.b")); - cl_assert_equal_s(str, "c"); - - cl_git_pass(git_config_get_string(&str, cfg, "d.e")); - cl_assert_equal_s(str, "f"); - - git_config_free(cfg); -} - -void test_config_read__read_git_config_entry(void) -{ - git_config *cfg; - const git_config_entry *entry; - - cl_git_pass(git_config_new(&cfg)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), - GIT_CONFIG_LEVEL_SYSTEM, 0)); - - cl_git_pass(git_config_get_entry(&entry, cfg, "core.dummy2")); - cl_assert_equal_s("core.dummy2", entry->name); - cl_assert_equal_s("42", entry->value); - cl_assert_equal_i(GIT_CONFIG_LEVEL_SYSTEM, entry->level); - - git_config_free(cfg); -} - -/* - * At the beginning of the test: - * - config9 has: core.dummy2=42 - * - config15 has: core.dummy2=7 - * - config16 has: core.dummy2=28 - */ -void test_config_read__local_config_overrides_global_config_overrides_system_config(void) -{ - git_config *cfg; - int32_t i; - - cl_git_pass(git_config_new(&cfg)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), - GIT_CONFIG_LEVEL_SYSTEM, 0)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"), - GIT_CONFIG_LEVEL_GLOBAL, 0)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config16"), - GIT_CONFIG_LEVEL_LOCAL, 0)); - - cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2")); - cl_assert_equal_i(28, i); - - git_config_free(cfg); - - cl_git_pass(git_config_new(&cfg)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), - GIT_CONFIG_LEVEL_SYSTEM, 0)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"), - GIT_CONFIG_LEVEL_GLOBAL, 0)); - - cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2")); - cl_assert_equal_i(7, i); - - git_config_free(cfg); -} - -/* - * At the beginning of the test: - * - config9 has: core.global does not exist - * - config15 has: core.global=17 - * - config16 has: core.global=29 - * - * And also: - * - config9 has: core.system does not exist - * - config15 has: core.system does not exist - * - config16 has: core.system=11 - */ -void test_config_read__fallback_from_local_to_global_and_from_global_to_system(void) -{ - git_config *cfg; - int32_t i; - - cl_git_pass(git_config_new(&cfg)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), - GIT_CONFIG_LEVEL_SYSTEM, 0)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"), - GIT_CONFIG_LEVEL_GLOBAL, 0)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config16"), - GIT_CONFIG_LEVEL_LOCAL, 0)); - - cl_git_pass(git_config_get_int32(&i, cfg, "core.global")); - cl_assert_equal_i(17, i); - cl_git_pass(git_config_get_int32(&i, cfg, "core.system")); - cl_assert_equal_i(11, i); - - git_config_free(cfg); -} - -/* - * At the beginning of the test, config18 has: - * int32global = 28 - * int64global = 9223372036854775803 - * boolglobal = true - * stringglobal = I'm a global config value! - * - * And config19 has: - * int32global = -1 - * int64global = -2 - * boolglobal = false - * stringglobal = don't find me! - * - */ -void test_config_read__simple_read_from_specific_level(void) -{ - git_config *cfg, *cfg_specific; - int i; - int64_t l, expected = +9223372036854775803; - const char *s; - - cl_git_pass(git_config_new(&cfg)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"), - GIT_CONFIG_LEVEL_GLOBAL, 0)); - cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"), - GIT_CONFIG_LEVEL_SYSTEM, 0)); - - cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL)); - - cl_git_pass(git_config_get_int32(&i, cfg_specific, "core.int32global")); - cl_assert_equal_i(28, i); - cl_git_pass(git_config_get_int64(&l, cfg_specific, "core.int64global")); - cl_assert(l == expected); - cl_git_pass(git_config_get_bool(&i, cfg_specific, "core.boolglobal")); - cl_assert_equal_b(true, i); - cl_git_pass(git_config_get_string(&s, cfg_specific, "core.stringglobal")); - cl_assert_equal_s("I'm a global config value!", s); - - git_config_free(cfg_specific); - git_config_free(cfg); -} - -static void clean_test_config(void *unused) -{ - GIT_UNUSED(unused); - cl_fixture_cleanup("./testconfig"); -} - -void test_config_read__can_load_and_parse_an_empty_config_file(void) -{ - git_config *cfg; - int i; - - cl_set_cleanup(&clean_test_config, NULL); - cl_git_mkfile("./testconfig", ""); - cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig")); - cl_assert_equal_i(GIT_ENOTFOUND, git_config_get_int32(&i, cfg, "nope.neither")); - - git_config_free(cfg); -} - -void test_config_read__corrupt_header(void) -{ - git_config *cfg; - - cl_set_cleanup(&clean_test_config, NULL); - cl_git_mkfile("./testconfig", "[sneaky ] \"quoted closing quote mark\\\""); - cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig")); - - git_config_free(cfg); -} - -void test_config_read__corrupt_header2(void) -{ - git_config *cfg; - - cl_set_cleanup(&clean_test_config, NULL); - cl_git_mkfile("./testconfig", "[unclosed \"bracket\"\n lib = git2\n"); - cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig")); - - git_config_free(cfg); -} - -void test_config_read__corrupt_header3(void) -{ - git_config *cfg; - - cl_set_cleanup(&clean_test_config, NULL); - cl_git_mkfile("./testconfig", "[unclosed \"slash\\\"]\n lib = git2\n"); - cl_git_fail(git_config_open_ondisk(&cfg, "./testconfig")); - - git_config_free(cfg); -} - -void test_config_read__override_variable(void) -{ - git_config *cfg; - const char *str; - - cl_set_cleanup(&clean_test_config, NULL); - cl_git_mkfile("./testconfig", "[some] var = one\nvar = two"); - cl_git_pass(git_config_open_ondisk(&cfg, "./testconfig")); - - cl_git_pass(git_config_get_string(&str, cfg, "some.var")); - cl_assert_equal_s(str, "two"); - - git_config_free(cfg); -} diff --git a/tests-clar/config/refresh.c b/tests-clar/config/refresh.c deleted file mode 100644 index 99d677f0e..000000000 --- a/tests-clar/config/refresh.c +++ /dev/null @@ -1,67 +0,0 @@ -#include "clar_libgit2.h" - -#define TEST_FILE "config.refresh" - -void test_config_refresh__initialize(void) -{ -} - -void test_config_refresh__cleanup(void) -{ - cl_fixture_cleanup(TEST_FILE); -} - -void test_config_refresh__update_value(void) -{ - git_config *cfg; - int32_t v; - - cl_git_mkfile(TEST_FILE, "[section]\n\tvalue = 1\n\n"); - - /* By freeing the config, we make sure we flush the values */ - cl_git_pass(git_config_open_ondisk(&cfg, TEST_FILE)); - - cl_git_pass(git_config_get_int32(&v, cfg, "section.value")); - cl_assert_equal_i(1, v); - - cl_git_rewritefile(TEST_FILE, "[section]\n\tvalue = 10\n\n"); - - cl_git_pass(git_config_get_int32(&v, cfg, "section.value")); - cl_assert_equal_i(1, v); - - cl_git_pass(git_config_refresh(cfg)); - - cl_git_pass(git_config_get_int32(&v, cfg, "section.value")); - cl_assert_equal_i(10, v); - - git_config_free(cfg); -} - -void test_config_refresh__delete_value(void) -{ - git_config *cfg; - int32_t v; - - cl_git_mkfile(TEST_FILE, "[section]\n\tvalue = 1\n\n"); - - /* By freeing the config, we make sure we flush the values */ - cl_git_pass(git_config_open_ondisk(&cfg, TEST_FILE)); - - cl_git_pass(git_config_get_int32(&v, cfg, "section.value")); - cl_assert_equal_i(1, v); - cl_git_fail(git_config_get_int32(&v, cfg, "section.newval")); - - cl_git_rewritefile(TEST_FILE, "[section]\n\tnewval = 10\n\n"); - - cl_git_pass(git_config_get_int32(&v, cfg, "section.value")); - cl_assert_equal_i(1, v); - cl_git_fail(git_config_get_int32(&v, cfg, "section.newval")); - - cl_git_pass(git_config_refresh(cfg)); - - cl_git_fail(git_config_get_int32(&v, cfg, "section.value")); - cl_git_pass(git_config_get_int32(&v, cfg, "section.newval")); - cl_assert_equal_i(10, v); - - git_config_free(cfg); -} diff --git a/tests-clar/config/stress.c b/tests-clar/config/stress.c deleted file mode 100644 index eeca54ff4..000000000 --- a/tests-clar/config/stress.c +++ /dev/null @@ -1,92 +0,0 @@ -#include "clar_libgit2.h" - -#include "filebuf.h" -#include "fileops.h" -#include "posix.h" - -#define TEST_CONFIG "git-test-config" - -void test_config_stress__initialize(void) -{ - git_filebuf file = GIT_FILEBUF_INIT; - - cl_git_pass(git_filebuf_open(&file, TEST_CONFIG, 0, 0666)); - - git_filebuf_printf(&file, "[color]\n\tui = auto\n"); - git_filebuf_printf(&file, "[core]\n\teditor = \n"); - - cl_git_pass(git_filebuf_commit(&file)); -} - -void test_config_stress__cleanup(void) -{ - p_unlink(TEST_CONFIG); -} - -void test_config_stress__dont_break_on_invalid_input(void) -{ - const char *editor, *color; - git_config *config; - - cl_assert(git_path_exists(TEST_CONFIG)); - cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); - - cl_git_pass(git_config_get_string(&color, config, "color.ui")); - cl_git_pass(git_config_get_string(&editor, config, "core.editor")); - - git_config_free(config); -} - -void test_config_stress__comments(void) -{ - git_config *config; - const char *str; - - cl_git_pass(git_config_open_ondisk(&config, cl_fixture("config/config12"))); - - cl_git_pass(git_config_get_string(&str, config, "some.section.other")); - cl_assert_equal_s("hello! \" ; ; ; ", str); - - cl_git_pass(git_config_get_string(&str, config, "some.section.multi")); - cl_assert_equal_s("hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#", str); - - cl_git_pass(git_config_get_string(&str, config, "some.section.back")); - cl_assert_equal_s("this is \ba phrase", str); - - git_config_free(config); -} - -void test_config_stress__escape_subsection_names(void) -{ - git_config *config; - const char *str; - - cl_assert(git_path_exists("git-test-config")); - cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); - - cl_git_pass(git_config_set_string(config, "some.sec\\tion.other", "foo")); - git_config_free(config); - - cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); - - cl_git_pass(git_config_get_string(&str, config, "some.sec\\tion.other")); - cl_assert_equal_s("foo", str); - git_config_free(config); -} - -void test_config_stress__trailing_backslash(void) -{ - git_config *config; - const char *str; - const char *path = "C:\\iam\\some\\windows\\path\\"; - - cl_assert(git_path_exists("git-test-config")); - cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); - cl_git_pass(git_config_set_string(config, "windows.path", path)); - git_config_free(config); - - cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG)); - cl_git_pass(git_config_get_string(&str, config, "windows.path")); - cl_assert_equal_s(path, str); - git_config_free(config); -} diff --git a/tests-clar/config/validkeyname.c b/tests-clar/config/validkeyname.c deleted file mode 100644 index 33699737b..000000000 --- a/tests-clar/config/validkeyname.c +++ /dev/null @@ -1,68 +0,0 @@ -#include "clar_libgit2.h" - -#include "config.h" - -static git_config *cfg; -static const char *value; - -void test_config_validkeyname__initialize(void) -{ - cl_fixture_sandbox("config/config10"); - - cl_git_pass(git_config_open_ondisk(&cfg, "config10")); -} - -void test_config_validkeyname__cleanup(void) -{ - git_config_free(cfg); - cfg = NULL; - - cl_fixture_cleanup("config10"); -} - -static void assert_invalid_config_key_name(const char *name) -{ - cl_git_fail_with(git_config_get_string(&value, cfg, name), - GIT_EINVALIDSPEC); - cl_git_fail_with(git_config_set_string(cfg, name, "42"), - GIT_EINVALIDSPEC); - cl_git_fail_with(git_config_delete_entry(cfg, name), - GIT_EINVALIDSPEC); - cl_git_fail_with(git_config_get_multivar_foreach(cfg, name, "*", NULL, NULL), - GIT_EINVALIDSPEC); - cl_git_fail_with(git_config_set_multivar(cfg, name, "*", "42"), - GIT_EINVALIDSPEC); -} - -void test_config_validkeyname__accessing_requires_a_valid_name(void) -{ - assert_invalid_config_key_name(""); - assert_invalid_config_key_name("."); - assert_invalid_config_key_name(".."); - assert_invalid_config_key_name("core."); - assert_invalid_config_key_name("d#ff.dirstat.lines"); - assert_invalid_config_key_name("diff.dirstat.lines#"); - assert_invalid_config_key_name("dif\nf.dirstat.lines"); - assert_invalid_config_key_name("dif.dir\nstat.lines"); - assert_invalid_config_key_name("dif.dirstat.li\nes"); -} - -static void assert_invalid_config_section_name(git_repository *repo, const char *name) -{ - cl_git_fail_with(git_config_rename_section(repo, "branch.remoteless", name), GIT_EINVALIDSPEC); -} - -void test_config_validkeyname__renaming_a_section_requires_a_valid_name(void) -{ - git_repository *repo; - - cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); - - assert_invalid_config_section_name(repo, ""); - assert_invalid_config_section_name(repo, "bra\nch"); - assert_invalid_config_section_name(repo, "branc#"); - assert_invalid_config_section_name(repo, "bra\nch.duh"); - assert_invalid_config_section_name(repo, "branc#.duh"); - - git_repository_free(repo); -} diff --git a/tests-clar/config/write.c b/tests-clar/config/write.c deleted file mode 100644 index 15f750dc0..000000000 --- a/tests-clar/config/write.c +++ /dev/null @@ -1,305 +0,0 @@ -#include "clar_libgit2.h" - -void test_config_write__initialize(void) -{ - cl_fixture_sandbox("config/config9"); - cl_fixture_sandbox("config/config15"); - cl_fixture_sandbox("config/config17"); -} - -void test_config_write__cleanup(void) -{ - cl_fixture_cleanup("config9"); - cl_fixture_cleanup("config15"); - cl_fixture_cleanup("config17"); -} - -void test_config_write__replace_value(void) -{ - git_config *cfg; - int i; - int64_t l, expected = +9223372036854775803; - - /* By freeing the config, we make sure we flush the values */ - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_int32(cfg, "core.dummy", 5)); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy")); - cl_assert(i == 5); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_int32(cfg, "core.dummy", 1)); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_int64(cfg, "core.verylong", expected)); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_get_int64(&l, cfg, "core.verylong")); - cl_assert(l == expected); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_must_fail(git_config_get_int32(&i, cfg, "core.verylong")); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_int64(cfg, "core.verylong", 1)); - git_config_free(cfg); -} - -void test_config_write__delete_value(void) -{ - git_config *cfg; - int32_t i; - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_int32(cfg, "core.dummy", 5)); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_delete_entry(cfg, "core.dummy")); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_assert(git_config_get_int32(&i, cfg, "core.dummy") == GIT_ENOTFOUND); - cl_git_pass(git_config_set_int32(cfg, "core.dummy", 1)); - git_config_free(cfg); -} - -/* - * At the beginning of the test: - * - config9 has: core.dummy2=42 - * - config15 has: core.dummy2=7 - */ -void test_config_write__delete_value_at_specific_level(void) -{ - git_config *cfg, *cfg_specific; - int32_t i; - - cl_git_pass(git_config_open_ondisk(&cfg, "config15")); - cl_git_pass(git_config_get_int32(&i, cfg, "core.dummy2")); - cl_assert(i == 7); - git_config_free(cfg); - - cl_git_pass(git_config_new(&cfg)); - cl_git_pass(git_config_add_file_ondisk(cfg, "config9", - GIT_CONFIG_LEVEL_LOCAL, 0)); - cl_git_pass(git_config_add_file_ondisk(cfg, "config15", - GIT_CONFIG_LEVEL_GLOBAL, 0)); - - cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL)); - - cl_git_pass(git_config_delete_entry(cfg_specific, "core.dummy2")); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config15")); - cl_assert(git_config_get_int32(&i, cfg, "core.dummy2") == GIT_ENOTFOUND); - cl_git_pass(git_config_set_int32(cfg, "core.dummy2", 7)); - - git_config_free(cfg_specific); - git_config_free(cfg); -} - -void test_config_write__write_subsection(void) -{ - git_config *cfg; - const char *str; - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_string(cfg, "my.own.var", "works")); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_get_string(&str, cfg, "my.own.var")); - cl_assert_equal_s("works", str); - git_config_free(cfg); -} - -void test_config_write__delete_inexistent(void) -{ - git_config *cfg; - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_assert(git_config_delete_entry(cfg, "core.imaginary") == GIT_ENOTFOUND); - git_config_free(cfg); -} - -void test_config_write__value_containing_quotes(void) -{ - git_config *cfg; - const char* str; - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes")); - cl_git_pass(git_config_get_string(&str, cfg, "core.somevar")); - cl_assert_equal_s(str, "this \"has\" quotes"); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_get_string(&str, cfg, "core.somevar")); - cl_assert_equal_s(str, "this \"has\" quotes"); - git_config_free(cfg); - - /* The code path for values that already exist is different, check that one as well */ - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_string(cfg, "core.somevar", "this also \"has\" quotes")); - cl_git_pass(git_config_get_string(&str, cfg, "core.somevar")); - cl_assert_equal_s(str, "this also \"has\" quotes"); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_get_string(&str, cfg, "core.somevar")); - cl_assert_equal_s(str, "this also \"has\" quotes"); - git_config_free(cfg); -} - -void test_config_write__escape_value(void) -{ - git_config *cfg; - const char* str; - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_set_string(cfg, "core.somevar", "this \"has\" quotes and \t")); - cl_git_pass(git_config_get_string(&str, cfg, "core.somevar")); - cl_assert_equal_s(str, "this \"has\" quotes and \t"); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - cl_git_pass(git_config_get_string(&str, cfg, "core.somevar")); - cl_assert_equal_s(str, "this \"has\" quotes and \t"); - git_config_free(cfg); -} - -void test_config_write__add_value_at_specific_level(void) -{ - git_config *cfg, *cfg_specific; - int i; - int64_t l, expected = +9223372036854775803; - const char *s; - - // open config15 as global level config file - cl_git_pass(git_config_new(&cfg)); - cl_git_pass(git_config_add_file_ondisk(cfg, "config9", - GIT_CONFIG_LEVEL_LOCAL, 0)); - cl_git_pass(git_config_add_file_ondisk(cfg, "config15", - GIT_CONFIG_LEVEL_GLOBAL, 0)); - - cl_git_pass(git_config_open_level(&cfg_specific, cfg, GIT_CONFIG_LEVEL_GLOBAL)); - - cl_git_pass(git_config_set_int32(cfg_specific, "core.int32global", 28)); - cl_git_pass(git_config_set_int64(cfg_specific, "core.int64global", expected)); - cl_git_pass(git_config_set_bool(cfg_specific, "core.boolglobal", true)); - cl_git_pass(git_config_set_string(cfg_specific, "core.stringglobal", "I'm a global config value!")); - git_config_free(cfg_specific); - git_config_free(cfg); - - // open config15 as local level config file - cl_git_pass(git_config_open_ondisk(&cfg, "config15")); - - cl_git_pass(git_config_get_int32(&i, cfg, "core.int32global")); - cl_assert_equal_i(28, i); - cl_git_pass(git_config_get_int64(&l, cfg, "core.int64global")); - cl_assert(l == expected); - cl_git_pass(git_config_get_bool(&i, cfg, "core.boolglobal")); - cl_assert_equal_b(true, i); - cl_git_pass(git_config_get_string(&s, cfg, "core.stringglobal")); - cl_assert_equal_s("I'm a global config value!", s); - - git_config_free(cfg); -} - -void test_config_write__add_value_at_file_with_no_clrf_at_the_end(void) -{ - git_config *cfg; - int i; - - cl_git_pass(git_config_open_ondisk(&cfg, "config17")); - cl_git_pass(git_config_set_int32(cfg, "core.newline", 7)); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config17")); - cl_git_pass(git_config_get_int32(&i, cfg, "core.newline")); - cl_assert_equal_i(7, i); - - git_config_free(cfg); -} - -void test_config_write__add_value_which_needs_quotes(void) -{ - git_config *cfg; - const char* str1; - const char* str2; - const char* str3; - const char* str4; - const char* str5; - - cl_git_pass(git_config_open_ondisk(&cfg, "config17")); - cl_git_pass(git_config_set_string(cfg, "core.startwithspace", " Something")); - cl_git_pass(git_config_set_string(cfg, "core.endwithspace", "Something ")); - cl_git_pass(git_config_set_string(cfg, "core.containscommentchar1", "some#thing")); - cl_git_pass(git_config_set_string(cfg, "core.containscommentchar2", "some;thing")); - cl_git_pass(git_config_set_string(cfg, "core.startwhithsapceandcontainsdoublequote", " some\"thing")); - git_config_free(cfg); - - cl_git_pass(git_config_open_ondisk(&cfg, "config17")); - cl_git_pass(git_config_get_string(&str1, cfg, "core.startwithspace")); - cl_assert_equal_s(" Something", str1); - cl_git_pass(git_config_get_string(&str2, cfg, "core.endwithspace")); - cl_assert_equal_s("Something ", str2); - cl_git_pass(git_config_get_string(&str3, cfg, "core.containscommentchar1")); - cl_assert_equal_s("some#thing", str3); - cl_git_pass(git_config_get_string(&str4, cfg, "core.containscommentchar2")); - cl_assert_equal_s("some;thing", str4); - cl_git_pass(git_config_get_string(&str5, cfg, "core.startwhithsapceandcontainsdoublequote")); - cl_assert_equal_s(" some\"thing", str5); - git_config_free(cfg); -} - -void test_config_write__can_set_a_value_to_NULL(void) -{ - git_repository *repository; - git_config *config; - - repository = cl_git_sandbox_init("testrepo.git"); - - cl_git_pass(git_repository_config(&config, repository)); - cl_git_fail(git_config_set_string(config, "a.b.c", NULL)); - git_config_free(config); - - cl_git_sandbox_cleanup(); -} - -void test_config_write__can_set_an_empty_value(void) -{ - git_repository *repository; - git_config *config; - const char * str; - - repository = cl_git_sandbox_init("testrepo.git"); - cl_git_pass(git_repository_config(&config, repository)); - - cl_git_pass(git_config_set_string(config, "core.somevar", "")); - cl_git_pass(git_config_get_string(&str, config, "core.somevar")); - cl_assert_equal_s(str, ""); - - git_config_free(config); - cl_git_sandbox_cleanup(); -} - -void test_config_write__updating_a_locked_config_file_returns_ELOCKED(void) -{ - git_config *cfg; - - cl_git_pass(git_config_open_ondisk(&cfg, "config9")); - - cl_git_mkfile("config9.lock", "[core]\n"); - - cl_git_fail_with(git_config_set_string(cfg, "core.dump", "boom"), GIT_ELOCKED); - - git_config_free(cfg); -} |
