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