Hash :
4efa3290
Author :
Date :
2013-08-08T13:41:18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#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);
}