Skip to content

Fix TestProcessInfo on Windows #2372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion TestFoundation/TestProcessInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class TestProcessInfo : XCTestCase {
// just test that the initial name is not empty or something?
#if DARWIN_COMPATIBILITY_TESTS
let targetName = "xctest"
#elseif os(Windows)
let targetName = "TestFoundation.exe"
#else
let targetName = "TestFoundation"
#endif
Expand Down Expand Up @@ -71,7 +73,11 @@ class TestProcessInfo : XCTestCase {
#if os(Windows)
func setenv(_ key: String, _ value: String, _ overwrite: Int) -> Int32 {
assert(overwrite == 1)
return putenv("\(key)=\(value)")
guard !key.contains("=") else {
errno = EINVAL
return -1
}
return _putenv("\(key)=\(value)")
}
#endif

Expand Down Expand Up @@ -104,7 +110,12 @@ class TestProcessInfo : XCTestCase {
XCTAssertNil(env["bad3"])
XCTAssertNil(env["bad3="])

#if os(Windows)
// On Windows, adding an empty environment variable removes it from the environment
XCTAssertNil(env["var1"])
#else
XCTAssertEqual(env["var1"], "")
#endif
XCTAssertEqual(env["var2"], "=")
XCTAssertEqual(env["var3"], "=x")
XCTAssertEqual(env["var4"], "x=")
Expand Down