Skip to content

Test fixes for RedHat #1562

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 2 commits into from
May 26, 2018
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
104 changes: 101 additions & 3 deletions DarwinCompatibilityTests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
B917D32420B0DB9700728EE0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B917D32320B0DB9700728EE0 /* Foundation.framework */; };
B917D32620B0DE2000728EE0 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = B917D32520B0DE2000728EE0 /* main.swift */; };
B95788861F6FB9470003EB01 /* TestNSNumberBridging.swift in Sources */ = {isa = PBXBuildFile; fileRef = B95788851F6FB9470003EB01 /* TestNSNumberBridging.swift */; };
B987C65E2093C8AF0026B50D /* TestImports.swift in Sources */ = {isa = PBXBuildFile; fileRef = B987C65D2093C8AF0026B50D /* TestImports.swift */; };
B9C89ED21F6BF67C00087AF4 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B9C89ED11F6BF67C00087AF4 /* XCTest.framework */; };
Expand Down Expand Up @@ -112,6 +114,15 @@
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
B917D31A20B0DB8B00728EE0 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
);
runOnlyForDeploymentPostprocessing = 1;
};
B9C89EBF1F6BF47D00087AF4 /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 12;
Expand All @@ -124,6 +135,9 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
B917D31C20B0DB8B00728EE0 /* xdgTestHelper */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = xdgTestHelper; sourceTree = BUILT_PRODUCTS_DIR; };
B917D32320B0DB9700728EE0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
B917D32520B0DE2000728EE0 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = main.swift; path = TestFoundation/xdgTestHelper/main.swift; sourceTree = "<group>"; };
B95788851F6FB9470003EB01 /* TestNSNumberBridging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNSNumberBridging.swift; path = TestFoundation/TestNSNumberBridging.swift; sourceTree = "<group>"; };
B987C65D2093C8AF0026B50D /* TestImports.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestImports.swift; path = TestFoundation/TestImports.swift; sourceTree = "<group>"; };
B9C89EC11F6BF47D00087AF4 /* DarwinCompatibilityTests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = DarwinCompatibilityTests; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -160,7 +174,6 @@
B9C89EFF1F6BF89300087AF4 /* TestNSString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNSString.swift; path = TestFoundation/TestNSString.swift; sourceTree = "<group>"; };
B9C89F001F6BF89300087AF4 /* TestNSUUID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNSUUID.swift; path = TestFoundation/TestNSUUID.swift; sourceTree = "<group>"; };
B9C89F011F6BF89300087AF4 /* TestPropertyListSerialization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestPropertyListSerialization.swift; path = TestFoundation/TestPropertyListSerialization.swift; sourceTree = "<group>"; };
B9C89F021F6BF89300087AF4 /* XDGTestHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = XDGTestHelper.swift; path = TestFoundation/XDGTestHelper.swift; sourceTree = "<group>"; };
B9C89F031F6BF89300087AF4 /* TestNSArray.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNSArray.swift; path = TestFoundation/TestNSArray.swift; sourceTree = "<group>"; };
B9C89F051F6BF89400087AF4 /* TestFileHandle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestFileHandle.swift; path = TestFoundation/TestFileHandle.swift; sourceTree = "<group>"; };
B9C89F061F6BF89400087AF4 /* TestTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestTimer.swift; path = TestFoundation/TestTimer.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -234,6 +247,14 @@
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
B917D31920B0DB8B00728EE0 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
B917D32420B0DB9700728EE0 /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
B9C89EBE1F6BF47D00087AF4 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
Expand All @@ -252,9 +273,17 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
B917D31D20B0DB8B00728EE0 /* xdgTestHelper */ = {
isa = PBXGroup;
children = (
);
path = xdgTestHelper;
sourceTree = "<group>";
};
B9C89EB81F6BF47D00087AF4 = {
isa = PBXGroup;
children = (
B917D32520B0DE2000728EE0 /* main.swift */,
B987C65D2093C8AF0026B50D /* TestImports.swift */,
B95788851F6FB9470003EB01 /* TestNSNumberBridging.swift */,
B9C89FAC1F6DCAE700087AF4 /* Info.plist */,
Expand Down Expand Up @@ -355,8 +384,8 @@
B9C89F0F1F6BF89500087AF4 /* TestXMLDocument.swift */,
B9C89EED1F6BF89000087AF4 /* TestXMLParser.swift */,
B9C89F131F6BF89600087AF4 /* xdgTestHelper */,
B9C89F021F6BF89300087AF4 /* XDGTestHelper.swift */,
B9C89ED81F6BF77E00087AF4 /* DarwinCompatibilityTests */,
B917D31D20B0DB8B00728EE0 /* xdgTestHelper */,
B9C89EC21F6BF47D00087AF4 /* Products */,
B9C89ED01F6BF67C00087AF4 /* Frameworks */,
);
Expand All @@ -367,13 +396,15 @@
children = (
B9C89EC11F6BF47D00087AF4 /* DarwinCompatibilityTests */,
B9C89ED71F6BF77E00087AF4 /* DarwinCompatibilityTests.xctest */,
B917D31C20B0DB8B00728EE0 /* xdgTestHelper */,
);
name = Products;
sourceTree = "<group>";
};
B9C89ED01F6BF67C00087AF4 /* Frameworks */ = {
isa = PBXGroup;
children = (
B917D32320B0DB9700728EE0 /* Foundation.framework */,
B9C89ED11F6BF67C00087AF4 /* XCTest.framework */,
);
name = Frameworks;
Expand All @@ -392,6 +423,23 @@
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
B917D31B20B0DB8B00728EE0 /* xdgTestHelper */ = {
isa = PBXNativeTarget;
buildConfigurationList = B917D32220B0DB8B00728EE0 /* Build configuration list for PBXNativeTarget "xdgTestHelper" */;
buildPhases = (
B917D31820B0DB8B00728EE0 /* Sources */,
B917D31920B0DB8B00728EE0 /* Frameworks */,
B917D31A20B0DB8B00728EE0 /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = xdgTestHelper;
productName = xdgTestHelper;
productReference = B917D31C20B0DB8B00728EE0 /* xdgTestHelper */;
productType = "com.apple.product-type.tool";
};
B9C89EC01F6BF47D00087AF4 /* DarwinCompatibilityTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = B9C89EC81F6BF47D00087AF4 /* Build configuration list for PBXNativeTarget "DarwinCompatibilityTests" */;
Expand Down Expand Up @@ -432,10 +480,14 @@
B9C89EB91F6BF47D00087AF4 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0900;
LastSwiftUpdateCheck = 0930;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = Apple;
TargetAttributes = {
B917D31B20B0DB8B00728EE0 = {
CreatedOnToolsVersion = 9.3.1;
ProvisioningStyle = Automatic;
};
B9C89EC01F6BF47D00087AF4 = {
CreatedOnToolsVersion = 9.0;
LastSwiftMigration = 0910;
Expand All @@ -461,6 +513,7 @@
targets = (
B9C89EC01F6BF47D00087AF4 /* DarwinCompatibilityTests */,
B9C89ED61F6BF77E00087AF4 /* DarwinCompatibilityTests */,
B917D31B20B0DB8B00728EE0 /* xdgTestHelper */,
);
};
/* End PBXProject section */
Expand Down Expand Up @@ -497,6 +550,14 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
B917D31820B0DB8B00728EE0 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B917D32620B0DE2000728EE0 /* main.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
B9C89EBD1F6BF47D00087AF4 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -594,6 +655,34 @@
/* End PBXSourcesBuildPhase section */

/* Begin XCBuildConfiguration section */
B917D32020B0DB8B00728EE0 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CODE_SIGN_STYLE = Automatic;
MACOSX_DEPLOYMENT_TARGET = 10.13;
OTHER_SWIFT_FLAGS = "-DDEPLOYMENT_RUNTIME_OBJC -DDARWIN_COMPATIBILITY_TESTS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Debug;
};
B917D32120B0DB8B00728EE0 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CODE_SIGN_STYLE = Automatic;
MACOSX_DEPLOYMENT_TARGET = 10.13;
OTHER_SWIFT_FLAGS = "-DDEPLOYMENT_RUNTIME_OBJC -DDARWIN_COMPATIBILITY_TESTS";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
};
name = Release;
};
B9C89EC61F6BF47D00087AF4 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
Expand Down Expand Up @@ -759,6 +848,15 @@
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
B917D32220B0DB8B00728EE0 /* Build configuration list for PBXNativeTarget "xdgTestHelper" */ = {
isa = XCConfigurationList;
buildConfigurations = (
B917D32020B0DB8B00728EE0 /* Debug */,
B917D32120B0DB8B00728EE0 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
B9C89EBC1F6BF47D00087AF4 /* Build configuration list for PBXProject "DarwinCompatibilityTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
Expand Down
4 changes: 0 additions & 4 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@
7900433C1CACD33E00ECCBF1 /* TestNSPredicate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7900433A1CACD33E00ECCBF1 /* TestNSPredicate.swift */; };
90E645DF1E4C89A400D0D47C /* TestNSCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90E645DE1E4C89A400D0D47C /* TestNSCache.swift */; };
9F0DD3521ECD73D000F68030 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F0041781ECD5962004138BD /* main.swift */; };
9F0DD3531ECD73D200F68030 /* XDGTestHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F4ADBD21ECD506E001F0B3D /* XDGTestHelper.swift */; };
9F0DD3571ECD783500F68030 /* SwiftFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5B5D885D1BBC938800234F36 /* SwiftFoundation.framework */; };
A058C2021E529CF100B07AA1 /* TestMassFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A058C2011E529CF100B07AA1 /* TestMassFormatter.swift */; };
AE35A1861CBAC85E0042DB84 /* SwiftFoundation.h in Headers */ = {isa = PBXBuildFile; fileRef = AE35A1851CBAC85E0042DB84 /* SwiftFoundation.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -809,7 +808,6 @@
9F0DD33F1ECD734200F68030 /* xdgTestHelper.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = xdgTestHelper.app; sourceTree = BUILT_PRODUCTS_DIR; };
9F0DD34F1ECD737B00F68030 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9F4ADBB61ECD445E001F0B3D /* SymbolAliases */ = {isa = PBXFileReference; lastKnownFileType = text; path = SymbolAliases; sourceTree = "<group>"; };
9F4ADBD21ECD506E001F0B3D /* XDGTestHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = XDGTestHelper.swift; path = ../XDGTestHelper.swift; sourceTree = "<group>"; };
A058C2011E529CF100B07AA1 /* TestMassFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestMassFormatter.swift; sourceTree = "<group>"; };
A5A34B551C18C85D00FD972B /* TestByteCountFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TestByteCountFormatter.swift; sourceTree = "<group>"; };
AE35A1851CBAC85E0042DB84 /* SwiftFoundation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SwiftFoundation.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1403,7 +1401,6 @@
isa = PBXGroup;
children = (
9F0DD34F1ECD737B00F68030 /* Info.plist */,
9F4ADBD21ECD506E001F0B3D /* XDGTestHelper.swift */,
9F0041781ECD5962004138BD /* main.swift */,
);
path = xdgTestHelper;
Expand Down Expand Up @@ -2521,7 +2518,6 @@
buildActionMask = 2147483647;
files = (
9F0DD3521ECD73D000F68030 /* main.swift in Sources */,
9F0DD3531ECD73D200F68030 /* XDGTestHelper.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
28 changes: 14 additions & 14 deletions Foundation/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,25 +292,25 @@ open class Process: NSObject {
}
argv.deallocate()
}

let envp: UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>

if let env = environment {
let nenv = env.count
envp = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>.allocate(capacity: 1 + nenv)
envp.initialize(from: env.map { strdup("\($0)=\($1)") }, count: nenv)
envp[env.count] = nil

var env: [String: String]
if let e = environment {
env = e
} else {
envp = _CFEnviron()
env = ProcessInfo.processInfo.environment
env["PWD"] = currentDirectoryURL.path
}

let nenv = env.count
let envp = UnsafeMutablePointer<UnsafeMutablePointer<Int8>?>.allocate(capacity: 1 + nenv)
envp.initialize(from: env.map { strdup("\($0)=\($1)") }, count: nenv)
envp[env.count] = nil

defer {
if let env = environment {
for pair in envp ..< envp + env.count {
free(UnsafeMutableRawPointer(pair.pointee))
}
envp.deallocate()
for pair in envp ..< envp + env.count {
free(UnsafeMutableRawPointer(pair.pointee))
}
envp.deallocate()
}

var taskSocketPair : [Int32] = [0, 0]
Expand Down
15 changes: 15 additions & 0 deletions TestFoundation/TestBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ internal func testBundleName() -> String {
return testBundle().infoDictionary!["CFBundleName"] as! String
}

internal func xdgTestHelperURL() -> URL {
#if DARWIN_COMPATIBILITY_TESTS
let exeName = "/xdgTestHelper"
#elseif os(macOS)
let exeName = "/xdgTestHelper.app/Contents/MacOS/xdgTestHelper"
#else
let exeName = "/xdgTestHelper/xdgTestHelper"
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems ok, but it's somewhat ironic that bundle can't find this helper itself. That's what it's supposed to be there fore in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue here is that we are not building xdgTestHelper in a bundle directory structure. It may be worth it to figure that out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll aim to do that in a follow-up PR as it is complicated by the fact that there are 3 separate targets being built (Linux, macOS and the Darwin Compatibility testing). However it should act as a good test of the Bundle class so it is definitely worth doing.


var path = testBundle().bundleURL.deletingLastPathComponent()
path.appendPathComponent(exeName)
return path
}


class BundlePlayground {
enum Layout {
case flat
Expand Down
1 change: 0 additions & 1 deletion TestFoundation/TestFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ class TestFileManager : XCTestCase {

let systemNumber = attrs[.systemNumber] as? NSNumber
XCTAssertNotNil(systemNumber)
XCTAssertNotEqual(systemNumber!.uint64Value, 0)

let systemFreeSize = attrs[.systemFreeSize] as? NSNumber
XCTAssertNotNil(systemFreeSize)
Expand Down
25 changes: 8 additions & 17 deletions TestFoundation/TestHTTPCookieStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class TestHTTPCookieStorage: XCTestCase {
}

func test_cookieInXDGSpecPath() {
#if !os(Android) && !DARWIN_COMPATIBILITY_TESTS
#if !os(Android)
//Test without setting the environment variable
let testCookie = HTTPCookie(properties: [
.name: "TestCookie0",
Expand All @@ -284,12 +284,8 @@ class TestHTTPCookieStorage: XCTestCase {
let storage = HTTPCookieStorage.shared
storage.setCookie(testCookie)
XCTAssertEqual(storage.cookies!.count, 1)
var destPath: String
let bundlePath = testBundle().bundlePath
var bundleName = "/" + bundlePath.components(separatedBy: "/").last!
if let range = bundleName.range(of: ".", options: .backwards, range: nil, locale: nil) {
bundleName = String(bundleName[..<range.lowerBound])
}
let destPath: String
let bundleName = "/" + testBundleName()
if let xdg_data_home = getenv("XDG_DATA_HOME") {
destPath = String(utf8String: xdg_data_home)! + bundleName + "/.cookies.shared"
} else {
Expand All @@ -299,21 +295,16 @@ class TestHTTPCookieStorage: XCTestCase {
var isDir: ObjCBool = false
let exists = fm.fileExists(atPath: destPath, isDirectory: &isDir)
XCTAssertTrue(exists)
//Test by setting the environmental variable
let pathIndex = bundlePath.range(of: "/", options: .backwards)?.lowerBound
let task = Process()

#if os(macOS)
let exeName = "/xdgTestHelper.app/Contents/MacOS/xdgTestHelper"
#else
let exeName = "/xdgTestHelper/xdgTestHelper"
#endif

task.launchPath = bundlePath[..<pathIndex!] + exeName
// Test by setting the environmental variable
let task = Process()
task.executableURL = xdgTestHelperURL()
task.arguments = ["--xdgcheck"]
var environment = ProcessInfo.processInfo.environment
let testPath = NSHomeDirectory() + "/TestXDG"
environment["XDG_DATA_HOME"] = testPath
task.environment = environment

// Launch the task
task.launch()
task.waitUntilExit()
Expand Down
Loading