]>
git.proxmox.com Git - libgit2.git/blob - tests/core/stat.c
59a13464938a2b74587831b22e0a000a20379b42
1 #include "clar_libgit2.h"
6 void test_core_stat__initialize(void)
8 cl_git_pass(git_futils_mkdir("root/d1/d2", 0755, GIT_MKDIR_PATH
));
9 cl_git_mkfile("root/file", "whatever\n");
10 cl_git_mkfile("root/d1/file", "whatever\n");
13 void test_core_stat__cleanup(void)
15 git_futils_rmdir_r("root", NULL
, GIT_RMDIR_REMOVE_FILES
);
18 #define cl_assert_error(val) \
19 do { err = errno; cl_assert_equal_i((val), err); } while (0)
21 void test_core_stat__0(void)
26 cl_assert_equal_i(0, p_lstat("root", &st
));
27 cl_assert(S_ISDIR(st
.st_mode
));
30 cl_assert_equal_i(0, p_lstat("root/", &st
));
31 cl_assert(S_ISDIR(st
.st_mode
));
34 cl_assert_equal_i(0, p_lstat("root/file", &st
));
35 cl_assert(S_ISREG(st
.st_mode
));
38 cl_assert_equal_i(0, p_lstat("root/d1", &st
));
39 cl_assert(S_ISDIR(st
.st_mode
));
42 cl_assert_equal_i(0, p_lstat("root/d1/", &st
));
43 cl_assert(S_ISDIR(st
.st_mode
));
46 cl_assert_equal_i(0, p_lstat("root/d1/file", &st
));
47 cl_assert(S_ISREG(st
.st_mode
));
50 cl_assert(p_lstat("root/missing", &st
) < 0);
51 cl_assert_error(ENOENT
);
53 cl_assert(p_lstat("root/missing/but/could/be/created", &st
) < 0);
54 cl_assert_error(ENOENT
);
56 cl_assert(p_lstat_posixly("root/missing/but/could/be/created", &st
) < 0);
57 cl_assert_error(ENOENT
);
59 cl_assert(p_lstat("root/d1/missing", &st
) < 0);
60 cl_assert_error(ENOENT
);
62 cl_assert(p_lstat("root/d1/missing/deeper/path", &st
) < 0);
63 cl_assert_error(ENOENT
);
65 cl_assert(p_lstat_posixly("root/d1/missing/deeper/path", &st
) < 0);
66 cl_assert_error(ENOENT
);
68 cl_assert(p_lstat_posixly("root/d1/file/deeper/path", &st
) < 0);
69 cl_assert_error(ENOTDIR
);
71 cl_assert(p_lstat("root/file/invalid", &st
) < 0);
73 cl_assert_error(ENOENT
);
75 cl_assert_error(ENOTDIR
);
78 cl_assert(p_lstat_posixly("root/file/invalid", &st
) < 0);
79 cl_assert_error(ENOTDIR
);
81 cl_assert(p_lstat("root/file/invalid/deeper_path", &st
) < 0);
83 cl_assert_error(ENOENT
);
85 cl_assert_error(ENOTDIR
);
88 cl_assert(p_lstat_posixly("root/file/invalid/deeper_path", &st
) < 0);
89 cl_assert_error(ENOTDIR
);
91 cl_assert(p_lstat_posixly("root/d1/file/extra", &st
) < 0);
92 cl_assert_error(ENOTDIR
);
94 cl_assert(p_lstat_posixly("root/d1/file/further/invalid/items", &st
) < 0);
95 cl_assert_error(ENOTDIR
);
98 void test_core_stat__root(void)
100 const char *sandbox
= clar_sandbox_path();
101 git_buf root
= GIT_BUF_INIT
;
105 root_len
= git_path_root(sandbox
);
106 cl_assert(root_len
>= 0);
108 git_buf_set(&root
, sandbox
, root_len
+1);
110 cl_must_pass(p_stat(root
.ptr
, &st
));
111 cl_assert(S_ISDIR(st
.st_mode
));
113 git_buf_dispose(&root
);