Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-03-19 01:19:35 +0400
committerRussell Belfer <rb@github.com>2013-03-19 01:19:35 +0400
commit41954a49c12a72eda3b3fe02c2752f6831b5dbf9 (patch)
tree4b9cff17fbd7172efddde4dba8e1d2f6b31e0c45 /tests-clar/core
parent5540d9477ed143707435324e785336d254b12e47 (diff)
Switch search paths to classic delimited strings
This switches the APIs for setting and getting the global/system search paths from using git_strarray to using a simple string with GIT_PATH_LIST_SEPARATOR delimited paths, just as the environment PATH variable would contain. This makes it simpler to get and set the value. I also added code to expand "$PATH" when setting a new value to embed the old value of the path. This means that I no longer require separate actions to PREPEND to the value.
Diffstat (limited to 'tests-clar/core')
-rw-r--r--tests-clar/core/env.c89
1 files changed, 64 insertions, 25 deletions
diff --git a/tests-clar/core/env.c b/tests-clar/core/env.c
index 7c36f3998..d684f4ca0 100644
--- a/tests-clar/core/env.c
+++ b/tests-clar/core/env.c
@@ -29,8 +29,24 @@ static char *home_values[] = {
void test_core_env__initialize(void)
{
int i;
- for (i = 0; i < NUM_VARS; ++i)
- env_save[i] = cl_getenv(env_vars[i]);
+ for (i = 0; i < NUM_VARS; ++i) {
+ const char *original = cl_getenv(env_vars[i]);
+#ifdef GIT_WIN32
+ env_save[i] = original;
+#else
+ env_save[i] = original ? git__strdup(original) : NULL;
+#endif
+ }
+}
+
+static void reset_global_search_path(void)
+{
+ cl_git_pass(git_futils_dirs_set(GIT_FUTILS_DIR_GLOBAL, NULL));
+}
+
+static void reset_system_search_path(void)
+{
+ cl_git_pass(git_futils_dirs_set(GIT_FUTILS_DIR_SYSTEM, NULL));
}
void test_core_env__cleanup(void)
@@ -40,9 +56,7 @@ void test_core_env__cleanup(void)
for (i = 0; i < NUM_VARS; ++i) {
cl_setenv(env_vars[i], env_save[i]);
-#ifdef GIT_WIN32
git__free(env_save[i]);
-#endif
env_save[i] = NULL;
}
@@ -55,8 +69,8 @@ void test_core_env__cleanup(void)
}
/* reset search paths to default */
- git_futils_dirs_set(GIT_FUTILS_DIR_GLOBAL, NULL, true);
- git_futils_dirs_set(GIT_FUTILS_DIR_SYSTEM, NULL, true);
+ reset_global_search_path();
+ reset_system_search_path();
}
static void setenv_and_check(const char *name, const char *value)
@@ -64,21 +78,10 @@ static void setenv_and_check(const char *name, const char *value)
char *check;
cl_git_pass(cl_setenv(name, value));
+
check = cl_getenv(name);
cl_assert_equal_s(value, check);
-#ifdef GIT_WIN32
git__free(check);
-#endif
-}
-
-static void reset_global_search_path(void)
-{
- cl_git_pass(git_futils_dirs_set(GIT_FUTILS_DIR_GLOBAL, NULL, true));
-}
-
-static void reset_system_search_path(void)
-{
- cl_git_pass(git_futils_dirs_set(GIT_FUTILS_DIR_SYSTEM, NULL, true));
}
void test_core_env__0(void)
@@ -216,7 +219,7 @@ void test_core_env__2(void)
char **val;
const char *testname = "alternate";
size_t testlen = strlen(testname);
- git_strarray arr;
+ char out[GIT_PATH_MAX];
strncpy(testfile, testname, sizeof(testfile));
cl_assert_equal_s(testname, testfile);
@@ -227,7 +230,7 @@ void test_core_env__2(void)
* we are on a filesystem that doesn't support the
* characters in question and skip this test...
*/
- if (p_mkdir(*val, 0777) != 0) {
+ if (p_mkdir(*val, 0777) != 0 && errno != EEXIST) {
*val = ""; /* mark as not created */
continue;
}
@@ -243,31 +246,67 @@ void test_core_env__2(void)
cl_git_mkfile(path.ptr, "find me");
git_buf_rtruncate_at_char(&path, '/');
- arr.count = 1;
- arr.strings = &path.ptr;
-
+ /* default should be NOTFOUND */
cl_assert_equal_i(
GIT_ENOTFOUND, git_futils_find_global_file(&found, testfile));
+ /* set search path */
+ cl_git_pass(git_libgit2_opts(
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
+
cl_git_pass(git_libgit2_opts(
- GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &arr));
+ GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, out, sizeof(out)));
+ cl_assert_equal_s(out, path.ptr);
cl_git_pass(git_futils_find_global_file(&found, testfile));
+ /* reset */
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, NULL));
+ cl_assert_equal_i(
+ GIT_ENOTFOUND, git_futils_find_global_file(&found, testfile));
+
+ /* try prepend behavior */
+ cl_git_pass(git_buf_putc(&path, GIT_PATH_LIST_SEPARATOR));
+ cl_git_pass(git_buf_puts(&path, "$PATH"));
+
+ cl_git_pass(git_libgit2_opts(
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
+ git_buf_rtruncate_at_char(&path, GIT_PATH_LIST_SEPARATOR);
+
+ cl_git_pass(git_libgit2_opts(
+ GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, out, sizeof(out)));
+ cl_assert(git__prefixcmp(out, path.ptr) == 0);
+
+ cl_git_pass(git_futils_find_global_file(&found, testfile));
+
+ /* reset */
+ cl_git_pass(git_libgit2_opts(
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, NULL));
cl_assert_equal_i(
GIT_ENOTFOUND, git_futils_find_global_file(&found, testfile));
+ /* try append behavior */
+ cl_git_pass(git_buf_join(
+ &found, GIT_PATH_LIST_SEPARATOR, "$PATH", path.ptr));
+
+ cl_git_pass(git_libgit2_opts(
+ GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, found.ptr));
+
cl_git_pass(git_libgit2_opts(
- GIT_OPT_PREPEND_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &arr));
+ GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, out, sizeof(out)));
+ cl_assert(git__suffixcmp(out, path.ptr) == 0);
cl_git_pass(git_futils_find_global_file(&found, testfile));
+ /* reset */
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, NULL));
+ cl_git_pass(git_buf_joinpath(&path, path.ptr, testfile));
+ (void)p_unlink(path.ptr);
+
(void)p_rmdir(*val);
}