Skip to content

Commit c85b15e

Browse files
committed
test: use portable env setter (Windows has no setenv/unsetenv)
1 parent be86dc3 commit c85b15e

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

tests/unit/test_xlings.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include <gtest/gtest.h>
2-
#include <cstdlib>
32

43
import std;
54
import mcpp.xlings;
5+
import mcpp.platform.env;
66

77
namespace {
88

@@ -174,9 +174,9 @@ TEST(XlingsSiblingPackage, MetadataOnlyHuskIsNotContent) {
174174

175175
// Isolate from the host's ~/.xlings fallback.
176176
const char* oldHome = std::getenv("HOME");
177-
::setenv("HOME", tmp.c_str(), 1);
177+
mcpp::platform::env::set("HOME", tmp.string());
178178
auto found = mcpp::xlings::paths::find_sibling_package(gccBin, "linux-headers");
179-
if (oldHome) ::setenv("HOME", oldHome, 1); else ::unsetenv("HOME");
179+
mcpp::platform::env::set("HOME", oldHome ? oldHome : "");
180180

181181
EXPECT_FALSE(found.has_value());
182182

@@ -235,10 +235,11 @@ TEST(XlingsHomeTool, FindsPayloadUnderNonXimPrefix) {
235235
auto real = xpkgs / "scode-x-linux-headers" / "5.11.1";
236236
touch(real / "include" / "linux" / "limits.h");
237237

238-
::setenv("MCPP_HOME", tmp.c_str(), 1);
238+
const char* oldMcppHome = std::getenv("MCPP_HOME");
239+
mcpp::platform::env::set("MCPP_HOME", tmp.string());
239240
auto found = mcpp::xlings::paths::find_home_tool(
240241
"linux-headers", "include/linux/limits.h");
241-
::unsetenv("MCPP_HOME");
242+
mcpp::platform::env::set("MCPP_HOME", oldMcppHome ? oldMcppHome : "");
242243

243244
ASSERT_TRUE(found.has_value());
244245
EXPECT_EQ(*found, real);

0 commit comments

Comments
 (0)