summaryrefslogtreecommitdiff
path: root/tests/config/stress.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/config/stress.c')
-rw-r--r--tests/config/stress.c58
1 files changed, 25 insertions, 33 deletions
diff --git a/tests/config/stress.c b/tests/config/stress.c
index e8e9d2b61..503f44f03 100644
--- a/tests/config/stress.c
+++ b/tests/config/stress.c
@@ -6,6 +6,8 @@
#define TEST_CONFIG "git-test-config"
+static git_buf buf = GIT_BUF_INIT;
+
void test_config_stress__initialize(void)
{
git_filebuf file = GIT_FILEBUF_INIT;
@@ -20,50 +22,43 @@ void test_config_stress__initialize(void)
void test_config_stress__cleanup(void)
{
+ git_buf_free(&buf);
p_unlink(TEST_CONFIG);
}
void test_config_stress__dont_break_on_invalid_input(void)
{
- const char *editor, *color;
git_config *config;
cl_assert(git_path_exists(TEST_CONFIG));
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
- cl_git_pass(git_config_get_string(&color, config, "color.ui"));
- cl_git_pass(git_config_get_string(&editor, config, "core.editor"));
+ cl_git_pass(git_config_get_string_buf(&buf, config, "color.ui"));
+ cl_git_pass(git_config_get_string_buf(&buf, config, "core.editor"));
git_config_free(config);
}
+void assert_config_value(git_config *config, const char *key, const char *value)
+{
+ git_buf_clear(&buf);
+ cl_git_pass(git_config_get_string_buf(&buf, config, key));
+ cl_assert_equal_s(value, git_buf_cstr(&buf));
+}
+
void test_config_stress__comments(void)
{
git_config *config;
- const char *str;
cl_git_pass(git_config_open_ondisk(&config, cl_fixture("config/config12")));
- cl_git_pass(git_config_get_string(&str, config, "some.section.test2"));
- cl_assert_equal_s("hello", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.test3"));
- cl_assert_equal_s("welcome", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.other"));
- cl_assert_equal_s("hello! \" ; ; ; ", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.other2"));
- cl_assert_equal_s("cool! \" # # # ", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.multi"));
- cl_assert_equal_s("hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.multi2"));
- cl_assert_equal_s("good, this is a ; multiline comment # with ;\n special chars and other stuff !@#", str);
-
- cl_git_pass(git_config_get_string(&str, config, "some.section.back"));
- cl_assert_equal_s("this is \ba phrase", str);
+ assert_config_value(config, "some.section.test2", "hello");
+ assert_config_value(config, "some.section.test3", "welcome");
+ assert_config_value(config, "some.section.other", "hello! \" ; ; ; ");
+ assert_config_value(config, "some.section.other2", "cool! \" # # # ");
+ assert_config_value(config, "some.section.multi", "hi, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
+ assert_config_value(config, "some.section.multi2", "good, this is a ; multiline comment # with ;\n special chars and other stuff !@#");
+ assert_config_value(config, "some.section.back", "this is \ba phrase");
git_config_free(config);
}
@@ -71,7 +66,6 @@ void test_config_stress__comments(void)
void test_config_stress__escape_subsection_names(void)
{
git_config *config;
- const char *str;
cl_assert(git_path_exists("git-test-config"));
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
@@ -81,15 +75,14 @@ void test_config_stress__escape_subsection_names(void)
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
- cl_git_pass(git_config_get_string(&str, config, "some.sec\\tion.other"));
- cl_assert_equal_s("foo", str);
+ assert_config_value(config, "some.sec\\tion.other", "foo");
+
git_config_free(config);
}
void test_config_stress__trailing_backslash(void)
{
git_config *config;
- const char *str;
const char *path = "C:\\iam\\some\\windows\\path\\";
cl_assert(git_path_exists("git-test-config"));
@@ -98,20 +91,19 @@ void test_config_stress__trailing_backslash(void)
git_config_free(config);
cl_git_pass(git_config_open_ondisk(&config, TEST_CONFIG));
- cl_git_pass(git_config_get_string(&str, config, "windows.path"));
- cl_assert_equal_s(path, str);
+ assert_config_value(config, "windows.path", path);
+
git_config_free(config);
}
void test_config_stress__complex(void)
{
git_config *config;
- const char *str;
const char *path = "./config-immediate-multiline";
cl_git_mkfile(path, "[imm]\n multi = \"\\\nfoo\"");
cl_git_pass(git_config_open_ondisk(&config, path));
- cl_git_pass(git_config_get_string(&str, config, "imm.multi"));
- cl_assert_equal_s(str, "foo");
+ assert_config_value(config, "imm.multi", "foo");
+
git_config_free(config);
}