summaryrefslogtreecommitdiff
path: root/tests-clar
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2012-05-25 09:44:56 -0700
committerRussell Belfer <rb@github.com>2012-05-25 09:44:56 -0700
commit29ef309e2ca39f68d11c755710446ff6d396d203 (patch)
treee026edd7b00baea86a34dddc769b894e4c155557 /tests-clar
parent4728b55ac66cde7f8c104f0a8cc350d96a530f33 (diff)
downloadlibgit2-29ef309e2ca39f68d11c755710446ff6d396d203.tar.gz
Make errors for system and global files consistent
The error codes from failed lookups of system and global files on Windows were not consistent with the codes returned on other platforms. This makes the error detection patterns match and adds a unit test for the various errors.
Diffstat (limited to 'tests-clar')
-rw-r--r--tests-clar/core/env.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests-clar/core/env.c b/tests-clar/core/env.c
index fb483e89e..3bde85649 100644
--- a/tests-clar/core/env.c
+++ b/tests-clar/core/env.c
@@ -54,6 +54,7 @@ static int cl_setenv(const char *name, const char *value)
#ifdef GIT_WIN32
static char *env_userprofile = NULL;
+static char *env_programfiles = NULL;
#else
static char *env_home = NULL;
#endif
@@ -62,6 +63,7 @@ void test_core_env__initialize(void)
{
#ifdef GIT_WIN32
env_userprofile = cl_getenv("USERPROFILE");
+ env_programfiles = cl_getenv("PROGRAMFILES");
#else
env_home = cl_getenv("HOME");
#endif
@@ -72,6 +74,8 @@ void test_core_env__cleanup(void)
#ifdef GIT_WIN32
cl_setenv("USERPROFILE", env_userprofile);
git__free(env_userprofile);
+ cl_setenv("PROGRAMFILES", env_programfiles);
+ git__free(env_programfiles);
#else
cl_setenv("HOME", env_home);
#endif
@@ -128,3 +132,34 @@ void test_core_env__0(void)
git_buf_free(&path);
git_buf_free(&found);
}
+
+void test_core_env__1(void)
+{
+ git_buf path = GIT_BUF_INIT;
+
+ cl_assert(git_futils_find_global_file(&path, "nonexistentfile") == GIT_ENOTFOUND);
+
+#ifdef GIT_WIN32
+ cl_git_pass(cl_setenv("USERPROFILE", "doesnotexist"));
+#else
+ cl_git_pass(cl_setenv("HOME", "doesnotexist"));
+#endif
+
+ cl_assert(git_futils_find_global_file(&path, "nonexistentfile") == GIT_ENOTFOUND);
+
+#ifdef GIT_WIN32
+ cl_git_pass(cl_setenv("USERPROFILE", NULL));
+#else
+ cl_git_pass(cl_setenv("HOME", NULL));
+#endif
+
+ cl_assert(git_futils_find_global_file(&path, "nonexistentfile") == -1);
+
+ cl_assert(git_futils_find_system_file(&path, "nonexistentfile") == GIT_ENOTFOUND);
+
+#ifdef GIT_WIN32
+ cl_git_pass(cl_setenv("PROGRAMFILES", NULL));
+
+ cl_assert(git_futils_find_system_file(&path, "nonexistentfile") == -1);
+#endif
+}