]> git.proxmox.com Git - libgit2.git/blob - tests/config/validkeyname.c
rebase: correctly finish rebasing detached heads
[libgit2.git] / tests / config / validkeyname.c
1 #include "clar_libgit2.h"
2
3 #include "config.h"
4
5 static git_config *cfg;
6
7 void test_config_validkeyname__initialize(void)
8 {
9 cl_fixture_sandbox("config/config10");
10
11 cl_git_pass(git_config_open_ondisk(&cfg, "config10"));
12 }
13
14 void test_config_validkeyname__cleanup(void)
15 {
16 git_config_free(cfg);
17 cfg = NULL;
18
19 cl_fixture_cleanup("config10");
20 }
21
22 static void assert_invalid_config_key_name(const char *name)
23 {
24 git_buf buf = GIT_BUF_INIT;
25
26 cl_git_fail_with(git_config_get_string_buf(&buf, cfg, name),
27 GIT_EINVALIDSPEC);
28 cl_git_fail_with(git_config_set_string(cfg, name, "42"),
29 GIT_EINVALIDSPEC);
30 cl_git_fail_with(git_config_delete_entry(cfg, name),
31 GIT_EINVALIDSPEC);
32 cl_git_fail_with(git_config_get_multivar_foreach(cfg, name, "*", NULL, NULL),
33 GIT_EINVALIDSPEC);
34 cl_git_fail_with(git_config_set_multivar(cfg, name, "*", "42"),
35 GIT_EINVALIDSPEC);
36 }
37
38 void test_config_validkeyname__accessing_requires_a_valid_name(void)
39 {
40 assert_invalid_config_key_name("");
41 assert_invalid_config_key_name(".");
42 assert_invalid_config_key_name("..");
43 assert_invalid_config_key_name("core.");
44 assert_invalid_config_key_name("d#ff.dirstat.lines");
45 assert_invalid_config_key_name("diff.dirstat.lines#");
46 assert_invalid_config_key_name("dif\nf.dirstat.lines");
47 assert_invalid_config_key_name("dif.dir\nstat.lines");
48 assert_invalid_config_key_name("dif.dirstat.li\nes");
49 }