Fix tests to use portable setenv
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
diff --git a/tests/t15-config.c b/tests/t15-config.c
index fdfa092..d912abb 100644
--- a/tests/t15-config.c
+++ b/tests/t15-config.c
@@ -26,6 +26,7 @@
#include "test_helpers.h"
#include <git2.h>
+#include <posix.h>
#include "filebuf.h"
#define CONFIG_BASE TEST_RESOURCES "/config"
@@ -217,7 +218,7 @@ BEGIN_TEST(config10, "a repo's config overrides the global config")
char *old_home;
old_home = git__strdup(getenv("HOME"));
- setenv("HOME", CONFIG_BASE, 1);
+ p_setenv("HOME", CONFIG_BASE, 1);
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_config(&cfg, repo, NULL));
@@ -226,7 +227,7 @@ BEGIN_TEST(config10, "a repo's config overrides the global config")
git_config_free(cfg);
git_repository_free(repo);
- setenv("HOME", old_home, 1);
+ p_setenv("HOME", old_home, 1);
free(old_home);
END_TEST
@@ -237,7 +238,7 @@ BEGIN_TEST(config11, "fall back to the global config")
char *old_home;
old_home = git__strdup(getenv("HOME"));
- setenv("HOME", CONFIG_BASE, 1);
+ p_setenv("HOME", CONFIG_BASE, 1);
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_config(&cfg, repo, NULL));
@@ -246,7 +247,7 @@ BEGIN_TEST(config11, "fall back to the global config")
git_config_free(cfg);
git_repository_free(repo);
- setenv("HOME", old_home, 1);
+ p_setenv("HOME", old_home, 1);
free(old_home);
END_TEST
diff --git a/tests/t16-remotes.c b/tests/t16-remotes.c
index 6529f0e..af54f29 100644
--- a/tests/t16-remotes.c
+++ b/tests/t16-remotes.c
@@ -26,6 +26,7 @@
#include "test_helpers.h"
#include <git2.h>
+#include <posix.h>
BEGIN_TEST(remotes0, "remote parsing works")
git_remote *remote;
@@ -34,7 +35,7 @@ BEGIN_TEST(remotes0, "remote parsing works")
char *old_home;
old_home = git__strdup(getenv("HOME"));
- setenv("HOME", "/dev/null", 1);
+ p_setenv("HOME", "/dev/null", 1);
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_config(&cfg, repo, NULL));
@@ -46,7 +47,7 @@ BEGIN_TEST(remotes0, "remote parsing works")
git_config_free(cfg);
git_repository_free(repo);
- setenv("HOME", old_home, 1);
+ p_setenv("HOME", old_home, 1);
free(old_home);
END_TEST
@@ -58,7 +59,7 @@ BEGIN_TEST(refspec0, "remote with refspec works")
char *old_home;
old_home = git__strdup(getenv("HOME"));
- setenv("HOME", "/dev/null", 1);
+ p_setenv("HOME", "/dev/null", 1);
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_config(&cfg, repo, NULL));
@@ -71,7 +72,7 @@ BEGIN_TEST(refspec0, "remote with refspec works")
git_config_free(cfg);
git_repository_free(repo);
- setenv("HOME", old_home, 1);
+ p_setenv("HOME", old_home, 1);
free(old_home);
END_TEST
@@ -83,7 +84,7 @@ BEGIN_TEST(refspec1, "remote fnmatch works as expected")
char *old_home;
old_home = git__strdup(getenv("HOME"));
- setenv("HOME", "/dev/null", 1);
+ p_setenv("HOME", "/dev/null", 1);
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_config(&cfg, repo, NULL));
@@ -96,7 +97,7 @@ BEGIN_TEST(refspec1, "remote fnmatch works as expected")
git_config_free(cfg);
git_repository_free(repo);
- setenv("HOME", old_home, 1);
+ p_setenv("HOME", old_home, 1);
free(old_home);
END_TEST
@@ -109,7 +110,7 @@ BEGIN_TEST(refspec2, "refspec transform")
char *old_home;
old_home = git__strdup(getenv("HOME"));
- setenv("HOME", "/dev/null", 1);
+ p_setenv("HOME", "/dev/null", 1);
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
must_pass(git_repository_config(&cfg, repo, NULL));
@@ -122,7 +123,7 @@ BEGIN_TEST(refspec2, "refspec transform")
git_config_free(cfg);
git_repository_free(repo);
- setenv("HOME", old_home, 1);
+ p_setenv("HOME", old_home, 1);
free(old_home);
END_TEST