Skip to content

Revert "<SR-9930> Swift CI: TestProcess.test_passthrough_environment : failed - Test failed: InvalidEnvironmentVariable("swift_xcode")" #1926

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
Feb 19, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3124,7 +3124,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -3144,7 +3144,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.12;
PRODUCT_BUNDLE_IDENTIFIER = org.swift.xdgTestHelper;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand Down
63 changes: 34 additions & 29 deletions TestFoundation/TestProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,38 +248,37 @@ class TestProcess : XCTestCase {
}
}

func helperToolEnvironment(from environment: [String: String]) -> [String: String] {
var result = environment
let importantEnvVars = ProcessInfo.processInfo.environment.filter {
$0.key.hasPrefix("LD_") || $0.key.hasPrefix("DYLD_")
}
for entry in importantEnvVars {
result[entry.key] = entry.value
func test_passthrough_environment() {
do {
let (output, _) = try runTask(["/usr/bin/env"], environment: nil)
let env = try parseEnv(output)
XCTAssertGreaterThan(env.count, 0)
} catch {
// FIXME: SR-9930 parseEnv fails if an environment variable contains
// a newline.
// XCTFail("Test failed: \(error)")
}
return result
}

func test_passthrough_environment() throws {
let helper = xdgTestHelperURL()
let (output, _) = try runTask([helper.path, "--env"], environment: nil)
let env = try parseEnv(output)
XCTAssertGreaterThan(env.count, 0)
}

func test_no_environment() throws {
let helper = xdgTestHelperURL()
let input = helperToolEnvironment(from: [:])
let (output, _) = try runTask([helper.path, "--env"], environment: input)
let env = try parseEnv(output)
XCTAssertEqual(env, input)
func test_no_environment() {
do {
let (output, _) = try runTask(["/usr/bin/env"], environment: [:])
let env = try parseEnv(output)
XCTAssertEqual(env.count, 0)
} catch {
XCTFail("Test failed: \(error)")
}
}

func test_custom_environment() throws {
let helper = xdgTestHelperURL()
let input = helperToolEnvironment(from: ["HELLO": "WORLD", "HOME": "CUPERTINO"])
let (output, _) = try runTask([helper.path, "--env"], environment: input)
let env = try parseEnv(output)
XCTAssertEqual(env, input)
func test_custom_environment() {
do {
let input = ["HELLO": "WORLD", "HOME": "CUPERTINO"]
let (output, _) = try runTask(["/usr/bin/env"], environment: input)
let env = try parseEnv(output)
XCTAssertEqual(env, input)
} catch {
XCTFail("Test failed: \(error)")
}
}

private func realpathOf(path: String) -> String? {
Expand Down Expand Up @@ -655,8 +654,14 @@ internal func runTask(_ arguments: [String], environment: [String: String]? = ni
}

private func parseEnv(_ env: String) throws -> [String: String] {
let dictionary = try PropertyListSerialization.propertyList(from: try env.data(using: .utf8).unwrapped(), format: nil) as? [String: String]
return try dictionary.unwrapped()
var result = [String: String]()
for line in env.components(separatedBy: "\n") where line != "" {
guard let range = line.range(of: "=") else {
throw Error.InvalidEnvironmentVariable(line)
}
result[String(line[..<range.lowerBound])] = String(line[range.upperBound...])
}
return result
}
#endif

3 changes: 0 additions & 3 deletions TestFoundation/xdgTestHelper/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ guard let arg = arguments.next() else {
}

switch arg {
case "--env":
try! FileHandle.standardOutput.write(contentsOf: PropertyListSerialization.data(fromPropertyList: ProcessInfo.processInfo.environment, format: .xml, options: 0))

case "--xdgcheck":
XDGCheck.run()

Expand Down