Commit e068f2bb71c647c19713fd9fb53596c7eeddc777

Philip Kelley 2012-11-01T11:50:08

Fix a bug in cl_setenv on Windows XP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/tests-clar/clar_helpers.c b/tests-clar/clar_helpers.c
index 647ea52..250c922 100644
--- a/tests-clar/clar_helpers.c
+++ b/tests-clar/clar_helpers.c
@@ -89,7 +89,11 @@ int cl_setenv(const char *name, const char *value)
 	if (value != NULL)
 		git__utf8_to_16(value_utf16, GIT_WIN_PATH, value);
 
-	cl_assert(SetEnvironmentVariableW(name_utf16, value ? value_utf16 : NULL));
+	/* Windows XP returns 0 (failed) when passing NULL for lpValue when lpName
+	 * does not exist in the environment block. This behavior seems to have changed
+	 * in later versions. Don't fail when SetEnvironmentVariable fails, if we passed
+	 * NULL for lpValue. */
+	cl_assert(SetEnvironmentVariableW(name_utf16, value ? value_utf16 : NULL) || !value);
 	return 0;
 }