config: test saving config to new file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
diff --git a/tests-clay/clay.h b/tests-clay/clay.h
index 812209b..3db9600 100644
--- a/tests-clay/clay.h
+++ b/tests-clay/clay.h
@@ -59,6 +59,7 @@ void cl_fixture_cleanup(const char *fixture_name);
*/
extern void test_buf_basic__printf(void);
extern void test_buf_basic__resize(void);
+extern void test_config_new__write_new_config(void);
extern void test_config_stress__cleanup(void);
extern void test_config_stress__dont_break_on_invalid_input(void);
extern void test_config_stress__initialize(void);
diff --git a/tests-clay/clay_main.c b/tests-clay/clay_main.c
index 6d964b1..2f9a49d 100644
--- a/tests-clay/clay_main.c
+++ b/tests-clay/clay_main.c
@@ -108,6 +108,9 @@ static const struct clay_func _clay_cb_buf_basic[] = {
{"printf", &test_buf_basic__printf},
{"resize", &test_buf_basic__resize}
};
+static const struct clay_func _clay_cb_config_new[] = {
+ {"write_new_config", &test_config_new__write_new_config}
+};
static const struct clay_func _clay_cb_config_stress[] = {
{"dont_break_on_invalid_input", &test_config_stress__dont_break_on_invalid_input}
};
@@ -229,6 +232,12 @@ static const struct clay_suite _clay_suites[] = {
_clay_cb_buf_basic, 2
},
{
+ "config::new",
+ {NULL, NULL},
+ {NULL, NULL},
+ _clay_cb_config_new, 1
+ },
+ {
"config::stress",
{"initialize", &test_config_stress__initialize},
{"cleanup", &test_config_stress__cleanup},
@@ -362,8 +371,8 @@ static const struct clay_suite _clay_suites[] = {
}
};
-static size_t _clay_suite_count = 23;
-static size_t _clay_callback_count = 70;
+static size_t _clay_suite_count = 24;
+static size_t _clay_callback_count = 71;
/* Core test functions */
static void
diff --git a/tests-clay/config/new.c b/tests-clay/config/new.c
new file mode 100644
index 0000000..285cc4a
--- /dev/null
+++ b/tests-clay/config/new.c
@@ -0,0 +1,36 @@
+#include "clay_libgit2.h"
+
+#include "filebuf.h"
+#include "fileops.h"
+#include "posix.h"
+
+#define TEST_CONFIG "git-new-config"
+
+void test_config_new__write_new_config(void)
+{
+ const char *out;
+ struct git_config_file *file;
+ git_config *config;
+
+ cl_git_pass(git_config_file__ondisk(&file, TEST_CONFIG));
+ cl_git_pass(git_config_new(&config));
+ cl_git_pass(git_config_add_file(config, file, 0));
+
+ cl_git_pass(git_config_set_string(config, "color.ui", "auto"));
+ cl_git_pass(git_config_set_string(config, "core.editor", "ed"));
+
+ git_config_free(config);
+
+ cl_git_pass(git_config_file__ondisk(&file, TEST_CONFIG));
+ cl_git_pass(git_config_new(&config));
+ cl_git_pass(git_config_add_file(config, file, 0));
+
+ cl_git_pass(git_config_get_string(config, "color.ui", &out));
+ cl_assert(strcmp(out, "auto") == 0);
+ cl_git_pass(git_config_get_string(config, "core.editor", &out));
+ cl_assert(strcmp(out, "ed") == 0);
+
+ git_config_free(config);
+
+ p_unlink(TEST_CONFIG);
+}