Skip to content

[DO NOT MERGE YET] Cherry-pick commits required for swift-3.0-branch Foundation integration #170

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
12 changes: 6 additions & 6 deletions Sources/XCTest/Private/TestListing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ extension XCTestSuite: Listable {
}

func dictionaryRepresentation() -> NSDictionary {
let listedTests = tests.flatMap({ ($0 as? Listable)?.dictionaryRepresentation() })
return [
"name": listingName.bridge(),
"tests": listedTests.bridge()
].bridge()
let listedTests = NSArray(array: tests.flatMap({ ($0 as? Listable)?.dictionaryRepresentation() }))
return NSDictionary(objects: [NSString(string: listingName),
listedTests],
forKeys: [NSString(string: "name"),
NSString(string: "tests")])
}

func findBundleTestSuite() -> XCTestSuite? {
Expand All @@ -102,6 +102,6 @@ extension XCTestCase: Listable {

func dictionaryRepresentation() -> NSDictionary {
let methodName = String(name.characters.split(separator: ".").last!)
return ["name": methodName].bridge()
return NSDictionary(object: NSString(string: methodName), forKey: NSString(string: "name"))
}
}
2 changes: 1 addition & 1 deletion Sources/XCTest/Private/WallClockTimeMetric.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal final class WallClockTimeMetric: PerformanceMetric {
}

private func currentTime() -> TimeInterval {
return ProcessInfo.processInfo().systemUptime
return ProcessInfo.processInfo.systemUptime
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/XCTest/Private/XCPredicateExpectation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
#endif

internal class XCPredicateExpectation: XCTestExpectation {
internal let predicate: Predicate
internal let predicate: NSPredicate
internal let object: AnyObject
internal var timer: Timer?
internal let handler: XCPredicateExpectationHandler?
private let evaluationInterval = 0.01

internal init(predicate: Predicate, object: AnyObject, description: String, file: StaticString, line: UInt, testCase: XCTestCase, handler: XCPredicateExpectationHandler? = nil) {
internal init(predicate: NSPredicate, object: AnyObject, description: String, file: StaticString, line: UInt, testCase: XCTestCase, handler: XCPredicateExpectationHandler? = nil) {
self.predicate = predicate
self.object = object
self.handler = handler
Expand Down
10 changes: 5 additions & 5 deletions Sources/XCTest/Public/XCTestCase+Asynchronous.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public extension XCTestCase {
// been fulfilled, it would be more efficient to use a runloop
// source that can be signaled to wake up when an expectation is
// fulfilled.
let runLoop = RunLoop.current()
let runLoop = RunLoop.current
let timeoutDate = Date(timeIntervalSinceNow: timeout)
repeat {
unfulfilledDescriptions = []
Expand Down Expand Up @@ -171,14 +171,14 @@ public extension XCTestCase {
var observer: NSObjectProtocol? = nil
func removeObserver() {
if let observer = observer as? AnyObject {
NotificationCenter.defaultCenter().removeObserver(observer)
NotificationCenter.default.removeObserver(observer)
}
}

weak var weakExpectation = expectation
observer = NotificationCenter
.defaultCenter()
.addObserverForName(Notification.Name(rawValue: notificationName),
.default
.addObserver(forName: Notification.Name(rawValue: notificationName),
object: objectToObserve,
queue: nil,
usingBlock: {
Expand Down Expand Up @@ -226,7 +226,7 @@ public extension XCTestCase {
/// first successful evaluation will fulfill the expectation. If provided,
/// the handler can override that behavior which leaves the caller
/// responsible for fulfilling the expectation.
func expectation(for predicate: Predicate, evaluatedWith object: AnyObject, file: StaticString = #file, line: UInt = #line, handler: XCPredicateExpectationHandler? = nil) -> XCTestExpectation {
func expectation(for predicate: NSPredicate, evaluatedWith object: AnyObject, file: StaticString = #file, line: UInt = #line, handler: XCPredicateExpectationHandler? = nil) -> XCTestExpectation {
let expectation = XCPredicateExpectation(
predicate: predicate,
object: object,
Expand Down
2 changes: 1 addition & 1 deletion Sources/XCTest/Public/XCTestMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
/// - Parameter testCases: An array of test cases run, each produced by a call to the `testCase` function
/// - seealso: `testCase`
public func XCTMain(_ testCases: [XCTestCaseEntry]) -> Never {
let testBundle = Bundle.main()
let testBundle = Bundle.main

let executionMode = ArgumentParser().executionMode

Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Asynchronous/Expectations/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ExpectationsTestCase: XCTestCase {
let timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: false) { _ in
expectation.fulfill()
}
RunLoop.current().add(timer, forMode: .defaultRunLoopMode)
RunLoop.current.add(timer, forMode: .defaultRunLoopMode)
waitForExpectations(timeout: 1.0)
}

Expand All @@ -59,7 +59,7 @@ class ExpectationsTestCase: XCTestCase {
let timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { _ in
expectation.fulfill()
}
RunLoop.current().add(timer, forMode: .defaultRunLoopMode)
RunLoop.current.add(timer, forMode: .defaultRunLoopMode)
waitForExpectations(timeout: 0.1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class NotificationExpectationsTestCase: XCTestCase {
func test_observeNotificationWithName_passes() {
let notificationName = "notificationWithNameTest"
expectation(forNotification: notificationName, object:nil)
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: notificationName), object: nil)
NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object: nil)
waitForExpectations(timeout: 0.0)
}

Expand All @@ -31,7 +31,7 @@ class NotificationExpectationsTestCase: XCTestCase {
let notificationName = "notificationWithNameAndObjectTest"
let dummyObject = NSObject()
expectation(forNotification: notificationName, object:dummyObject)
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: notificationName), object: dummyObject)
NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object: dummyObject)
waitForExpectations(timeout: 0.0)
}

Expand All @@ -41,7 +41,7 @@ class NotificationExpectationsTestCase: XCTestCase {
let notificationName = "notificationWithNameAndObject_expectNoObjectTest"
expectation(forNotification: notificationName, object:nil)
let dummyObject = NSObject()
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: notificationName), object: dummyObject)
NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object: dummyObject)
waitForExpectations(timeout: 0.0)
}

Expand All @@ -50,7 +50,7 @@ class NotificationExpectationsTestCase: XCTestCase {
// CHECK: Test Case 'NotificationExpectationsTestCase.test_observeNotificationWithIncorrectName_fails' failed \(\d+\.\d+ seconds\).
func test_observeNotificationWithIncorrectName_fails() {
expectation(forNotification: "expectedName", object: nil)
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: "actualName"), object: nil)
NotificationCenter.default.post(name: Notification.Name(rawValue: "actualName"), object: nil)
waitForExpectations(timeout: 0.1)
}

Expand All @@ -62,7 +62,7 @@ class NotificationExpectationsTestCase: XCTestCase {
let dummyObject: NSString = "dummyObject"
let anotherDummyObject = NSObject()
expectation(forNotification: notificationName, object: dummyObject)
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: notificationName), object:anotherDummyObject)
NotificationCenter.default.post(name: Notification.Name(rawValue: notificationName), object:anotherDummyObject)
waitForExpectations(timeout: 0.1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NotificationHandlerTestCase: XCTestCase {
notification in
return false
})
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: "returnFalse"), object: nil)
NotificationCenter.default.post(name: Notification.Name(rawValue: "returnFalse"), object: nil)
waitForExpectations(timeout: 0.1)
}

Expand All @@ -34,7 +34,7 @@ class NotificationHandlerTestCase: XCTestCase {
notification in
return true
})
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: "returnTrue"), object: nil)
NotificationCenter.default.post(name: Notification.Name(rawValue: "returnTrue"), object: nil)
waitForExpectations(timeout: 0.1)
}

Expand All @@ -47,7 +47,7 @@ class NotificationHandlerTestCase: XCTestCase {
return true
})
waitForExpectations(timeout: 0.1, handler: nil)
NotificationCenter.defaultCenter().postNotificationName(Notification.Name(rawValue: "note"), object: nil)
NotificationCenter.default.post(name: Notification.Name(rawValue: "note"), object: nil)
}

static var allTests = {
Expand Down
11 changes: 6 additions & 5 deletions Tests/Functional/Asynchronous/Predicates/Expectations/main.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %{swiftc} %s -o %T/Asynchronous-Predicates
// RUN: %T/Asynchronous-Predicates > %t || true
// RUN: %{xctest_checker} %t %s
// Disabled due to: https://bugs.swift.org/browse/SR-2332
// xxx: %{xctest_checker} %t %s

#if os(Linux) || os(FreeBSD)
import XCTest
Expand All @@ -18,7 +19,7 @@ class PredicateExpectationsTestCase: XCTestCase {
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyTruePredicateAndObject_passes' started at \d+:\d+:\d+\.\d+
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyTruePredicateAndObject_passes' passed \(\d+\.\d+ seconds\).
func test_immediatelyTruePredicateAndObject_passes() {
let predicate = Predicate(value: true)
let predicate = NSPredicate(value: true)
let object = NSObject()
expectation(for: predicate, evaluatedWith: object)
waitForExpectations(timeout: 0.1)
Expand All @@ -28,7 +29,7 @@ class PredicateExpectationsTestCase: XCTestCase {
// CHECK: .*/Tests/Functional/Asynchronous/Predicates/Expectations/main.swift:[[@LINE+6]]: error: PredicateExpectationsTestCase.test_immediatelyFalsePredicateAndObject_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect `<Predicate: 0x[0-9A-Fa-f]{1,16}>` for object <NSObject: 0x[0-9A-Fa-f]{1,16}>
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyFalsePredicateAndObject_fails' failed \(\d+\.\d+ seconds\).
func test_immediatelyFalsePredicateAndObject_fails() {
let predicate = Predicate(value: false)
let predicate = NSPredicate(value: false)
let object = NSObject()
expectation(for: predicate, evaluatedWith: object)
waitForExpectations(timeout: 0.1)
Expand All @@ -38,7 +39,7 @@ class PredicateExpectationsTestCase: XCTestCase {
// CHECK: Test Case 'PredicateExpectationsTestCase.test_delayedTruePredicateAndObject_passes' passed \(\d+\.\d+ seconds\).
func test_delayedTruePredicateAndObject_passes() {
var didEvaluate = false
let predicate = Predicate(block: { evaluatedObject, bindings in
let predicate = NSPredicate(block: { evaluatedObject, bindings in
defer { didEvaluate = true }
return didEvaluate
})
Expand All @@ -50,7 +51,7 @@ class PredicateExpectationsTestCase: XCTestCase {
// CHECK: Test Case 'PredicateExpectationsTestCase.test_immediatelyTrueDelayedFalsePredicateAndObject_passes' passed \(\d+\.\d+ seconds\).
func test_immediatelyTrueDelayedFalsePredicateAndObject_passes() {
var didEvaluate = false
let predicate = Predicate(block: { evaluatedObject, bindings in
let predicate = NSPredicate(block: { evaluatedObject, bindings in
defer { didEvaluate = true }
return !didEvaluate
})
Expand Down
10 changes: 5 additions & 5 deletions Tests/Functional/Asynchronous/Predicates/Handler/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ class PredicateHandlerTestCase: XCTestCase {
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsTrue_passes' started at \d+:\d+:\d+\.\d+
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsTrue_passes' passed \(\d+\.\d+ seconds\).
func test_predicateIsTrue_handlerReturnsTrue_passes() {
let predicate = Predicate(value: true)
let predicate = NSPredicate(value: true)
let object = NSObject()
self.expectation(for: predicate, evaluatedWith: object, handler: { _ in
return true
})
waitForExpectations(timeout: 0.1)
}
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsFalse_fails' started at \d+:\d+:\d+\.\d+
// CHECK: .*/Tests/Functional/Asynchronous/Predicates/Handler/main.swift:[[@LINE+8]]: error: PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsFalse_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect `<Predicate: 0x[0-9a-fA-F]{1,16}>` for object <NSObject: 0x[0-9a-fA-F]{1,16}>
// CHECK: .*/Tests/Functional/Asynchronous/Predicates/Handler/main.swift:[[@LINE+8]]: error: PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsFalse_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect `<NSPredicate: 0x[0-9a-fA-F]{1,16}>` for object <NSObject: 0x[0-9a-fA-F]{1,16}>
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrue_handlerReturnsFalse_fails' failed \(\d+\.\d+ seconds\).
func test_predicateIsTrue_handlerReturnsFalse_fails() {
let predicate = Predicate(value: true)
let predicate = NSPredicate(value: true)
let object = NSObject()
self.expectation(for: predicate, evaluatedWith: object, handler: { _ in
return false
Expand All @@ -38,11 +38,11 @@ class PredicateHandlerTestCase: XCTestCase {
}

// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails' started at \d+:\d+:\d+\.\d+
// CHECK: .*/Tests/Functional/Asynchronous/Predicates/Handler/main.swift:[[@LINE+14]]: error: PredicateHandlerTestCase.test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect `<Predicate: 0x[0-9a-fA-F]{1,16}>` for object \d{4}-\d{2}-\d{2} \d+:\d+:\d+ \+\d+
// CHECK: .*/Tests/Functional/Asynchronous/Predicates/Handler/main.swift:[[@LINE+14]]: error: PredicateHandlerTestCase.test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: Expect `<NSPredicate: 0x[0-9a-fA-F]{1,16}>` for object \d{4}-\d{2}-\d{2} \d+:\d+:\d+ \+\d+
// CHECK: Test Case 'PredicateHandlerTestCase.test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails' failed \(\d+\.\d+ seconds\).
func test_predicateIsTrueAfterTimeout_handlerIsNotCalled_fails() {
let halfSecLaterDate = NSDate(timeIntervalSinceNow: 0.2)
let predicate = Predicate(block: { evaluatedObject, bindings in
let predicate = NSPredicate(block: { evaluatedObject, bindings in
if let evaluatedDate = evaluatedObject as? NSDate {
return evaluatedDate.compare(Date()) == ComparisonResult.orderedAscending
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/Performance/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class PerformanceTestCase: XCTestCase {
// CHECK: .*/Performance/main.swift:[[@LINE+1]]: error: PerformanceTestCase.test_measuresWallClockTimeInBlock : failed: The relative standard deviation of the measurements is \d+.\d{3}% which is higher than the max allowed of \d+.\d{3}%.
measure {
if !hasWaited {
Thread.sleepForTimeInterval(1)
Thread.sleep(forTimeInterval: 1)
hasWaited = true
}
}
Expand Down