1 //===-- EnvironmentTest.cpp -----------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "gtest/gtest.h"
11 #include "lldb/Utility/Environment.h"
13 using namespace lldb_private
;
15 TEST(EnvironmentTest
, EnvpConstruction
) {
16 const char **Envp1
= nullptr;
17 EXPECT_EQ(0u, Environment(Envp1
).size());
19 const char *Envp2
[] = {"FOO=BAR", nullptr};
20 EXPECT_EQ("BAR", Environment(Envp2
).lookup("FOO"));
22 const char *Envp3
[] = {"FOO=BAR", "FOO=BAZ", nullptr};
23 EXPECT_EQ("BAR", Environment(Envp3
).lookup("FOO"));
25 const char *Envp4
[] = {"FOO=", "BAR", nullptr};
26 Environment
Env4(Envp4
);
27 ASSERT_EQ(2u, Env4
.size());
28 EXPECT_EQ("", Environment(Envp4
).find("FOO")->second
);
29 EXPECT_EQ("", Environment(Envp4
).find("BAR")->second
);
31 const char *Envp5
[] = {"FOO=BAR=BAZ", nullptr};
32 EXPECT_EQ("BAR=BAZ", Environment(Envp5
).lookup("FOO"));
35 TEST(EnvironmentTest
, EnvpConversion
) {
36 std::string
FOO_EQ_BAR("FOO=BAR");
37 std::string
BAR_EQ_BAZ("BAR=BAZ");
40 Env
.insert(FOO_EQ_BAR
);
41 Env
.insert(BAR_EQ_BAZ
);
42 Environment::Envp Envp
= Env
.getEnvp();
43 const char *const *Envp_
= Envp
;
45 EXPECT_TRUE(FOO_EQ_BAR
== Envp_
[0] || FOO_EQ_BAR
== Envp_
[1]);
46 EXPECT_TRUE(BAR_EQ_BAZ
== Envp_
[0] || BAR_EQ_BAZ
== Envp_
[1]);
47 EXPECT_EQ(nullptr, Envp_
[2]);