]> git.proxmox.com Git - libgit2.git/blob - tests/config/stress.c
Merge pull request #2771 from libgit2/cmn/config-borrow-entry
[libgit2.git] / tests / config / stress.c
1 #include "clar_libgit2.h"
2
3 #include "filebuf.h"
4 #include "fileops.h"
5 #include "posix.h"
6
7 #define TEST_CONFIG "git-test-config"
8
9 static git_buf buf = GIT_BUF_INIT;
10
11 void test_config_stress__initialize(void)
12 {
13 git_filebuf file = GIT_FILEBUF_INIT;
14
15 cl_git_pass(git_filebuf_open(&file, TEST_CONFIG, 0, 0666));
16
17 git_filebuf_printf(&file, "[color]\n\tui = auto\n");
18 git_filebuf_printf(&file, "[core]\n\teditor = \n");
19
20 cl_git_pass(git_filebuf_commit(&file));
21 }
22
23 void test_config_stress__cleanup(void)
24 {
25 git_buf_free(&buf);
26 p_unlink(TEST_CONFIG);
27 }
28
29 void test_config_stress__dont_break_on_invalid_input(void)
30 {
31 git_config *config;
32
33 cl_assert(git_path_exists(TEST_CONFIG));
34 cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
35
36 cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui"));
37 cl_git_pass(git_config_get_string_buf(&buf, config, "core.editor"));
38
39 git_config_free(config);
40 }
41
42 void assert_config_value(git_config *config, const char *key, const char *value)
43 {
44 git_buf_clear(&buf);
45 cl_git_pass(git_config_get_string_buf(&buf, config, key));
46 cl_assert_equal_s(value, git_buf_cstr(&buf));
47 }
48
49 void test_config_stress__comments(void)
50 {
51 git_config *config;
52
53 cl_git_pass(git_config_open_ondisk(&config, cl_fixture("config/config12")));
54
55 assert_config_value(config, "some.section.test2", "hello");
56 assert_config_value(config, "some.section.test3", "welcome");
57 assert_config_value(config, "some.section.other", "hello! \" ; ; ; ");
58 assert_config_value(config, "some.section.other2", "cool! \" # # # ");
59 assert_config_value(config, "some.section.multi", "hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
60 assert_config_value(config, "some.section.multi2", "good, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
61 assert_config_value(config, "some.section.back", "this is \ba phrase");
62
63 git_config_free(config);
64 }
65
66 void test_config_stress__escape_subsection_names(void)
67 {
68 git_config *config;
69
70 cl_assert(git_path_exists("git-test-config"));
71 cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
72
73 cl_git_pass(git_config_set_string(config, "some.sec\\tion.other", "foo"));
74 git_config_free(config);
75
76 cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
77
78 assert_config_value(config, "some.sec\\tion.other", "foo");
79
80 git_config_free(config);
81 }
82
83 void test_config_stress__trailing_backslash(void)
84 {
85 git_config *config;
86 const char *path = "C:\\iam\\some\\windows\\path\\";
87
88 cl_assert(git_path_exists("git-test-config"));
89 cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
90 cl_git_pass(git_config_set_string(config, "windows.path", path));
91 git_config_free(config);
92
93 cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
94 assert_config_value(config, "windows.path", path);
95
96 git_config_free(config);
97 }
98
99 void test_config_stress__complex(void)
100 {
101 git_config *config;
102 const char *path = "./config-immediate-multiline";
103
104 cl_git_mkfile(path, "[imm]\n multi = \"\\\nfoo\"");
105 cl_git_pass(git_config_open_ondisk(&config, path));
106 assert_config_value(config, "imm.multi", "foo");
107
108 git_config_free(config);
109 }