diff options
| author | Edward Thomson <ethomson@microsoft.com> | 2015-04-21 17:18:21 -0400 |
|---|---|---|
| committer | Edward Thomson <ethomson@microsoft.com> | 2015-04-23 11:25:03 -0400 |
| commit | 6dc55872a86df3428e312455333b19b42664c355 (patch) | |
| tree | 25adb40f35cdbe42baa0dbcf62cb6ddc92b161ef /tests/config/write.c | |
| parent | 2c8c00c646580cf952dc03c598830666b8c05933 (diff) | |
| download | libgit2-6dc55872a86df3428e312455333b19b42664c355.tar.gz | |
config: ensure we can write to an empty file
Diffstat (limited to 'tests/config/write.c')
| -rw-r--r-- | tests/config/write.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/config/write.c b/tests/config/write.c index bcc87571c..1832466ae 100644 --- a/tests/config/write.c +++ b/tests/config/write.c @@ -1,5 +1,6 @@ #include "clar_libgit2.h" #include "buffer.h" +#include "fileops.h" void test_config_write__initialize(void) { @@ -393,3 +394,37 @@ void test_config_write__outside_change(void) git_config_free(cfg); } + +void test_config_write__to_empty_file(void) +{ + git_config *cfg; + const char *filename = "config-file"; + git_buf result = GIT_BUF_INIT; + + cl_git_mkfile(filename, ""); + cl_git_pass(git_config_open_ondisk(&cfg, filename)); + cl_git_pass(git_config_set_string(cfg, "section.name", "value")); + git_config_free(cfg); + + cl_git_pass(git_futils_readbuffer(&result, "config-file")); + cl_assert_equal_s("[section]\n\tname = value\n", result.ptr); + + git_buf_free(&result); +} + +void test_config_write__to_file_with_only_comment(void) +{ + git_config *cfg; + const char *filename = "config-file"; + git_buf result = GIT_BUF_INIT; + + cl_git_mkfile(filename, "\n\n"); + cl_git_pass(git_config_open_ondisk(&cfg, filename)); + cl_git_pass(git_config_set_string(cfg, "section.name", "value")); + git_config_free(cfg); + + cl_git_pass(git_futils_readbuffer(&result, "config-file")); + cl_assert_equal_s("\n\n[section]\n\tname = value\n", result.ptr); + + git_buf_free(&result); +} |
