]>
git.proxmox.com Git - libgit2.git/blob - tests/config/stress.c
1 #include "clar_libgit2.h"
7 #define TEST_CONFIG "git-test-config"
9 static git_buf buf
= GIT_BUF_INIT
;
11 void test_config_stress__initialize(void)
13 git_filebuf file
= GIT_FILEBUF_INIT
;
15 cl_git_pass(git_filebuf_open(&file
, TEST_CONFIG
, 0, 0666));
17 git_filebuf_printf(&file
, "[color]\n\tui = auto\n");
18 git_filebuf_printf(&file
, "[core]\n\teditor = \n");
20 cl_git_pass(git_filebuf_commit(&file
));
23 void test_config_stress__cleanup(void)
26 p_unlink(TEST_CONFIG
);
29 void test_config_stress__dont_break_on_invalid_input(void)
33 cl_assert(git_path_exists(TEST_CONFIG
));
34 cl_git_pass(git_config_open_ondisk(&config
, TEST_CONFIG
));
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"));
39 git_config_free(config
);
42 void assert_config_value(git_config
*config
, const char *key
, const char *value
)
45 cl_git_pass(git_config_get_string_buf(&buf
, config
, key
));
46 cl_assert_equal_s(value
, git_buf_cstr(&buf
));
49 void test_config_stress__comments(void)
53 cl_git_pass(git_config_open_ondisk(&config
, cl_fixture("config/config12")));
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");
63 git_config_free(config
);
66 void test_config_stress__escape_subsection_names(void)
70 cl_assert(git_path_exists("git-test-config"));
71 cl_git_pass(git_config_open_ondisk(&config
, TEST_CONFIG
));
73 cl_git_pass(git_config_set_string(config
, "some.sec\\tion.other", "foo"));
74 git_config_free(config
);
76 cl_git_pass(git_config_open_ondisk(&config
, TEST_CONFIG
));
78 assert_config_value(config
, "some.sec\\tion.other", "foo");
80 git_config_free(config
);
83 void test_config_stress__trailing_backslash(void)
86 const char *path
= "C:\\iam\\some\\windows\\path\\";
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
);
93 cl_git_pass(git_config_open_ondisk(&config
, TEST_CONFIG
));
94 assert_config_value(config
, "windows.path", path
);
96 git_config_free(config
);
99 void test_config_stress__complex(void)
102 const char *path
= "./config-immediate-multiline";
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");
108 git_config_free(config
);