summaryrefslogtreecommitdiff
path: root/unittests/Support/CommandLineTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/Support/CommandLineTest.cpp')
-rw-r--r--unittests/Support/CommandLineTest.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/unittests/Support/CommandLineTest.cpp b/unittests/Support/CommandLineTest.cpp
index 70d6950f8b..72fa24a5ac 100644
--- a/unittests/Support/CommandLineTest.cpp
+++ b/unittests/Support/CommandLineTest.cpp
@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/CommandLine.h"
+#include "llvm/Config/config.h"
#include "gtest/gtest.h"
@@ -24,17 +25,26 @@ class TempEnvVar {
: name(name) {
const char *old_value = getenv(name);
EXPECT_EQ(NULL, old_value) << old_value;
+#if HAVE_SETENV
setenv(name, value, true);
+#else
+# define SKIP_ENVIRONMENT_TESTS
+#endif
}
~TempEnvVar() {
+#if HAVE_SETENV
+ // Assume setenv and unsetenv come together.
unsetenv(name);
+#endif
}
private:
const char *const name;
};
+#ifndef SKIP_ENVIRONMENT_TESTS
+
const char test_env_var[] = "LLVM_TEST_COMMAND_LINE_FLAGS";
cl::opt<std::string> EnvironmentTestOption("env-test-opt");
@@ -45,4 +55,6 @@ TEST(CommandLineTest, ParseEnvironment) {
EXPECT_EQ("hello", EnvironmentTestOption);
}
+#endif // SKIP_ENVIRONMENT_TESTS
+
} // anonymous namespace