]>
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.test2"));
48 cl_assert_equal_s("hello", str
);
50 cl_git_pass(git_config_get_string(&str
, config
, "some.section.test3"));
51 cl_assert_equal_s("welcome", str
);
53 cl_git_pass(git_config_get_string(&str
, config
, "some.section.other"));
54 cl_assert_equal_s("hello! \" ; ; ; ", str
);
56 cl_git_pass(git_config_get_string(&str
, config
, "some.section.other2"));
57 cl_assert_equal_s("cool! \" # # # ", str
);
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
);
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
);
65 cl_git_pass(git_config_get_string(&str
, config
, "some.section.back"));
66 cl_assert_equal_s("this is \ba phrase", str
);
68 git_config_free(config
);
71 void test_config_stress__escape_subsection_names(void)
76 cl_assert(git_path_exists("git-test-config"));
77 cl_git_pass(git_config_open_ondisk(&config
, TEST_CONFIG
));
79 cl_git_pass(git_config_set_string(config
, "some.sec\\tion.other", "foo"));
80 git_config_free(config
);
82 cl_git_pass(git_config_open_ondisk(&config
, TEST_CONFIG
));
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
);
89 void test_config_stress__trailing_backslash(void)
93 const char *path
= "C:\\iam\\some\\windows\\path\\";
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
);
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
);
106 void test_config_stress__complex(void)
110 const char *path
= "./config-immediate-multiline";
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
);