]>
git.proxmox.com Git - libgit2.git/blob - tests/core/stat.c
1 #include "clar_libgit2.h"
5 void test_core_stat__initialize(void)
7 cl_git_pass(git_futils_mkdir("root/d1/d2", 0755, GIT_MKDIR_PATH
));
8 cl_git_mkfile("root/file", "whatever\n");
9 cl_git_mkfile("root/d1/file", "whatever\n");
12 void test_core_stat__cleanup(void)
14 git_futils_rmdir_r("root", NULL
, GIT_RMDIR_REMOVE_FILES
);
17 #define cl_assert_error(val) \
18 do { err = errno; cl_assert_equal_i((val), err); } while (0)
20 void test_core_stat__0(void)
25 cl_assert_equal_i(0, p_lstat("root", &st
));
26 cl_assert(S_ISDIR(st
.st_mode
));
29 cl_assert_equal_i(0, p_lstat("root/", &st
));
30 cl_assert(S_ISDIR(st
.st_mode
));
33 cl_assert_equal_i(0, p_lstat("root/file", &st
));
34 cl_assert(S_ISREG(st
.st_mode
));
37 cl_assert_equal_i(0, p_lstat("root/d1", &st
));
38 cl_assert(S_ISDIR(st
.st_mode
));
41 cl_assert_equal_i(0, p_lstat("root/d1/", &st
));
42 cl_assert(S_ISDIR(st
.st_mode
));
45 cl_assert_equal_i(0, p_lstat("root/d1/file", &st
));
46 cl_assert(S_ISREG(st
.st_mode
));
49 cl_assert(p_lstat("root/missing", &st
) < 0);
50 cl_assert_error(ENOENT
);
52 cl_assert(p_lstat("root/missing/but/could/be/created", &st
) < 0);
53 cl_assert_error(ENOENT
);
55 cl_assert(p_lstat_posixly("root/missing/but/could/be/created", &st
) < 0);
56 cl_assert_error(ENOENT
);
58 cl_assert(p_lstat("root/d1/missing", &st
) < 0);
59 cl_assert_error(ENOENT
);
61 cl_assert(p_lstat("root/d1/missing/deeper/path", &st
) < 0);
62 cl_assert_error(ENOENT
);
64 cl_assert(p_lstat_posixly("root/d1/missing/deeper/path", &st
) < 0);
65 cl_assert_error(ENOENT
);
67 cl_assert(p_lstat_posixly("root/d1/file/deeper/path", &st
) < 0);
68 cl_assert_error(ENOTDIR
);
70 cl_assert(p_lstat("root/file/invalid", &st
) < 0);
72 cl_assert_error(ENOENT
);
74 cl_assert_error(ENOTDIR
);
77 cl_assert(p_lstat_posixly("root/file/invalid", &st
) < 0);
78 cl_assert_error(ENOTDIR
);
80 cl_assert(p_lstat("root/file/invalid/deeper_path", &st
) < 0);
82 cl_assert_error(ENOENT
);
84 cl_assert_error(ENOTDIR
);
87 cl_assert(p_lstat_posixly("root/file/invalid/deeper_path", &st
) < 0);
88 cl_assert_error(ENOTDIR
);
90 cl_assert(p_lstat_posixly("root/d1/file/extra", &st
) < 0);
91 cl_assert_error(ENOTDIR
);
93 cl_assert(p_lstat_posixly("root/d1/file/further/invalid/items", &st
) < 0);
94 cl_assert_error(ENOTDIR
);
97 void test_core_stat__root(void)
99 const char *sandbox
= clar_sandbox_path();
100 git_str root
= GIT_STR_INIT
;
104 root_len
= git_fs_path_root(sandbox
);
105 cl_assert(root_len
>= 0);
107 git_str_set(&root
, sandbox
, root_len
+1);
109 cl_must_pass(p_stat(root
.ptr
, &st
));
110 cl_assert(S_ISDIR(st
.st_mode
));
112 git_str_dispose(&root
);