From ca0fb40a6f3ec2b1a254e0d5e5f307cbed541251 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sat, 5 Feb 2011 17:18:27 +0100 Subject: [PATCH 1/3] Made test index_write_test() remove the test file it has created. It can now be run twice in a row without failing. --- tests/t06-index.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/t06-index.c b/tests/t06-index.c index 72702e819..f46dfb339 100644 --- a/tests/t06-index.c +++ b/tests/t06-index.c @@ -146,6 +146,8 @@ BEGIN_TEST("write", index_write_test) must_pass(git_filelock_commit(&out_file)); git_index_free(index); + + gitfo_unlink("index_rewrite"); END_TEST From a79e8e632a674934843612084cd654475c2c85b5 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sat, 5 Feb 2011 19:22:44 +0100 Subject: [PATCH 2/3] Fixed a small issue in git__join_path(). Added tests to exercise git__join_path(). --- src/util.c | 4 +++- tests/t00-core.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/util.c b/src/util.c index e1f709962..67b74eeba 100644 --- a/src/util.c +++ b/src/util.c @@ -207,6 +207,8 @@ char *git__joinpath(const char *path_a, const char *path_b) int len_a, len_b; char *path_new; + assert(path_a && path_b); + len_a = strlen(path_a); len_b = strlen(path_b); @@ -216,7 +218,7 @@ char *git__joinpath(const char *path_a, const char *path_b) strcpy(path_new, path_a); - if (path_new[len_a - 1] != '/') + if (len_a > 0 && len_b > 0 && path_new[len_a - 1] != '/') path_new[len_a++] = '/'; if (path_b[0] == '/') diff --git a/tests/t00-core.c b/tests/t00-core.c index 7dd09955f..4a5df385f 100644 --- a/tests/t00-core.c +++ b/tests/t00-core.c @@ -342,6 +342,34 @@ BEGIN_TEST("path", dir_path_prettifying) must_fail(ensure_dir_path_normalized("/d1/.../d2", NULL)); END_TEST +static int ensure_joinpath(const char *path_a, const char *path_b, const char *expected_path) +{ + int error = GIT_SUCCESS; + char* joined_path; + + joined_path = git__joinpath(path_a, path_b); + if (joined_path == NULL) + return GIT_ERROR; + + if (strcmp(joined_path, expected_path)) + error = GIT_ERROR; + + return error; +} + +BEGIN_TEST("path", joinpath) + must_pass(ensure_joinpath("", "", "")); + must_pass(ensure_joinpath("", "a", "a")); + must_pass(ensure_joinpath("a", "", "a")); + must_pass(ensure_joinpath("a", "b", "a/b")); + must_pass(ensure_joinpath("/", "a", "/a")); + must_pass(ensure_joinpath("/", "", "/")); + must_pass(ensure_joinpath("/a", "/b", "/a/b")); + must_pass(ensure_joinpath("/a", "/b/", "/a/b/")); + must_pass(ensure_joinpath("/a/", "b/", "/a/b/")); + must_pass(ensure_joinpath("/a/", "/b/", "/a/b/")); +END_TEST + typedef struct name_data { int count; /* return count */ char *name; /* filename */ @@ -601,6 +629,7 @@ git_testsuite *libgit2_suite_core(void) ADD_TEST(suite, "path", file_path_prettifying); ADD_TEST(suite, "path", dir_path_prettifying); + ADD_TEST(suite, "path", joinpath); ADD_TEST(suite, "dirent", dot); ADD_TEST(suite, "dirent", sub); From fc8afc87d78c79c57b6448f9b92e47f3f2515f38 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 6 Feb 2011 07:48:17 +0100 Subject: [PATCH 3/3] Fix a memory leak in git__joinpath() tests. --- tests/t00-core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/t00-core.c b/tests/t00-core.c index 4a5df385f..f20aa9d76 100644 --- a/tests/t00-core.c +++ b/tests/t00-core.c @@ -354,6 +354,8 @@ static int ensure_joinpath(const char *path_a, const char *path_b, const char *e if (strcmp(joined_path, expected_path)) error = GIT_ERROR; + free(joined_path); + return error; }