Commit 780f3e54 by Russell Belfer

Make tests take umask into account

It seems that libgit2 is correctly applying the umask when
initializing a repository from a template and when creating new
directories during checkout, but the test suite is not accounting
for possible variations due to the umask.  This updates that so
that the test suite will work regardless of the umask.
parent cf94024c
......@@ -229,6 +229,7 @@ void test_checkout_index__options_dir_modes(void)
struct stat st;
git_oid oid;
git_commit *commit;
mode_t um;
cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
......@@ -240,12 +241,15 @@ void test_checkout_index__options_dir_modes(void)
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
/* umask will influence actual directory creation mode */
(void)p_umask(um = p_umask(022));
cl_git_pass(p_stat("./testrepo/a", &st));
cl_assert_equal_i(st.st_mode & 0777, 0701);
cl_assert_equal_i_fmt(st.st_mode, GIT_FILEMODE_TREE | 0701 & ~um, "%07o");
/* File-mode test, since we're on the 'dir' branch */
cl_git_pass(p_stat("./testrepo/a/b.txt", &st));
cl_assert_equal_i(st.st_mode & 0777, 0755);
cl_assert_equal_i_fmt(st.st_mode, GIT_FILEMODE_BLOB_EXECUTABLE, "%07o");
git_commit_free(commit);
#endif
......@@ -263,7 +267,7 @@ void test_checkout_index__options_override_file_modes(void)
cl_git_pass(git_checkout_index(g_repo, NULL, &opts));
cl_git_pass(p_stat("./testrepo/new.txt", &st));
cl_assert_equal_i(st.st_mode & 0777, 0700);
cl_assert_equal_i_fmt(st.st_mode & 0777, 0700, "%07o");
#endif
}
......
......@@ -32,7 +32,7 @@ void cl_git_report_failure(int, const char *, int, const char *);
#define cl_assert_at_line(expr,file,line) \
clar__assert((expr) != 0, file, line, "Expression is not true: " #expr, NULL, 1)
#define cl_assert_equal_sz(sz1,sz2) cl_assert_equal_i((int)sz1, (int)(sz2))
#define cl_assert_equal_sz(sz1,sz2) clar__assert_equal(__FILE__,__LINE__,#sz1 " != " #sz2, 1, PRIuZ, (size_t)(sz1), (size_t)(sz2))
GIT_INLINE(void) clar__assert_in_range(
int lo, int val, int hi,
......
......@@ -10,10 +10,17 @@ enum repo_mode {
};
static git_repository *_repo = NULL;
static mode_t _umask = 0;
void test_repo_init__initialize(void)
{
_repo = NULL;
/* load umask if not already loaded */
if (!_umask) {
_umask = p_umask(022);
(void)p_umask(_umask);
}
}
static void cleanup_repository(void *path)
......@@ -377,14 +384,18 @@ static void assert_hooks_match(
cl_git_pass(git_buf_joinpath(&actual, repo_dir, hook_path));
cl_git_pass(git_path_lstat(actual.ptr, &st));
cl_assert(expected_st.st_size == st.st_size);
cl_assert_equal_sz(expected_st.st_size, st.st_size);
expected_st.st_mode =
(expected_st.st_mode & ~0777) |
(((expected_st.st_mode & 0111) ? 0100777 : 0100666) & ~_umask);
if (!core_filemode) {
expected_st.st_mode = expected_st.st_mode & ~0111;
st.st_mode = st.st_mode & ~0111;
}
cl_assert_equal_i((int)expected_st.st_mode, (int)st.st_mode);
cl_assert_equal_i_fmt(expected_st.st_mode, st.st_mode, "%07o");
git_buf_free(&expected);
git_buf_free(&actual);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment