]>
git.proxmox.com Git - libgit2.git/blob - tests/config/stress.c
1 #include "clar_libgit2.h"
7 #define TEST_CONFIG "git-test-config"
9 void test_config_stress__initialize(void)
11 git_filebuf file
= GIT_FILEBUF_INIT
;
13 cl_git_pass(git_filebuf_open(&file
, TEST_CONFIG
, 0, 0666));
15 git_filebuf_printf(&file
, "[color]\n\tui = auto\n");
16 git_filebuf_printf(&file
, "[core]\n\teditor = \n");
18 cl_git_pass(git_filebuf_commit(&file
));
21 void test_config_stress__cleanup(void)
23 p_unlink(TEST_CONFIG
);
26 void test_config_stress__dont_break_on_invalid_input(void)
28 const char *editor
, *color
;
31 cl_assert(git_path_exists(TEST_CONFIG
));
32 cl_git_pass(git_config_open_ondisk(&config
, TEST_CONFIG
));
34 cl_git_pass(git_config_get_string(&color
, config
, "color.ui"));
35 cl_git_pass(git_config_get_string(&editor
, config
, "core.editor"));
37 git_config_free(config
);
40 void test_config_stress__comments(void)
45 cl_git_pass(git_config_open_ondisk(&config
, cl_fixture("config/config12")));
47 cl_git_pass(git_config_get_string(&str
, config
, "some.section.other"));
48 cl_assert_equal_s("hello! \" ; ; ; ", str
);
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
);
53 cl_git_pass(git_config_get_string(&str
, config
, "some.section.back"));
54 cl_assert_equal_s("this is \ba phrase", str
);
56 git_config_free(config
);
59 void test_config_stress__escape_subsection_names(void)
64 cl_assert(git_path_exists("git-test-config"));
65 cl_git_pass(git_config_open_ondisk(&config
, TEST_CONFIG
));
67 cl_git_pass(git_config_set_string(config
, "some.sec\\tion.other", "foo"));
68 git_config_free(config
);
70 cl_git_pass(git_config_open_ondisk(&config
, TEST_CONFIG
));
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
);
77 void test_config_stress__trailing_backslash(void)
81 const char *path
= "C:\\iam\\some\\windows\\path\\";
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
);
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
);
94 void test_config_stress__complex(void)
98 const char *path
= "./config-immediate-multiline";
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
);