]> git.proxmox.com Git - libgit2.git/blob - tests/config/stress.c
Merge remote-tracking branch 'upstream/master' into cmn/describe
[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.other"));
48 cl_assert_equal_s("hello! \" ; ; ; ", str);
49
50 cl_git_pass(git_config_get_string(&str, config, "some.section.multi"));
51 cl_assert_equal_s("hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#", str);
52
53 cl_git_pass(git_config_get_string(&str, config, "some.section.back"));
54 cl_assert_equal_s("this is \ba phrase", str);
55
56 git_config_free(config);
57 }
58
59 void test_config_stress__escape_subsection_names(void)
60 {
61 git_config *config;
62 const char *str;
63
64 cl_assert(git_path_exists("git-test-config"));
65 cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
66
67 cl_git_pass(git_config_set_string(config, "some.sec\\tion.other", "foo"));
68 git_config_free(config);
69
70 cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
71
72 cl_git_pass(git_config_get_string(&str, config, "some.sec\\tion.other"));
73 cl_assert_equal_s("foo", str);
74 git_config_free(config);
75 }
76
77 void test_config_stress__trailing_backslash(void)
78 {
79 git_config *config;
80 const char *str;
81 const char *path = "C:\\iam\\some\\windows\\path\\";
82
83 cl_assert(git_path_exists("git-test-config"));
84 cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
85 cl_git_pass(git_config_set_string(config, "windows.path", path));
86 git_config_free(config);
87
88 cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
89 cl_git_pass(git_config_get_string(&str, config, "windows.path"));
90 cl_assert_equal_s(path, str);
91 git_config_free(config);
92 }
93
94 void test_config_stress__complex(void)
95 {
96 git_config *config;
97 const char *str;
98 const char *path = "./config-immediate-multiline";
99
100 cl_git_mkfile(path, "[imm]\n multi = \"\\\nfoo\"");
101 cl_git_pass(git_config_open_ondisk(&config, path));
102 cl_git_pass(git_config_get_string(&str, config, "imm.multi"));
103 cl_assert_equal_s(str, "foo");
104 git_config_free(config);
105 }