Skip to content

Commit bef93d6

Browse files
committed
Fix TestProcessInfo on Windows
- The Executable name should have .exe - Windows doesn't have setenv, so make putenv work more like it
1 parent bbfd56e commit bef93d6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

TestFoundation/TestProcessInfo.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class TestProcessInfo : XCTestCase {
3838
// just test that the initial name is not empty or something?
3939
#if DARWIN_COMPATIBILITY_TESTS
4040
let targetName = "xctest"
41+
#elseif os(Windows)
42+
let targetName = "TestFoundation.exe"
4143
#else
4244
let targetName = "TestFoundation"
4345
#endif
@@ -71,7 +73,8 @@ class TestProcessInfo : XCTestCase {
7173
#if os(Windows)
7274
func setenv(_ key: String, _ value: String, _ overwrite: Int) -> Int32 {
7375
assert(overwrite == 1)
74-
return putenv("\(key)=\(value)")
76+
guard !key.contains("=") else { return -1 }
77+
return _putenv("\(key)=\(value)")
7578
}
7679
#endif
7780

@@ -104,7 +107,12 @@ class TestProcessInfo : XCTestCase {
104107
XCTAssertNil(env["bad3"])
105108
XCTAssertNil(env["bad3="])
106109

110+
#if os(Windows)
111+
// On Windows, adding an empty environment variable removes it from the environment
112+
XCTAssertNil(env["var1"])
113+
#else
107114
XCTAssertEqual(env["var1"], "")
115+
#endif
108116
XCTAssertEqual(env["var2"], "=")
109117
XCTAssertEqual(env["var3"], "=x")
110118
XCTAssertEqual(env["var4"], "x=")

0 commit comments

Comments
 (0)