From db22dec30146400bd1487d02906c40dd85bcb372 Mon Sep 17 00:00:00 2001 From: Simon Evans Date: Sun, 9 Jun 2019 11:37:27 -0700 Subject: [PATCH] DarwinCompatibility: Restore tests to compiling and working - Add new test files. --- .../project.pbxproj | 50 +++++++++++++++++-- .../xcschemes/xdgTestHelper.xcscheme | 22 ++++---- Foundation/NSArray.swift | 10 +++- TestFoundation/TestBundle.swift | 17 +++++-- TestFoundation/TestFileManager.swift | 4 +- TestFoundation/TestImports.swift | 2 + TestFoundation/TestMeasurement.swift | 4 ++ TestFoundation/TestNSSet.swift | 10 ++-- TestFoundation/TestNSSortDescriptor.swift | 2 + TestFoundation/TestNSString.swift | 2 + TestFoundation/TestPipe.swift | 4 +- TestFoundation/TestURLSessionFTP.swift | 2 + TestFoundation/Utilities.swift | 32 +++++++++++- TestFoundation/xdgTestHelper/main.swift | 14 +++++- 14 files changed, 143 insertions(+), 32 deletions(-) diff --git a/DarwinCompatibilityTests.xcodeproj/project.pbxproj b/DarwinCompatibilityTests.xcodeproj/project.pbxproj index 7dc91bcd64..b656535222 100644 --- a/DarwinCompatibilityTests.xcodeproj/project.pbxproj +++ b/DarwinCompatibilityTests.xcodeproj/project.pbxproj @@ -8,7 +8,16 @@ /* Begin PBXBuildFile section */ 1560EA8C219217F8004377E9 /* TestNSCalendar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1560EA8B219217F8004377E9 /* TestNSCalendar.swift */; }; + B906C30122AC6CE700FCFA2D /* TestNSSortDescriptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B906C2FF22AC6CE600FCFA2D /* TestNSSortDescriptor.swift */; }; + B906C30222AC6CE700FCFA2D /* TestURLSessionFTP.swift in Sources */ = {isa = PBXBuildFile; fileRef = B906C30022AC6CE600FCFA2D /* TestURLSessionFTP.swift */; }; + B906C30422AC6E2A00FCFA2D /* FTPServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B906C30322AC6E2A00FCFA2D /* FTPServer.swift */; }; B907F36F20BB188800013CBE /* NSString-ISO-8859-1-data.txt in Resources */ = {isa = PBXBuildFile; fileRef = B907F36E20BB188800013CBE /* NSString-ISO-8859-1-data.txt */; }; + B91269F622857B7100C78241 /* TestUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = B91269EE22857B7000C78241 /* TestUUID.swift */; }; + B91269F722857B7100C78241 /* TestDateInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = B91269EF22857B7000C78241 /* TestDateInterval.swift */; }; + B91269F822857B7100C78241 /* TestMeasurement.swift in Sources */ = {isa = PBXBuildFile; fileRef = B91269F022857B7000C78241 /* TestMeasurement.swift */; }; + B91269F922857B7100C78241 /* TestHost.swift in Sources */ = {isa = PBXBuildFile; fileRef = B91269F122857B7000C78241 /* TestHost.swift */; }; + B91269FA22857B7100C78241 /* TestNSLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = B91269F322857B7100C78241 /* TestNSLock.swift */; }; + B91269FB22857B7100C78241 /* TestDateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = B91269F522857B7100C78241 /* TestDateComponents.swift */; }; B917D32420B0DB9700728EE0 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B917D32320B0DB9700728EE0 /* Foundation.framework */; }; B917D32620B0DE2000728EE0 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = B917D32520B0DE2000728EE0 /* main.swift */; }; B940492B223B13D000FB4384 /* TestProgressFraction.swift in Sources */ = {isa = PBXBuildFile; fileRef = B940492A223B13D000FB4384 /* TestProgressFraction.swift */; }; @@ -154,7 +163,19 @@ /* Begin PBXFileReference section */ 1560EA8B219217F8004377E9 /* TestNSCalendar.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TestNSCalendar.swift; path = TestFoundation/TestNSCalendar.swift; sourceTree = ""; }; + B906C2FF22AC6CE600FCFA2D /* TestNSSortDescriptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNSSortDescriptor.swift; path = TestFoundation/TestNSSortDescriptor.swift; sourceTree = ""; }; + B906C30022AC6CE600FCFA2D /* TestURLSessionFTP.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestURLSessionFTP.swift; path = TestFoundation/TestURLSessionFTP.swift; sourceTree = ""; }; + B906C30322AC6E2A00FCFA2D /* FTPServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FTPServer.swift; path = TestFoundation/FTPServer.swift; sourceTree = ""; }; B907F36E20BB188800013CBE /* NSString-ISO-8859-1-data.txt */ = {isa = PBXFileReference; lastKnownFileType = text; name = "NSString-ISO-8859-1-data.txt"; path = "TestFoundation/Resources/NSString-ISO-8859-1-data.txt"; sourceTree = ""; }; + B91269ED22857B7000C78241 /* TestNotification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNotification.swift; path = TestFoundation/TestNotification.swift; sourceTree = ""; }; + B91269EE22857B7000C78241 /* TestUUID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestUUID.swift; path = TestFoundation/TestUUID.swift; sourceTree = ""; }; + B91269EF22857B7000C78241 /* TestDateInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestDateInterval.swift; path = TestFoundation/TestDateInterval.swift; sourceTree = ""; }; + B91269F022857B7000C78241 /* TestMeasurement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestMeasurement.swift; path = TestFoundation/TestMeasurement.swift; sourceTree = ""; }; + B91269F122857B7000C78241 /* TestHost.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestHost.swift; path = TestFoundation/TestHost.swift; sourceTree = ""; }; + B91269F222857B7100C78241 /* TestNotificationQueue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNotificationQueue.swift; path = TestFoundation/TestNotificationQueue.swift; sourceTree = ""; }; + B91269F322857B7100C78241 /* TestNSLock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNSLock.swift; path = TestFoundation/TestNSLock.swift; sourceTree = ""; }; + B91269F422857B7100C78241 /* TestNotificationCenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNotificationCenter.swift; path = TestFoundation/TestNotificationCenter.swift; sourceTree = ""; }; + B91269F522857B7100C78241 /* TestDateComponents.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestDateComponents.swift; path = TestFoundation/TestDateComponents.swift; sourceTree = ""; }; 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 = ""; }; @@ -231,7 +252,7 @@ B9C89F221F6BF89800087AF4 /* TestNSCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNSCache.swift; path = TestFoundation/TestNSCache.swift; sourceTree = ""; }; B9C89F231F6BF89800087AF4 /* TestNSDictionary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNSDictionary.swift; path = TestFoundation/TestNSDictionary.swift; sourceTree = ""; }; B9C89F241F6BF89800087AF4 /* TestNotificationCenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNotificationCenter.swift; path = TestFoundation/TestNotificationCenter.swift; sourceTree = ""; }; - B9C89F251F6BF89800087AF4 /* TestProcess.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestProcess.swift; path = TestFoundation/TestProcess.swift; sourceTree = ""; }; + B9C89F251F6BF89800087AF4 /* TestProcess.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestProcess.swift; path = TestFoundation/TestProcess.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; B9C89F261F6BF89900087AF4 /* TestEnergyFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestEnergyFormatter.swift; path = TestFoundation/TestEnergyFormatter.swift; sourceTree = ""; }; B9C89F271F6BF89900087AF4 /* TestNSCompoundPredicate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNSCompoundPredicate.swift; path = TestFoundation/TestNSCompoundPredicate.swift; sourceTree = ""; }; B9C89F281F6BF89900087AF4 /* TestNotification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TestNotification.swift; path = TestFoundation/TestNotification.swift; sourceTree = ""; }; @@ -301,6 +322,18 @@ B9C89EB81F6BF47D00087AF4 = { isa = PBXGroup; children = ( + B906C30322AC6E2A00FCFA2D /* FTPServer.swift */, + B906C2FF22AC6CE600FCFA2D /* TestNSSortDescriptor.swift */, + B906C30022AC6CE600FCFA2D /* TestURLSessionFTP.swift */, + B91269F522857B7100C78241 /* TestDateComponents.swift */, + B91269EF22857B7000C78241 /* TestDateInterval.swift */, + B91269F122857B7000C78241 /* TestHost.swift */, + B91269F022857B7000C78241 /* TestMeasurement.swift */, + B91269ED22857B7000C78241 /* TestNotification.swift */, + B91269F422857B7100C78241 /* TestNotificationCenter.swift */, + B91269F222857B7100C78241 /* TestNotificationQueue.swift */, + B91269F322857B7100C78241 /* TestNSLock.swift */, + B91269EE22857B7000C78241 /* TestUUID.swift */, B9C1C63322607372002BBEA0 /* FixtureValues.swift */, B940492A223B13D000FB4384 /* TestProgressFraction.swift */, B97E7855222AF995007596B0 /* TestPropertyListEncoder.swift */, @@ -569,6 +602,18 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + B906C30422AC6E2A00FCFA2D /* FTPServer.swift in Sources */, + B906C30122AC6CE700FCFA2D /* TestNSSortDescriptor.swift in Sources */, + B906C30222AC6CE700FCFA2D /* TestURLSessionFTP.swift in Sources */, + B9C89F771F6BF89C00087AF4 /* TestNotification.swift in Sources */, + B91269F622857B7100C78241 /* TestUUID.swift in Sources */, + B91269F722857B7100C78241 /* TestDateInterval.swift in Sources */, + B91269F822857B7100C78241 /* TestMeasurement.swift in Sources */, + B91269F922857B7100C78241 /* TestHost.swift in Sources */, + B9C89F7F1F6BF89C00087AF4 /* TestNotificationQueue.swift in Sources */, + B91269FA22857B7100C78241 /* TestNSLock.swift in Sources */, + B9C89F731F6BF89C00087AF4 /* TestNotificationCenter.swift in Sources */, + B91269FB22857B7100C78241 /* TestDateComponents.swift in Sources */, B9C1C63422607372002BBEA0 /* FixtureValues.swift in Sources */, B940492B223B13D000FB4384 /* TestProgressFraction.swift in Sources */, B97E7856222AF995007596B0 /* TestPropertyListEncoder.swift in Sources */, @@ -639,18 +684,15 @@ B9C89F701F6BF89C00087AF4 /* TestDecimal.swift in Sources */, B9C89F711F6BF89C00087AF4 /* TestNSCache.swift in Sources */, B9C89F721F6BF89C00087AF4 /* TestNSDictionary.swift in Sources */, - B9C89F731F6BF89C00087AF4 /* TestNotificationCenter.swift in Sources */, B9C89F741F6BF89C00087AF4 /* TestProcess.swift in Sources */, B9C89F751F6BF89C00087AF4 /* TestEnergyFormatter.swift in Sources */, B9C89F761F6BF89C00087AF4 /* TestNSCompoundPredicate.swift in Sources */, - B9C89F771F6BF89C00087AF4 /* TestNotification.swift in Sources */, B9C89F781F6BF89C00087AF4 /* TestNSData.swift in Sources */, B9C89F791F6BF89C00087AF4 /* TestNSRange.swift in Sources */, B9C89F7A1F6BF89C00087AF4 /* TestNSGeometry.swift in Sources */, B9C89F7C1F6BF89C00087AF4 /* TestURLCredential.swift in Sources */, B9C89F7D1F6BF89C00087AF4 /* TestRunLoop.swift in Sources */, B9C89F7E1F6BF89C00087AF4 /* TestThread.swift in Sources */, - B9C89F7F1F6BF89C00087AF4 /* TestNotificationQueue.swift in Sources */, B9C89F801F6BF89C00087AF4 /* TestJSONSerialization.swift in Sources */, B9C89F811F6BF89C00087AF4 /* TestAffineTransform.swift in Sources */, B9C89F821F6BF89C00087AF4 /* TestNSURLRequest.swift in Sources */, diff --git a/DarwinCompatibilityTests.xcodeproj/xcshareddata/xcschemes/xdgTestHelper.xcscheme b/DarwinCompatibilityTests.xcodeproj/xcshareddata/xcschemes/xdgTestHelper.xcscheme index 192a059c87..f19768a015 100644 --- a/DarwinCompatibilityTests.xcodeproj/xcshareddata/xcschemes/xdgTestHelper.xcscheme +++ b/DarwinCompatibilityTests.xcodeproj/xcshareddata/xcschemes/xdgTestHelper.xcscheme @@ -27,6 +27,15 @@ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "YES"> + + + + @@ -50,17 +59,6 @@ - - - - - - - - String { var descriptions = [String]() + var nonAlphaNum = CharacterSet.alphanumerics + nonAlphaNum.invert() let cnt = count for idx in 0.. Bundle { #endif } + +#if DARWIN_COMPATIBILITY_TESTS +extension Bundle { + static let _supportsFreestandingBundles = false + static let _supportsFHSBundles = false +} +#endif + + internal func testBundleName() -> String { // Either 'TestFoundation' or 'DarwinCompatibilityTests' return testBundle().infoDictionary!["CFBundleName"] as! String @@ -521,7 +530,8 @@ class TestBundle : XCTestCase { XCTAssertNil(bundle.url(forAuxiliaryExecutable: "does_not_exist_at_all")) } } - + +#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT func test_bundleReverseBundleLookup() { _withEachPlaygroundLayout { (playground) in #if !os(Windows) @@ -542,15 +552,12 @@ class TestBundle : XCTestCase { } } -#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT func test_mainBundleExecutableURL() { -#if !DARWIN_COMPATIBILITY_TESTS // _CFProcessPath() is unavailable on native Foundation let maybeURL = Bundle.main.executableURL XCTAssertNotNil(maybeURL) guard let url = maybeURL else { return } XCTAssertEqual(url.path, ProcessInfo.processInfo._processPath) -#endif } #endif @@ -571,13 +578,13 @@ class TestBundle : XCTestCase { ("test_bundlePreflight", test_bundlePreflight), ("test_bundleFindExecutable", test_bundleFindExecutable), ("test_bundleFindAuxiliaryExecutables", test_bundleFindAuxiliaryExecutables), - ("test_bundleReverseBundleLookup", test_bundleReverseBundleLookup), ("test_bundleForClass", testExpectedToFailOnWindows(test_bundleForClass, "Functionality not yet implemented on Windows. SR-XXXX")), ] #if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT tests.append(contentsOf: [ ("test_mainBundleExecutableURL", test_mainBundleExecutableURL), + ("test_bundleReverseBundleLookup", test_bundleReverseBundleLookup), ]) #endif diff --git a/TestFoundation/TestFileManager.swift b/TestFoundation/TestFileManager.swift index b702d59ba4..0c97944443 100644 --- a/TestFoundation/TestFileManager.swift +++ b/TestFoundation/TestFileManager.swift @@ -1647,11 +1647,13 @@ VIDEOS=StopgapVideos try runSingleTest(aIsDirectory: true, bIsDirectory: false, options: .usingNewMetadataOnly) try runSingleTest(aIsDirectory: true, bIsDirectory: false, options: [.withoutDeletingBackupItem, .usingNewMetadataOnly]) } - + + #if !DARWIN_COMPATIBILITY_TESTS print("note: Testing platform-specific replace implementation.", to: &stderr) try testReplaceMethod { (a, b, backupItemName, options) -> URL? in try fm.replaceItem(at: a, withItemAt: b, backupItemName: backupItemName, options: options) } + #endif #if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT print("note: Testing cross-platform replace implementation.", to: &stderr) diff --git a/TestFoundation/TestImports.swift b/TestFoundation/TestImports.swift index 6ddbb6c0e4..2f3cc6c74f 100644 --- a/TestFoundation/TestImports.swift +++ b/TestFoundation/TestImports.swift @@ -15,6 +15,8 @@ @_exported import SwiftXCTest #else @_exported import Foundation +#if canImport(FoundationNetworking) @_exported import FoundationNetworking +#endif @_exported import XCTest #endif diff --git a/TestFoundation/TestMeasurement.swift b/TestFoundation/TestMeasurement.swift index 2f6d5acce4..77eb701237 100644 --- a/TestFoundation/TestMeasurement.swift +++ b/TestFoundation/TestMeasurement.swift @@ -7,6 +7,7 @@ // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // +#if !DARWIN_COMPATIBILITY_TESTS // https://bugs.swift.org/browse/SR-10904 class CustomUnit: Unit { required init(symbol: String) { super.init(symbol: symbol) @@ -19,6 +20,7 @@ class CustomUnit: Unit { public static let bugs = CustomUnit(symbol: "bug") public static let features = CustomUnit(symbol: "feature") } +#endif class TestMeasurement: XCTestCase { static var allTests: [(String, (TestMeasurement) -> () throws -> Void)] { @@ -59,6 +61,7 @@ class TestMeasurement: XCTestCase { ] checkHashableGroups(durations) +#if !DARWIN_COMPATIBILITY_TESTS let custom: [Measurement] = [ Measurement(value: 1, unit: CustomUnit.bugs), Measurement(value: 2, unit: CustomUnit.bugs), @@ -70,6 +73,7 @@ class TestMeasurement: XCTestCase { Measurement(value: 4, unit: CustomUnit.features), ] checkHashable(custom, equalityOracle: { $0 == $1 }) +#endif } } diff --git a/TestFoundation/TestNSSet.swift b/TestFoundation/TestNSSet.swift index 31623930e0..b6fb8b77a3 100644 --- a/TestFoundation/TestNSSet.swift +++ b/TestFoundation/TestNSSet.swift @@ -231,16 +231,16 @@ class TestNSSet : XCTestCase { } func test_description() { - let array = NSArray(array: ["array_element1", "array_element2"]) + let array = NSArray(array: ["array_element1", "arrayElement2", "", "!@#$%^&*()", "a+b"]) let dictionary = NSDictionary(dictionary: ["key1": "value1", "key2": "value2"]) let innerSet = NSSet(array: [4444, 5555]) let set: NSSet = NSSet(array: [array, dictionary, innerSet, 1111, 2222, 3333]) let description = NSString(string: set.description) - - XCTAssertTrue(description.substring(to: 2).isEqual(to: "{(")) - XCTAssertTrue(description.substring(from: description.length - 2).isEqual(to: ")}")) - XCTAssertTrue(description.contains(" (\n array_element1,\n array_element2\n )")) + + XCTAssertTrue(description.hasPrefix("{(")) + XCTAssertTrue(description.hasSuffix(")}")) + XCTAssertTrue(description.contains(" (\n \"array_element1\",\n arrayElement2,\n \"\",\n \"!@#$%^&*()\",\n \"a+b\"\n )")) XCTAssertTrue(description.contains(" key1 = value1")) XCTAssertTrue(description.contains(" key2 = value2")) XCTAssertTrue(description.contains(" 4444")) diff --git a/TestFoundation/TestNSSortDescriptor.swift b/TestFoundation/TestNSSortDescriptor.swift index 8ece984304..39f1a2eb46 100644 --- a/TestFoundation/TestNSSortDescriptor.swift +++ b/TestFoundation/TestNSSortDescriptor.swift @@ -7,6 +7,7 @@ // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // +#if !DARWIN_COMPATIBILITY_TESTS struct IntSortable { var value: Int } @@ -233,3 +234,4 @@ class TestNSSortDescriptor: XCTestCase { ] } } +#endif diff --git a/TestFoundation/TestNSString.swift b/TestFoundation/TestNSString.swift index 68b9ae4834..70372b7a6a 100755 --- a/TestFoundation/TestNSString.swift +++ b/TestFoundation/TestNSString.swift @@ -1054,10 +1054,12 @@ class TestNSString: LoopbackServerTest { } do { +#if !DARWIN_COMPATIBILITY_TESTS // https://bugs.swift.org/browse/SR-10916 let path: NSString = "~/foo/bar/" let result = path.standardizingPath let expected = NSHomeDirectory().appendingPathComponent("foo/bar") XCTAssertEqual(result, expected, "standardizingPath expanding initial tilde.") +#endif } // relative file paths depend on file path standardizing that is not yet implemented diff --git a/TestFoundation/TestPipe.swift b/TestFoundation/TestPipe.swift index 5734cfe74b..d5e501d19e 100644 --- a/TestFoundation/TestPipe.swift +++ b/TestFoundation/TestPipe.swift @@ -7,6 +7,8 @@ // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // +#if !DARWIN_COMPATIBILITY_TESTS // Disable until Foundation has the new FileHandle API + #if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT #if canImport(SwiftFoundation) && !DEPLOYMENT_RUNTIME_OBJC @testable import SwiftFoundation @@ -15,7 +17,7 @@ #endif #endif -#if !DARWIN_COMPATIBILITY_TESTS // Disable until Foundation has the new FileHandle API + class TestPipe: XCTestCase { static var allTests: [(String, (TestPipe) -> () throws -> Void)] { diff --git a/TestFoundation/TestURLSessionFTP.swift b/TestFoundation/TestURLSessionFTP.swift index 0387745c40..29f739012b 100644 --- a/TestFoundation/TestURLSessionFTP.swift +++ b/TestFoundation/TestURLSessionFTP.swift @@ -28,6 +28,7 @@ class TestURLSessionFTP : LoopbackFTPServerTest { """ func test_ftpDataTask() { +#if !DARWIN_COMPATIBILITY_TESTS let ftpURL = "ftp://127.0.0.1:\(TestURLSessionFTP.serverPort)/test.txt" let req = URLRequest(url: URL(string: ftpURL)!) let configuration = URLSessionConfiguration.default @@ -41,6 +42,7 @@ class TestURLSessionFTP : LoopbackFTPServerTest { }) dataTask1.resume() waitForExpectations(timeout: 60) +#endif } func test_ftpDataTaskDelegate() { diff --git a/TestFoundation/Utilities.swift b/TestFoundation/Utilities.swift index a1de66814d..24598137a9 100644 --- a/TestFoundation/Utilities.swift +++ b/TestFoundation/Utilities.swift @@ -7,6 +7,27 @@ // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // +#if DARWIN_COMPATIBILITY_TESTS +public typealias XCTestCaseEntry = (testCaseClass: XCTestCase.Type, allTests: [(String, XCTestCaseClosure)]) +public typealias XCTestCaseClosure = (XCTestCase) throws -> Void + +public func testCase(_ allTests: [(String, (T) -> () throws -> Void)]) -> XCTestCaseEntry { + let tests: [(String, XCTestCaseClosure)] = allTests.map { ($0.0, test($0.1)) } + return (T.self, tests) +} + +private func test(_ testFunc: @escaping (T) -> () throws -> Void) -> XCTestCaseClosure { + return { testCaseType in + guard let testCase = testCaseType as? T else { + fatalError("Attempt to invoke test on class \(T.self) with incompatible instance type \(type(of: testCaseType))") + } + + try testFunc(testCase)() + } +} +#endif + + func checkHashing_ValueType( initialValue item: Item, byMutating keyPath: WritableKeyPath, @@ -488,11 +509,20 @@ private var shouldRunXFailTests: Bool { return ProcessInfo.processInfo.environment["NS_FOUNDATION_ATTEMPT_XFAIL_TESTS"] == "YES" } + +private func printStderr(_ msg: String) { +#if DARWIN_COMPATIBILITY_TESTS + FileHandle.standardError.write(Data(msg.utf8)) +#else + try? FileHandle.standardError.write(contentsOf: Data(msg.utf8)) +#endif +} + func shouldAttemptXFailTests(_ reason: String) -> Bool { if shouldRunXFailTests { return true } else { - try? FileHandle.standardError.write(contentsOf: Data("warning: Skipping test expected to fail with reason '\(reason)'\n".utf8)) + printStderr("warning: Skipping test expected to fail with reason '\(reason)'\n") return false } } diff --git a/TestFoundation/xdgTestHelper/main.swift b/TestFoundation/xdgTestHelper/main.swift index 9fe6b311e6..21beea70be 100644 --- a/TestFoundation/xdgTestHelper/main.swift +++ b/TestFoundation/xdgTestHelper/main.swift @@ -7,13 +7,15 @@ // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // -#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) +#if !DEPLOYMENT_RUNTIME_OBJC && canImport(SwiftFoundation) && canImport(SwiftFoundationNetworking) import SwiftFoundation import SwiftFoundationNetworking #else import Foundation +#if canImport(FoundationNetworking) import FoundationNetworking #endif +#endif #if os(Windows) import WinSDK #endif @@ -177,9 +179,19 @@ func cat(_ args: ArraySlice.Iterator) { exitCode = 1 return } + #if DARWIN_COMPATIBILITY_TESTS + var data: Data + repeat { + data = fh.readData(ofLength: Int.max) + if data.count > 0 { + FileHandle.standardOutput.write(data) + } + } while data.count > 0 +#else while let data = try fh.readToEnd() { try FileHandle.standardOutput.write(contentsOf: data) } +#endif } catch { print(error) } }