diff options
author | Vicent Marti <tanoku@gmail.com> | 2011-07-05 03:11:33 +0400 |
---|---|---|
committer | Vicent Marti <tanoku@gmail.com> | 2011-07-05 04:09:05 +0400 |
commit | eec3fe394ad5953cc5e290e8bc6492dfbe463a1f (patch) | |
tree | 049e3c3956cec1841f0c9e9e014212c856890ecd /tests | |
parent | 19ac1ed702b043790f4a6f0d095dd81f078b6c4c (diff) |
fileutils: Finish dropping the old `prettify_path`
Diffstat (limited to 'tests')
-rw-r--r-- | tests/t00-core.c | 234 | ||||
-rw-r--r-- | tests/t12-repo.c | 2 |
2 files changed, 1 insertions, 235 deletions
diff --git a/tests/t00-core.c b/tests/t00-core.c index 7ce51a7ba..ba5188a43 100644 --- a/tests/t00-core.c +++ b/tests/t00-core.c @@ -152,206 +152,6 @@ BEGIN_TEST(path2, "get the latest component in a path") #undef TOPDIR_TEST END_TEST -typedef int (normalize_path)(char *, size_t, const char *, const char *); - -/* Assert flags */ -#define CWD_AS_PREFIX 1 -#define PATH_AS_SUFFIX 2 -#define ROOTED_PATH 4 - -static int ensure_normalized(const char *input_path, const char *expected_path, normalize_path normalizer, int assert_flags) -{ - int error = GIT_SUCCESS; - char buffer_out[GIT_PATH_MAX]; - char current_workdir[GIT_PATH_MAX]; - - error = p_getcwd(current_workdir, sizeof(current_workdir)); - if (error < GIT_SUCCESS) - return error; - - error = normalizer(buffer_out, sizeof(buffer_out), input_path, NULL); - if (error < GIT_SUCCESS) - return error; - - if (expected_path == NULL) - return error; - - if ((assert_flags & PATH_AS_SUFFIX) != 0) - if (git__suffixcmp(buffer_out, expected_path)) - return GIT_ERROR; - - if ((assert_flags & CWD_AS_PREFIX) != 0) - if (git__prefixcmp(buffer_out, current_workdir)) - return GIT_ERROR; - - if ((assert_flags & ROOTED_PATH) != 0) { - error = strcmp(expected_path, buffer_out); - } - - return error; -} - -static int ensure_dir_path_normalized(const char *input_path, const char *expected_path, int assert_flags) -{ - return ensure_normalized(input_path, expected_path, git_futils_prettify_dir, assert_flags); -} - -static int ensure_file_path_normalized(const char *input_path, const char *expected_path, int assert_flags) -{ - return ensure_normalized(input_path, expected_path, git_futils_prettyify_file, assert_flags); -} - -BEGIN_TEST(path3, "prettify and validate a path to a file") - must_pass(ensure_file_path_normalized("a", "a", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_file_path_normalized("./testrepo.git", "testrepo.git", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_file_path_normalized("./.git", ".git", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_file_path_normalized("./git.", "git.", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_fail(ensure_file_path_normalized("git./", NULL, 0)); - must_fail(ensure_file_path_normalized("", NULL, 0)); - must_fail(ensure_file_path_normalized(".", NULL, 0)); - must_fail(ensure_file_path_normalized("./", NULL, 0)); - must_fail(ensure_file_path_normalized("./.", NULL, 0)); - must_fail(ensure_file_path_normalized("./..", NULL, 0)); - must_fail(ensure_file_path_normalized("../.", NULL, 0)); - must_fail(ensure_file_path_normalized("./.././/", NULL, 0)); - must_fail(ensure_file_path_normalized("dir/..", NULL, 0)); - must_fail(ensure_file_path_normalized("dir/sub/../..", NULL, 0)); - must_fail(ensure_file_path_normalized("dir/sub/..///..", NULL, 0)); - must_fail(ensure_file_path_normalized("dir/sub///../..", NULL, 0)); - must_fail(ensure_file_path_normalized("dir/sub///..///..", NULL, 0)); - must_fail(ensure_file_path_normalized("dir/sub/../../..", NULL, 0)); - must_pass(ensure_file_path_normalized("dir", "dir", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_fail(ensure_file_path_normalized("dir//", NULL, 0)); - must_pass(ensure_file_path_normalized("./dir", "dir", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_fail(ensure_file_path_normalized("dir/.", NULL, 0)); - must_fail(ensure_file_path_normalized("dir///./", NULL, 0)); - must_fail(ensure_file_path_normalized("dir/sub/..", NULL, 0)); - must_fail(ensure_file_path_normalized("dir//sub/..",NULL, 0)); - must_fail(ensure_file_path_normalized("dir//sub/../", NULL, 0)); - must_fail(ensure_file_path_normalized("dir/sub/../", NULL, 0)); - must_fail(ensure_file_path_normalized("dir/sub/../.", NULL, 0)); - must_fail(ensure_file_path_normalized("dir/s1/../s2/", NULL, 0)); - must_fail(ensure_file_path_normalized("d1/s1///s2/..//../s3/", NULL, 0)); - must_pass(ensure_file_path_normalized("d1/s1//../s2/../../d2", "d2", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_fail(ensure_file_path_normalized("dir/sub/../", NULL, 0)); - must_pass(ensure_file_path_normalized("../a/../b/c/d/../../e", "b/e", PATH_AS_SUFFIX)); - must_fail(ensure_file_path_normalized("....", NULL, 0)); - must_fail(ensure_file_path_normalized("...", NULL, 0)); - must_fail(ensure_file_path_normalized("./...", NULL, 0)); - must_fail(ensure_file_path_normalized("d1/...", NULL, 0)); - must_fail(ensure_file_path_normalized("d1/.../", NULL, 0)); - must_fail(ensure_file_path_normalized("d1/.../d2", NULL, 0)); - - must_pass(ensure_file_path_normalized("/a", "/a", ROOTED_PATH)); - must_pass(ensure_file_path_normalized("/./testrepo.git", "/testrepo.git", ROOTED_PATH)); - must_pass(ensure_file_path_normalized("/./.git", "/.git", ROOTED_PATH)); - must_pass(ensure_file_path_normalized("/./git.", "/git.", ROOTED_PATH)); - must_fail(ensure_file_path_normalized("/git./", NULL, 0)); - must_fail(ensure_file_path_normalized("/", NULL, 0)); - must_fail(ensure_file_path_normalized("/.", NULL, 0)); - must_fail(ensure_file_path_normalized("/./", NULL, 0)); - must_fail(ensure_file_path_normalized("/./.", NULL, 0)); - must_fail(ensure_file_path_normalized("/./..", NULL, 0)); - must_fail(ensure_file_path_normalized("/../.", NULL, 0)); - must_fail(ensure_file_path_normalized("/./.././/", NULL, 0)); - must_fail(ensure_file_path_normalized("/dir/..", NULL, 0)); - must_fail(ensure_file_path_normalized("/dir/sub/../..", NULL, 0)); - must_fail(ensure_file_path_normalized("/dir/sub/..///..", NULL, 0)); - must_fail(ensure_file_path_normalized("/dir/sub///../..", NULL, 0)); - must_fail(ensure_file_path_normalized("/dir/sub///..///..", NULL, 0)); - must_fail(ensure_file_path_normalized("/dir/sub/../../..", NULL, 0)); - must_pass(ensure_file_path_normalized("/dir", "/dir", 0)); - must_fail(ensure_file_path_normalized("/dir//", NULL, 0)); - must_pass(ensure_file_path_normalized("/./dir", "/dir", 0)); - must_fail(ensure_file_path_normalized("/dir/.", NULL, 0)); - must_fail(ensure_file_path_normalized("/dir///./", NULL, 0)); - must_fail(ensure_file_path_normalized("/dir/sub/..", NULL, 0)); - must_fail(ensure_file_path_normalized("/dir//sub/..",NULL, 0)); - must_fail(ensure_file_path_normalized("/dir//sub/../", NULL, 0)); - must_fail(ensure_file_path_normalized("/dir/sub/../", NULL, 0)); - must_fail(ensure_file_path_normalized("/dir/sub/../.", NULL, 0)); - must_fail(ensure_file_path_normalized("/dir/s1/../s2/", NULL, 0)); - must_fail(ensure_file_path_normalized("/d1/s1///s2/..//../s3/", NULL, 0)); - must_pass(ensure_file_path_normalized("/d1/s1//../s2/../../d2", "/d2", 0)); - must_fail(ensure_file_path_normalized("/dir/sub/../", NULL, 0)); - must_fail(ensure_file_path_normalized("/....", NULL, 0)); - must_fail(ensure_file_path_normalized("/...", NULL, 0)); - must_fail(ensure_file_path_normalized("/./...", NULL, 0)); - must_fail(ensure_file_path_normalized("/d1/...", NULL, 0)); - must_fail(ensure_file_path_normalized("/d1/.../", NULL, 0)); - must_fail(ensure_file_path_normalized("/d1/.../d2", NULL, 0)); -END_TEST - -BEGIN_TEST(path4, "validate and prettify a path to a folder") - must_pass(ensure_dir_path_normalized("./testrepo.git", "testrepo.git/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("./.git", ".git/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("./git.", "git./", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("git./", "git./", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("", "", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized(".", "", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("./", "", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("./.", "", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir/..", "", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir/sub/../..", "", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir/sub/..///..", "", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir/sub///../..", "", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir/sub///..///..", "", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir", "dir/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir//", "dir/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("./dir", "dir/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir/.", "dir/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir///./", "dir/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir/sub/..", "dir/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir//sub/..", "dir/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir//sub/../", "dir/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir/sub/../", "dir/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir/sub/../.", "dir/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir/s1/../s2/", "dir/s2/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("d1/s1///s2/..//../s3/", "d1/s3/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("d1/s1//../s2/../../d2", "d2/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("dir/sub/../", "dir/", CWD_AS_PREFIX | PATH_AS_SUFFIX)); - must_pass(ensure_dir_path_normalized("../a/../b/c/d/../../e", "b/e/", PATH_AS_SUFFIX)); - must_fail(ensure_dir_path_normalized("....", NULL, 0)); - must_fail(ensure_dir_path_normalized("...", NULL, 0)); - must_fail(ensure_dir_path_normalized("./...", NULL, 0)); - must_fail(ensure_dir_path_normalized("d1/...", NULL, 0)); - must_fail(ensure_dir_path_normalized("d1/.../", NULL, 0)); - must_fail(ensure_dir_path_normalized("d1/.../d2", NULL, 0)); - - must_pass(ensure_dir_path_normalized("/./testrepo.git", "/testrepo.git/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/./.git", "/.git/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/./git.", "/git./", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/git./", "/git./", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/", "/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("//", "/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("///", "/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/.", "/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/./", "/", ROOTED_PATH)); - must_fail(ensure_dir_path_normalized("/./..", NULL, 0)); - must_fail(ensure_dir_path_normalized("/../.", NULL, 0)); - must_fail(ensure_dir_path_normalized("/./.././/", NULL, 0)); - must_pass(ensure_dir_path_normalized("/dir/..", "/", 0)); - must_pass(ensure_dir_path_normalized("/dir/sub/../..", "/", 0)); - must_fail(ensure_dir_path_normalized("/dir/sub/../../..", NULL, 0)); - must_pass(ensure_dir_path_normalized("/dir", "/dir/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/dir//", "/dir/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/./dir", "/dir/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/dir/.", "/dir/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/dir///./", "/dir/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/dir//sub/..", "/dir/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/dir/sub/../", "/dir/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("//dir/sub/../.", "/dir/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/dir/s1/../s2/", "/dir/s2/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/d1/s1///s2/..//../s3/", "/d1/s3/", ROOTED_PATH)); - must_pass(ensure_dir_path_normalized("/d1/s1//../s2/../../d2", "/d2/", ROOTED_PATH)); - must_fail(ensure_dir_path_normalized("/....", NULL, 0)); - must_fail(ensure_dir_path_normalized("/...", NULL, 0)); - must_fail(ensure_dir_path_normalized("/./...", NULL, 0)); - must_fail(ensure_dir_path_normalized("/d1/...", NULL, 0)); - must_fail(ensure_dir_path_normalized("/d1/.../", NULL, 0)); - must_fail(ensure_dir_path_normalized("/d1/.../d2", NULL, 0)); -END_TEST - static int ensure_joinpath(const char *path_a, const char *path_b, const char *expected_path) { char joined_path[GIT_PATH_MAX]; @@ -390,37 +190,6 @@ BEGIN_TEST(path6, "properly join path components for more than one path") must_pass(ensure_joinpath_n("a", "b", "", "/c/d", "a/b/c/d")); END_TEST -static int count_number_of_path_segments(const char *path) -{ - int number = 0; - char *current = (char *)path; - - while (*current) - { - if (*current++ == '/') - number++; - } - - assert (number > 0); - - return --number; -} - -BEGIN_TEST(path7, "prevent a path which escapes the root directory from being prettified") - char current_workdir[GIT_PATH_MAX]; - char prettified[GIT_PATH_MAX]; - int i = 0, number_to_escape; - - must_pass(p_getcwd(current_workdir, sizeof(current_workdir))); - - number_to_escape = count_number_of_path_segments(current_workdir); - - for (i = 0; i < number_to_escape + 1; i++) - git_path_join(current_workdir, current_workdir, "../"); - - must_fail(git_futils_prettify_dir(prettified, sizeof(prettified), current_workdir, NULL)); -END_TEST - typedef struct name_data { int count; /* return count */ char *name; /* filename */ @@ -715,11 +484,8 @@ BEGIN_SUITE(core) ADD_TEST(path0); ADD_TEST(path1); ADD_TEST(path2); - ADD_TEST(path3); - ADD_TEST(path4); ADD_TEST(path5); ADD_TEST(path6); - ADD_TEST(path7); ADD_TEST(dirent0); ADD_TEST(dirent1); diff --git a/tests/t12-repo.c b/tests/t12-repo.c index 4881e758f..6d897a14e 100644 --- a/tests/t12-repo.c +++ b/tests/t12-repo.c @@ -374,7 +374,7 @@ static int append_ceiling_dir(char *ceiling_dirs, const char *path) int len = strlen(ceiling_dirs); int error; - error = git_futils_prettify_dir(ceiling_dirs + len + (len ? 1 : 0), GIT_PATH_MAX, path, NULL); + error = git_path_prettify_dir(ceiling_dirs + len + (len ? 1 : 0), path, NULL); if (error < GIT_SUCCESS) return git__rethrow(error, "Failed to append ceiling directory."); |