summaryrefslogtreecommitdiff
path: root/tests-clar
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-10-03 15:16:06 -0700
committerRussell Belfer <rb@github.com>2013-10-03 15:16:06 -0700
commitb8f9059d6330d1b0113910eb4c6f049ea5a150a4 (patch)
tree390c233048cc0948eba0b2491bcb51ed1cb61abe /tests-clar
parent840fb4fc4346580a6398856b3fa2f1226b3a365d (diff)
downloadlibgit2-b8f9059d6330d1b0113910eb4c6f049ea5a150a4.tar.gz
More cleanups to remove WIN assumptions
This cleans up more of the test suite to check actual filesystem behavior instead of relying on Windows vs. Mac vs. Linux to test.
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/checkout/index.c10
-rw-r--r--tests-clar/core/mkdir.c20
-rw-r--r--tests-clar/repo/init.c17
3 files changed, 22 insertions, 25 deletions
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c
index 73050d08e..48d6d79f9 100644
--- a/tests-clar/checkout/index.c
+++ b/tests-clar/checkout/index.c
@@ -224,13 +224,15 @@ void test_checkout_index__options_disable_filters(void)
void test_checkout_index__options_dir_modes(void)
{
-#ifndef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
struct stat st;
git_oid oid;
git_commit *commit;
mode_t um;
+ if (!cl_is_chmod_supported())
+ return;
+
cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir"));
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
@@ -252,15 +254,16 @@ void test_checkout_index__options_dir_modes(void)
cl_assert_equal_i_fmt(st.st_mode, GIT_FILEMODE_BLOB_EXECUTABLE, "%07o");
git_commit_free(commit);
-#endif
}
void test_checkout_index__options_override_file_modes(void)
{
-#ifndef GIT_WIN32
git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
struct stat st;
+ if (!cl_is_chmod_supported())
+ return;
+
opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
opts.file_mode = 0700;
@@ -268,7 +271,6 @@ void test_checkout_index__options_override_file_modes(void)
cl_git_pass(p_stat("./testrepo/new.txt", &st));
cl_assert_equal_i_fmt(st.st_mode & GIT_MODE_PERMS_MASK, 0700, "%07o");
-#endif
}
void test_checkout_index__options_open_flags(void)
diff --git a/tests-clar/core/mkdir.c b/tests-clar/core/mkdir.c
index a969e4de2..a8c5b10ae 100644
--- a/tests-clar/core/mkdir.c
+++ b/tests-clar/core/mkdir.c
@@ -111,14 +111,20 @@ static void cleanup_chmod_root(void *ref)
git_futils_rmdir_r("r", NULL, GIT_RMDIR_EMPTY_HIERARCHY);
}
-static void check_mode(mode_t expected, mode_t actual)
+#define check_mode(X,A) check_mode_at_line((X), (A), __FILE__, __LINE__)
+
+static void check_mode_at_line(
+ mode_t expected, mode_t actual, const char *file, int line)
{
-#ifdef GIT_WIN32
- /* chmod on Win32 doesn't support exec bit, not group/world bits */
- cl_assert_equal_i_fmt((expected & 0600), (actual & 0777), "%07o");
-#else
- cl_assert_equal_i_fmt(expected, (actual & 0777), "%07o");
-#endif
+ /* FAT filesystems don't support exec bit, nor group/world bits */
+ if (!cl_is_chmod_supported()) {
+ expected &= 0600;
+ actual &= 0600;
+ }
+
+ clar__assert_equal(
+ file, line, "expected_mode != actual_mode", 1,
+ "%07o", (int)expected, (int)(actual & 0777));
}
void test_core_mkdir__chmods(void)
diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c
index 061e444b5..617fdf879 100644
--- a/tests-clar/repo/init.c
+++ b/tests-clar/repo/init.c
@@ -212,20 +212,9 @@ static void assert_config_entry_on_init(
assert_config_entry_on_init_bytype(config_key, expected_value, false);
}
-static int expect_filemode_support(void)
-{
- struct stat st;
-
- cl_git_write2file("testmode", "whatever\n", 0, O_CREAT | O_WRONLY, 0767);
- cl_must_pass(p_stat("testmode", &st));
- cl_must_pass(p_unlink("testmode"));
-
- return (st.st_mode & 0111) == 0101;
-}
-
void test_repo_init__detect_filemode(void)
{
- assert_config_entry_on_init("core.filemode", expect_filemode_support());
+ assert_config_entry_on_init("core.filemode", cl_is_chmod_supported());
}
void test_repo_init__detect_ignorecase(void)
@@ -287,7 +276,7 @@ void test_repo_init__reinit_doesnot_overwrite_ignorecase(void)
void test_repo_init__reinit_overwrites_filemode(void)
{
- int expected = expect_filemode_support(), current_value;
+ int expected = cl_is_chmod_supported(), current_value;
/* Init a new repo */
cl_set_cleanup(&cleanup_repository, "overwrite.git");
@@ -359,7 +348,7 @@ void test_repo_init__extended_1(void)
cl_git_pass(git_path_lstat(git_repository_path(_repo), &st));
cl_assert(S_ISDIR(st.st_mode));
- if (expect_filemode_support())
+ if (cl_is_chmod_supported())
cl_assert((S_ISGID & st.st_mode) == S_ISGID);
else
cl_assert((S_ISGID & st.st_mode) == 0);