Skip to content

Commit 06ccad8

Browse files
authored
Merge pull request swiftlang#2372 from gmittert/TestProcessInfo
Fix TestProcessInfo on Windows
2 parents 21f5313 + 63c3229 commit 06ccad8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

TestFoundation/TestProcessInfo.swift

+12-1
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,11 @@ 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 {
77+
errno = EINVAL
78+
return -1
79+
}
80+
return _putenv("\(key)=\(value)")
7581
}
7682
#endif
7783

@@ -104,7 +110,12 @@ class TestProcessInfo : XCTestCase {
104110
XCTAssertNil(env["bad3"])
105111
XCTAssertNil(env["bad3="])
106112

113+
#if os(Windows)
114+
// On Windows, adding an empty environment variable removes it from the environment
115+
XCTAssertNil(env["var1"])
116+
#else
107117
XCTAssertEqual(env["var1"], "")
118+
#endif
108119
XCTAssertEqual(env["var2"], "=")
109120
XCTAssertEqual(env["var3"], "=x")
110121
XCTAssertEqual(env["var4"], "x=")

0 commit comments

Comments
 (0)