diff options
Diffstat (limited to 'tests/index')
-rw-r--r-- | tests/index/crlf.c | 84 | ||||
-rw-r--r-- | tests/index/filemodes.c | 11 | ||||
-rw-r--r-- | tests/index/nsec.c | 6 | ||||
-rw-r--r-- | tests/index/racy.c | 25 | ||||
-rw-r--r-- | tests/index/tests.c | 30 |
5 files changed, 77 insertions, 79 deletions
diff --git a/tests/index/crlf.c b/tests/index/crlf.c index 26c19d76d..8d2a5fcce 100644 --- a/tests/index/crlf.c +++ b/tests/index/crlf.c @@ -14,7 +14,7 @@ static git_repository *g_repo; static git_index *g_index; -static git_buf expected_fixture = GIT_BUF_INIT; +static git_str expected_fixture = GIT_STR_INIT; void test_index_crlf__initialize(void) { @@ -29,7 +29,7 @@ void test_index_crlf__cleanup(void) if (expected_fixture.size) { cl_fixture_cleanup(expected_fixture.ptr); - git_buf_dispose(&expected_fixture); + git_str_dispose(&expected_fixture); } } @@ -42,11 +42,11 @@ struct compare_data const char *attrs; }; -static int add_and_check_file(void *payload, git_buf *actual_path) +static int add_and_check_file(void *payload, git_str *actual_path) { - git_buf expected_path = GIT_BUF_INIT; - git_buf expected_path_fail = GIT_BUF_INIT; - git_buf expected_contents = GIT_BUF_INIT; + git_str expected_path = GIT_STR_INIT; + git_str expected_path_fail = GIT_STR_INIT; + git_str expected_contents = GIT_STR_INIT; struct compare_data *cd = payload; char *basename; const git_index_entry *entry; @@ -60,10 +60,10 @@ static int add_and_check_file(void *payload, git_buf *actual_path) goto done; } - cl_git_pass(git_buf_joinpath(&expected_path, cd->dirname, basename)); + cl_git_pass(git_str_joinpath(&expected_path, cd->dirname, basename)); - cl_git_pass(git_buf_puts(&expected_path_fail, expected_path.ptr)); - cl_git_pass(git_buf_puts(&expected_path_fail, ".fail")); + cl_git_pass(git_str_puts(&expected_path_fail, expected_path.ptr)); + cl_git_pass(git_str_puts(&expected_path_fail, ".fail")); if (git_path_isfile(expected_path.ptr)) { cl_git_pass(git_index_add_bypath(g_index, basename)); @@ -79,7 +79,7 @@ static int add_and_check_file(void *payload, git_buf *actual_path) git_blob_free(blob); } else if (git_path_isfile(expected_path_fail.ptr)) { cl_git_pass(git_futils_readbuffer(&expected_contents, expected_path_fail.ptr)); - git_buf_rtrim(&expected_contents); + git_str_rtrim(&expected_contents); if (git_index_add_bypath(g_index, basename) == 0 || git_error_last()->klass != GIT_ERROR_FILTER || @@ -93,18 +93,18 @@ static int add_and_check_file(void *payload, git_buf *actual_path) done: if (failed) { - git_buf details = GIT_BUF_INIT; - git_buf_printf(&details, "filename=%s, system=%s, autocrlf=%s, safecrlf=%s, attrs={%s}", + git_str details = GIT_STR_INIT; + git_str_printf(&details, "filename=%s, system=%s, autocrlf=%s, safecrlf=%s, attrs={%s}", basename, cd->systype, cd->autocrlf, cd->safecrlf, cd->attrs); clar__fail(__FILE__, __func__, __LINE__, "index contents did not match expected", details.ptr, 0); - git_buf_dispose(&details); + git_str_dispose(&details); } git__free(basename); - git_buf_dispose(&expected_contents); - git_buf_dispose(&expected_path); - git_buf_dispose(&expected_path_fail); + git_str_dispose(&expected_contents); + git_str_dispose(&expected_path); + git_str_dispose(&expected_path_fail); return 0; } @@ -118,34 +118,34 @@ static const char *system_type(void) static void test_add_index(const char *safecrlf, const char *autocrlf, const char *attrs) { - git_buf attrbuf = GIT_BUF_INIT; - git_buf expected_dirname = GIT_BUF_INIT; - git_buf sandboxname = GIT_BUF_INIT; - git_buf reponame = GIT_BUF_INIT; + git_str attrbuf = GIT_STR_INIT; + git_str expected_dirname = GIT_STR_INIT; + git_str sandboxname = GIT_STR_INIT; + git_str reponame = GIT_STR_INIT; struct compare_data compare_data = { system_type(), NULL, safecrlf, autocrlf, attrs }; const char *c; - git_buf_puts(&reponame, "crlf"); + git_str_puts(&reponame, "crlf"); - git_buf_puts(&sandboxname, "autocrlf_"); - git_buf_puts(&sandboxname, autocrlf); + git_str_puts(&sandboxname, "autocrlf_"); + git_str_puts(&sandboxname, autocrlf); - git_buf_puts(&sandboxname, ",safecrlf_"); - git_buf_puts(&sandboxname, safecrlf); + git_str_puts(&sandboxname, ",safecrlf_"); + git_str_puts(&sandboxname, safecrlf); if (*attrs) { - git_buf_puts(&sandboxname, ","); + git_str_puts(&sandboxname, ","); for (c = attrs; *c; c++) { if (*c == ' ') - git_buf_putc(&sandboxname, ','); + git_str_putc(&sandboxname, ','); else if (*c == '=') - git_buf_putc(&sandboxname, '_'); + git_str_putc(&sandboxname, '_'); else - git_buf_putc(&sandboxname, *c); + git_str_putc(&sandboxname, *c); } - git_buf_printf(&attrbuf, "* %s\n", attrs); + git_str_printf(&attrbuf, "* %s\n", attrs); cl_git_mkfile("crlf/.gitattributes", attrbuf.ptr); } @@ -154,23 +154,23 @@ static void test_add_index(const char *safecrlf, const char *autocrlf, const cha cl_git_pass(git_index_clear(g_index)); - git_buf_joinpath(&expected_dirname, "crlf_data", system_type()); - git_buf_puts(&expected_dirname, "_to_odb"); + git_str_joinpath(&expected_dirname, "crlf_data", system_type()); + git_str_puts(&expected_dirname, "_to_odb"); - git_buf_joinpath(&expected_fixture, expected_dirname.ptr, sandboxname.ptr); + git_str_joinpath(&expected_fixture, expected_dirname.ptr, sandboxname.ptr); cl_fixture_sandbox(expected_fixture.ptr); compare_data.dirname = sandboxname.ptr; cl_git_pass(git_path_direach(&reponame, 0, add_and_check_file, &compare_data)); cl_fixture_cleanup(expected_fixture.ptr); - git_buf_dispose(&expected_fixture); + git_str_dispose(&expected_fixture); - git_buf_dispose(&attrbuf); - git_buf_dispose(&expected_fixture); - git_buf_dispose(&expected_dirname); - git_buf_dispose(&sandboxname); - git_buf_dispose(&reponame); + git_str_dispose(&attrbuf); + git_str_dispose(&expected_fixture); + git_str_dispose(&expected_dirname); + git_str_dispose(&sandboxname); + git_str_dispose(&reponame); } static void set_up_workingdir(const char *name) @@ -196,16 +196,16 @@ static void set_up_workingdir(const char *name) git_path_dirload(&contents, cl_fixture("crlf"), 0, 0); git_vector_foreach(&contents, i, fn) { char *basename = git_path_basename(fn); - git_buf dest_filename = GIT_BUF_INIT; + git_str dest_filename = GIT_STR_INIT; if (strcmp(basename, ".gitted") && strcmp(basename, ".gitattributes")) { - git_buf_joinpath(&dest_filename, name, basename); + git_str_joinpath(&dest_filename, name, basename); cl_git_pass(git_futils_cp(fn, dest_filename.ptr, 0644)); } git__free(basename); - git_buf_dispose(&dest_filename); + git_str_dispose(&dest_filename); } git_vector_free_deep(&contents); } diff --git a/tests/index/filemodes.c b/tests/index/filemodes.c index 3d2bb4a03..1ab8a9a7f 100644 --- a/tests/index/filemodes.c +++ b/tests/index/filemodes.c @@ -1,5 +1,4 @@ #include "clar_libgit2.h" -#include "buffer.h" #include "posix.h" #include "index.h" @@ -36,10 +35,10 @@ void test_index_filemodes__read(void) static void replace_file_with_mode( const char *filename, const char *backup, unsigned int create_mode) { - git_buf path = GIT_BUF_INIT, content = GIT_BUF_INIT; + git_str path = GIT_STR_INIT, content = GIT_STR_INIT; - cl_git_pass(git_buf_joinpath(&path, "filemodes", filename)); - cl_git_pass(git_buf_printf(&content, "%s as %08u (%d)", + cl_git_pass(git_str_joinpath(&path, "filemodes", filename)); + cl_git_pass(git_str_printf(&content, "%s as %08u (%d)", filename, create_mode, rand())); cl_git_pass(p_rename(path.ptr, backup)); @@ -47,8 +46,8 @@ static void replace_file_with_mode( path.ptr, content.ptr, content.size, O_WRONLY|O_CREAT|O_TRUNC, create_mode); - git_buf_dispose(&path); - git_buf_dispose(&content); + git_str_dispose(&path); + git_str_dispose(&content); } #define add_and_check_mode(I,F,X) add_and_check_mode_(I,F,X,__FILE__,__func__,__LINE__) diff --git a/tests/index/nsec.c b/tests/index/nsec.c index 6edcf030a..3efd855a7 100644 --- a/tests/index/nsec.c +++ b/tests/index/nsec.c @@ -47,16 +47,16 @@ static bool try_create_file_with_nsec_timestamp(const char *path) */ static bool should_expect_nsecs(void) { - git_buf nsec_path = GIT_BUF_INIT; + git_str nsec_path = GIT_STR_INIT; bool expect; - git_buf_joinpath(&nsec_path, clar_sandbox_path(), "nsec_test"); + git_str_joinpath(&nsec_path, clar_sandbox_path(), "nsec_test"); expect = try_create_file_with_nsec_timestamp(nsec_path.ptr); cl_must_pass(p_unlink(nsec_path.ptr)); - git_buf_dispose(&nsec_path); + git_str_dispose(&nsec_path); return expect; } diff --git a/tests/index/racy.c b/tests/index/racy.c index b06f55de4..07b3b73d4 100644 --- a/tests/index/racy.c +++ b/tests/index/racy.c @@ -1,7 +1,6 @@ #include "clar_libgit2.h" #include "../checkout/checkout_helpers.h" -#include "buffer.h" #include "index.h" #include "repository.h" @@ -24,9 +23,9 @@ void test_index_racy__diff(void) { git_index *index; git_diff *diff; - git_buf path = GIT_BUF_INIT; + git_str path = GIT_STR_INIT; - cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A")); + cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "A")); cl_git_mkfile(path.ptr, "A"); /* Put 'A' into the index */ @@ -46,21 +45,21 @@ void test_index_racy__diff(void) git_index_free(index); git_diff_free(diff); - git_buf_dispose(&path); + git_str_dispose(&path); } void test_index_racy__write_index_just_after_file(void) { git_index *index; git_diff *diff; - git_buf path = GIT_BUF_INIT; + git_str path = GIT_STR_INIT; struct p_timeval times[2]; /* Make sure we do have a timestamp */ cl_git_pass(git_repository_index(&index, g_repo)); cl_git_pass(git_index_write(index)); - cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A")); + cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "A")); cl_git_mkfile(path.ptr, "A"); /* Force the file's timestamp to be a second after we wrote the index */ times[0].tv_sec = index->stamp.mtime.tv_sec + 1; @@ -95,7 +94,7 @@ void test_index_racy__write_index_just_after_file(void) cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, NULL)); cl_assert_equal_i(1, git_diff_num_deltas(diff)); - git_buf_dispose(&path); + git_str_dispose(&path); git_diff_free(diff); git_index_free(index); } @@ -103,7 +102,7 @@ void test_index_racy__write_index_just_after_file(void) static void setup_race(void) { - git_buf path = GIT_BUF_INIT; + git_str path = GIT_STR_INIT; git_index *index; git_index_entry *entry; struct stat st; @@ -112,7 +111,7 @@ static void setup_race(void) cl_git_pass(git_repository_index__weakptr(&index, g_repo)); cl_git_pass(git_index_write(index)); - cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A")); + cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "A")); cl_git_mkfile(path.ptr, "A"); cl_git_pass(git_index_add_bypath(index, "A")); @@ -129,7 +128,7 @@ static void setup_race(void) entry->mtime.seconds = (int32_t)st.st_mtime; entry->mtime.nanoseconds = (int32_t)st.st_mtime_nsec; - git_buf_dispose(&path); + git_str_dispose(&path); } void test_index_racy__smudges_index_entry_on_save(void) @@ -169,14 +168,14 @@ void test_index_racy__detects_diff_of_change_in_identical_timestamp(void) static void setup_uptodate_files(void) { - git_buf path = GIT_BUF_INIT; + git_str path = GIT_STR_INIT; git_index *index; const git_index_entry *a_entry; git_index_entry new_entry = {{0}}; cl_git_pass(git_repository_index(&index, g_repo)); - cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A")); + cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "A")); cl_git_mkfile(path.ptr, "A"); /* Put 'A' into the index */ @@ -196,7 +195,7 @@ static void setup_uptodate_files(void) cl_git_pass(git_index_add_from_buffer(index, &new_entry, "hello!\n", 7)); git_index_free(index); - git_buf_dispose(&path); + git_str_dispose(&path); } void test_index_racy__adding_to_index_is_uptodate(void) diff --git a/tests/index/tests.c b/tests/index/tests.c index d9d8371dd..9b28028e6 100644 --- a/tests/index/tests.c +++ b/tests/index/tests.c @@ -28,7 +28,7 @@ static struct test_entry test_entries[] = { /* Helpers */ static void copy_file(const char *src, const char *dst) { - git_buf source_buf = GIT_BUF_INIT; + git_str source_buf = GIT_STR_INIT; git_file dst_fd; cl_git_pass(git_futils_readbuffer(&source_buf, src)); @@ -40,28 +40,28 @@ static void copy_file(const char *src, const char *dst) cl_git_pass(p_write(dst_fd, source_buf.ptr, source_buf.size)); cleanup: - git_buf_dispose(&source_buf); + git_str_dispose(&source_buf); p_close(dst_fd); } static void files_are_equal(const char *a, const char *b) { - git_buf buf_a = GIT_BUF_INIT; - git_buf buf_b = GIT_BUF_INIT; + git_str buf_a = GIT_STR_INIT; + git_str buf_b = GIT_STR_INIT; int pass; if (git_futils_readbuffer(&buf_a, a) < 0) cl_assert(0); if (git_futils_readbuffer(&buf_b, b) < 0) { - git_buf_dispose(&buf_a); + git_str_dispose(&buf_a); cl_assert(0); } pass = (buf_a.size == buf_b.size && !memcmp(buf_a.ptr, buf_b.ptr, buf_a.size)); - git_buf_dispose(&buf_a); - git_buf_dispose(&buf_b); + git_str_dispose(&buf_a); + git_str_dispose(&buf_b); cl_assert(pass); } @@ -544,12 +544,12 @@ void test_index_tests__add_bypath_to_a_bare_repository_returns_EBAREPO(void) static void assert_add_bypath_fails(git_repository *repo, const char *fn) { git_index *index; - git_buf path = GIT_BUF_INIT; + git_str path = GIT_STR_INIT; cl_git_pass(git_repository_index(&index, repo)); cl_assert(git_index_entrycount(index) == 0); - git_buf_joinpath(&path, "./invalid", fn); + git_str_joinpath(&path, "./invalid", fn); cl_git_mkfile(path.ptr, NULL); cl_git_fail(git_index_add_bypath(index, fn)); @@ -557,7 +557,7 @@ static void assert_add_bypath_fails(git_repository *repo, const char *fn) cl_assert(git_index_entrycount(index) == 0); - git_buf_dispose(&path); + git_str_dispose(&path); git_index_free(index); } @@ -592,7 +592,7 @@ void test_index_tests__cannot_add_invalid_filename(void) static void assert_add_fails(git_repository *repo, const char *fn) { git_index *index; - git_buf path = GIT_BUF_INIT; + git_str path = GIT_STR_INIT; git_index_entry entry = {{0}}; cl_git_pass(git_repository_index(&index, repo)); @@ -606,7 +606,7 @@ static void assert_add_fails(git_repository *repo, const char *fn) cl_assert(git_index_entrycount(index) == 0); - git_buf_dispose(&path); + git_str_dispose(&path); git_index_free(index); } @@ -659,7 +659,7 @@ static void assert_write_fails(git_repository *repo, const char *fn_orig) git_index *index; git_oid expected; const git_index_entry *entry; - git_buf path = GIT_BUF_INIT; + git_str path = GIT_STR_INIT; char *fn; cl_git_pass(git_repository_index(&index, repo)); @@ -673,7 +673,7 @@ static void assert_write_fails(git_repository *repo, const char *fn_orig) replace_char(fn, '/', '_'); replace_char(fn, ':', '!'); - git_buf_joinpath(&path, "./invalid", fn); + git_str_joinpath(&path, "./invalid", fn); cl_git_mkfile(path.ptr, NULL); @@ -691,7 +691,7 @@ static void assert_write_fails(git_repository *repo, const char *fn_orig) p_unlink(path.ptr); cl_git_pass(git_index_remove_all(index, NULL, NULL, NULL)); - git_buf_dispose(&path); + git_str_dispose(&path); git_index_free(index); git__free(fn); } |