blob: 70d6950f8b09922a04aea49249fee4def57c768f [file] [log] [blame]
Jeffrey Yasskin1d75d3a2009-09-24 01:14:07 +00001//===- 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
17using namespace llvm;
18
19namespace {
20
21class 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
38const char test_env_var[] = "LLVM_TEST_COMMAND_LINE_FLAGS";
39
40cl::opt<std::string> EnvironmentTestOption("env-test-opt");
41TEST(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