Jeffrey Yasskin | 1d75d3a | 2009-09-24 01:14:07 +0000 | [diff] [blame^] | 1 | //===- llvm/unittest/Support/CommandLineTest.cpp - CommandLine tests ------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "llvm/Support/CommandLine.h" |
| 11 | |
| 12 | #include "gtest/gtest.h" |
| 13 | |
| 14 | #include <string> |
| 15 | #include <stdlib.h> |
| 16 | |
| 17 | using namespace llvm; |
| 18 | |
| 19 | namespace { |
| 20 | |
| 21 | class TempEnvVar { |
| 22 | public: |
| 23 | TempEnvVar(const char *name, const char *value) |
| 24 | : name(name) { |
| 25 | const char *old_value = getenv(name); |
| 26 | EXPECT_EQ(NULL, old_value) << old_value; |
| 27 | setenv(name, value, true); |
| 28 | } |
| 29 | |
| 30 | ~TempEnvVar() { |
| 31 | unsetenv(name); |
| 32 | } |
| 33 | |
| 34 | private: |
| 35 | const char *const name; |
| 36 | }; |
| 37 | |
| 38 | const char test_env_var[] = "LLVM_TEST_COMMAND_LINE_FLAGS"; |
| 39 | |
| 40 | cl::opt<std::string> EnvironmentTestOption("env-test-opt"); |
| 41 | TEST(CommandLineTest, ParseEnvironment) { |
| 42 | TempEnvVar TEV(test_env_var, "-env-test-opt=hello"); |
| 43 | EXPECT_EQ("", EnvironmentTestOption); |
| 44 | cl::ParseEnvironmentOptions("CommandLineTest", test_env_var); |
| 45 | EXPECT_EQ("hello", EnvironmentTestOption); |
| 46 | } |
| 47 | |
| 48 | } // anonymous namespace |