Skip to content

Commit 0d488a3

Browse files
committed
Migrate from UInt -> Int
Prior to Swift 4, several XCTest APIs were brought into Swift using the `UInt` type, in contrast to other Apple system frameworks which consistently used `Int`. In Swift 4, XCTest began being treated as a system framework and now uses `Int` as well. This change adapts the swift-corelibs-xctest API to match.
1 parent 73190ac commit 0d488a3

19 files changed

+48
-48
lines changed

Sources/XCTest/Private/PerformanceMeter.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,22 @@ internal protocol PerformanceMeterDelegate {
4040
/// as average, and standard deviation
4141
/// - Parameter file: The source file name where the measurement was invoked
4242
/// - Parameter line: The source line number where the measurement was invoked
43-
func recordMeasurements(results: String, file: StaticString, line: UInt)
43+
func recordMeasurements(results: String, file: StaticString, line: Int)
4444

4545
/// Reports a test failure from the analysis of performance measurements.
4646
/// This can currently be caused by an unexpectedly large standard deviation
4747
/// calculated over the data.
4848
/// - Parameter description: An explanation of the failure
4949
/// - Parameter file: The source file name where the measurement was invoked
5050
/// - Parameter line: The source line number where the measurement was invoked
51-
func recordFailure(description: String, file: StaticString, line: UInt)
51+
func recordFailure(description: String, file: StaticString, line: Int)
5252

5353
/// Reports a misuse of the `PerformanceMeter` API, such as calling `
5454
/// startMeasuring` multiple times.
5555
/// - Parameter description: An explanation of the misuse
5656
/// - Parameter file: The source file name where the misuse occurred
5757
/// - Parameter line: The source line number where the misuse occurred
58-
func recordAPIViolation(description: String, file: StaticString, line: UInt)
58+
func recordAPIViolation(description: String, file: StaticString, line: Int)
5959
}
6060

6161
/// - Bug: This class is intended to be `internal` but is public to work around
@@ -97,16 +97,16 @@ public final class PerformanceMeter {
9797
private let metrics: [PerformanceMetric]
9898
private let delegate: PerformanceMeterDelegate
9999
private let invocationFile: StaticString
100-
private let invocationLine: UInt
100+
private let invocationLine: Int
101101

102-
private init(metrics: [PerformanceMetric], delegate: PerformanceMeterDelegate, file: StaticString, line: UInt) {
102+
private init(metrics: [PerformanceMetric], delegate: PerformanceMeterDelegate, file: StaticString, line: Int) {
103103
self.metrics = metrics
104104
self.delegate = delegate
105105
self.invocationFile = file
106106
self.invocationLine = line
107107
}
108108

109-
static func measureMetrics(_ metricNames: [String], delegate: PerformanceMeterDelegate, file: StaticString = #file, line: UInt = #line, for block: (PerformanceMeter) -> Void) {
109+
static func measureMetrics(_ metricNames: [String], delegate: PerformanceMeterDelegate, file: StaticString = #file, line: Int = #line, for block: (PerformanceMeter) -> Void) {
110110
do {
111111
let metrics = try self.metrics(forNames: metricNames)
112112
let meter = PerformanceMeter(metrics: metrics, delegate: delegate, file: file, line: line)
@@ -116,15 +116,15 @@ public final class PerformanceMeter {
116116
}
117117
}
118118

119-
func startMeasuring(file: StaticString = #file, line: UInt = #line) {
119+
func startMeasuring(file: StaticString = #file, line: Int = #line) {
120120
guard state == .iterationUnstarted else {
121121
return recordAPIViolation(.startMeasuringAlreadyCalled, file: file, line: line)
122122
}
123123
state = .iterationStarted
124124
metrics.forEach { $0.startMeasuring() }
125125
}
126126

127-
func stopMeasuring(file: StaticString = #file, line: UInt = #line) {
127+
func stopMeasuring(file: StaticString = #file, line: Int = #line) {
128128
guard state != .iterationUnstarted else {
129129
return recordAPIViolation(.stopBeforeStarting, file: file, line: line)
130130
}
@@ -195,7 +195,7 @@ public final class PerformanceMeter {
195195
}
196196
}
197197

198-
private func recordAPIViolation(_ error: Error, file: StaticString, line: UInt) {
198+
private func recordAPIViolation(_ error: Error, file: StaticString, line: Int) {
199199
state = .measurementAborted
200200
delegate.recordAPIViolation(description: String(describing: error), file: file, line: line)
201201
}

Sources/XCTest/Private/PrintObserver.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal class PrintObserver: XCTestObservation {
2424
printAndFlush("Test Case '\(testCase.name)' started at \(dateFormatter.string(from: testCase.testRun!.startDate!))")
2525
}
2626

27-
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {
27+
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: Int) {
2828
let file = filePath ?? "<unknown>"
2929
printAndFlush("\(file):\(lineNumber): error: \(testCase.name) : \(description)")
3030
}
@@ -68,7 +68,7 @@ internal class PrintObserver: XCTestObservation {
6868
}
6969

7070
extension PrintObserver: XCTestInternalObservation {
71-
func testCase(_ testCase: XCTestCase, didMeasurePerformanceResults results: String, file: StaticString, line: UInt) {
71+
func testCase(_ testCase: XCTestCase, didMeasurePerformanceResults results: String, file: StaticString, line: Int) {
7272
printAndFlush("\(file):\(line): Test Case '\(testCase.name)' measured \(results)")
7373
}
7474
}

Sources/XCTest/Private/XCPredicateExpectation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal class XCPredicateExpectation: XCTestExpectation {
1818
internal let handler: XCPredicateExpectationHandler?
1919
private let evaluationInterval = 0.01
2020

21-
internal init(predicate: NSPredicate, object: AnyObject, description: String, file: StaticString, line: UInt, testCase: XCTestCase, handler: XCPredicateExpectationHandler? = nil) {
21+
internal init(predicate: NSPredicate, object: AnyObject, description: String, file: StaticString, line: Int, testCase: XCTestCase, handler: XCPredicateExpectationHandler? = nil) {
2222
self.predicate = predicate
2323
self.object = object
2424
self.handler = handler

Sources/XCTest/Private/XCTestInternalObservation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ internal protocol XCTestInternalObservation: XCTestObservation {
2323
/// reported, if available.
2424
/// - Parameter line: The line number in the source file where the failure
2525
/// was reported.
26-
func testCase(_ testCase: XCTestCase, didMeasurePerformanceResults results: String, file: StaticString, line: UInt)
26+
func testCase(_ testCase: XCTestCase, didMeasurePerformanceResults results: String, file: StaticString, line: Int)
2727
}
2828

2929
// All `XCInternalTestObservation` methods are optional, so empty default implementations are provided
3030
internal extension XCTestInternalObservation {
31-
func testCase(_ testCase: XCTestCase, didMeasurePerformanceResults results: String, file: StaticString, line: UInt) {}
31+
func testCase(_ testCase: XCTestCase, didMeasurePerformanceResults results: String, file: StaticString, line: Int) {}
3232
}

Sources/XCTest/Public/Asynchronous/XCTestCase+Asynchronous.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public extension XCTestCase {
3333
/// between these environments. To ensure compatibility of tests between
3434
/// swift-corelibs-xctest and Apple XCTest, it is not recommended to pass
3535
/// explicit values for `file` and `line`.
36-
@discardableResult func expectation(description: String, file: StaticString = #file, line: UInt = #line) -> XCTestExpectation {
36+
@discardableResult func expectation(description: String, file: StaticString = #file, line: Int = #line) -> XCTestExpectation {
3737
let expectation = XCTestExpectation(
3838
description: description,
3939
file: file,
@@ -68,7 +68,7 @@ public extension XCTestCase {
6868
/// these environments. To ensure compatibility of tests between
6969
/// swift-corelibs-xctest and Apple XCTest, it is not recommended to pass
7070
/// explicit values for `file` and `line`.
71-
func waitForExpectations(timeout: TimeInterval, file: StaticString = #file, line: UInt = #line, handler: XCWaitCompletionHandler? = nil) {
71+
func waitForExpectations(timeout: TimeInterval, file: StaticString = #file, line: Int = #line, handler: XCWaitCompletionHandler? = nil) {
7272
// Mirror Objective-C XCTest behavior; display an unexpected test
7373
// failure when users wait without having first set expectations.
7474
// FIXME: Objective-C XCTest raises an exception for most "API

Sources/XCTest/Public/Asynchronous/XCTestCase+PredicateExpectation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public extension XCTestCase {
3333
/// first successful evaluation will fulfill the expectation. If provided,
3434
/// the handler can override that behavior which leaves the caller
3535
/// responsible for fulfilling the expectation.
36-
@discardableResult func expectation(for predicate: NSPredicate, evaluatedWith object: AnyObject, file: StaticString = #file, line: UInt = #line, handler: XCPredicateExpectationHandler? = nil) -> XCTestExpectation {
36+
@discardableResult func expectation(for predicate: NSPredicate, evaluatedWith object: AnyObject, file: StaticString = #file, line: Int = #line, handler: XCPredicateExpectationHandler? = nil) -> XCTestExpectation {
3737
let expectation = XCPredicateExpectation(
3838
predicate: predicate,
3939
object: object,

Sources/XCTest/Public/Asynchronous/XCTestExpectation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
public class XCTestExpectation {
1616
internal let description: String
1717
internal let file: StaticString
18-
internal let line: UInt
18+
internal let line: Int
1919

2020
internal var isFulfilled = false
2121
internal weak var testCase: XCTestCase?
2222

23-
internal init(description: String, file: StaticString, line: UInt, testCase: XCTestCase) {
23+
internal init(description: String, file: StaticString, line: Int, testCase: XCTestCase) {
2424
self.description = description
2525
self.file = file
2626
self.line = line
@@ -47,7 +47,7 @@ public class XCTestExpectation {
4747
/// between these environments. To ensure compatibility of tests between
4848
/// swift-corelibs-xctest and Apple XCTest, it is not recommended to pass
4949
/// explicit values for `file` and `line`.
50-
public func fulfill(_ file: StaticString = #file, line: UInt = #line) {
50+
public func fulfill(_ file: StaticString = #file, line: Int = #line) {
5151
// FIXME: Objective-C XCTest emits failures when expectations are
5252
// fulfilled after the test cases that generated those
5353
// expectations have completed. Similarly, this should cause an

Sources/XCTest/Public/XCAbstractTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ open class XCTest {
2222
}
2323

2424
/// Number of test cases. Must be overridden by subclasses.
25-
open var testCaseCount: UInt {
25+
open var testCaseCount: Int {
2626
fatalError("Must be overridden by subclasses.")
2727
}
2828

Sources/XCTest/Public/XCTAssert.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private func _XCTEvaluateAssertion(_ assertion: _XCTAssertion, message: @autoclo
9393
currentTestCase.recordFailure(
9494
withDescription: "\(result.failureDescription(assertion)) - \(message())",
9595
inFile: String(describing: file),
96-
atLine: line,
96+
atLine: Int(line),
9797
expected: result.isExpected)
9898
}
9999
}

Sources/XCTest/Public/XCTestCase+Performance.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public extension XCTestCase {
4949
/// these methods are not exactly identical between these environments. To
5050
/// ensure compatibility of tests between swift-corelibs-xctest and Apple
5151
/// XCTest, it is not recommended to pass explicit values for `file` and `line`.
52-
func measure(file: StaticString = #file, line: UInt = #line, block: () -> Void) {
52+
func measure(file: StaticString = #file, line: Int = #line, block: () -> Void) {
5353
measureMetrics(type(of: self).defaultPerformanceMetrics(),
5454
automaticallyStartMeasuring: true,
5555
file: file,
@@ -103,7 +103,7 @@ public extension XCTestCase {
103103
/// these methods are not exactly identical between these environments. To
104104
/// ensure compatibility of tests between swift-corelibs-xctest and Apple
105105
/// XCTest, it is not recommended to pass explicit values for `file` and `line`.
106-
func measureMetrics(_ metrics: [String], automaticallyStartMeasuring: Bool, file: StaticString = #file, line: UInt = #line, for block: () -> Void) {
106+
func measureMetrics(_ metrics: [String], automaticallyStartMeasuring: Bool, file: StaticString = #file, line: Int = #line, for block: () -> Void) {
107107
guard _performanceMeter == nil else {
108108
return recordAPIViolation(description: "Can only record one set of metrics per test method.", file: file, line: line)
109109
}
@@ -125,7 +125,7 @@ public extension XCTestCase {
125125
/// these methods are not exactly identical between these environments. To
126126
/// ensure compatibility of tests between swift-corelibs-xctest and Apple
127127
/// XCTest, it is not recommended to pass explicit values for `file` and `line`.
128-
func startMeasuring(file: StaticString = #file, line: UInt = #line) {
128+
func startMeasuring(file: StaticString = #file, line: Int = #line) {
129129
guard let performanceMeter = _performanceMeter, !performanceMeter.didFinishMeasuring else {
130130
return recordAPIViolation(description: "Cannot start measuring. startMeasuring() is only supported from a block passed to measureMetrics(...).", file: file, line: line)
131131
}
@@ -140,7 +140,7 @@ public extension XCTestCase {
140140
/// these methods are not exactly identical between these environments. To
141141
/// ensure compatibility of tests between swift-corelibs-xctest and Apple
142142
/// XCTest, it is not recommended to pass explicit values for `file` and `line`.
143-
func stopMeasuring(file: StaticString = #file, line: UInt = #line) {
143+
func stopMeasuring(file: StaticString = #file, line: Int = #line) {
144144
guard let performanceMeter = _performanceMeter, !performanceMeter.didFinishMeasuring else {
145145
return recordAPIViolation(description: "Cannot stop measuring. stopMeasuring() is only supported from a block passed to measureMetrics(...).", file: file, line: line)
146146
}
@@ -149,18 +149,18 @@ public extension XCTestCase {
149149
}
150150

151151
extension XCTestCase: PerformanceMeterDelegate {
152-
internal func recordAPIViolation(description: String, file: StaticString, line: UInt) {
152+
internal func recordAPIViolation(description: String, file: StaticString, line: Int) {
153153
recordFailure(withDescription: "API violation - \(description)",
154154
inFile: String(describing: file),
155155
atLine: line,
156156
expected: false)
157157
}
158158

159-
internal func recordMeasurements(results: String, file: StaticString, line: UInt) {
159+
internal func recordMeasurements(results: String, file: StaticString, line: Int) {
160160
XCTestObservationCenter.shared().testCase(self, didMeasurePerformanceResults: results, file: file, line: line)
161161
}
162162

163-
internal func recordFailure(description: String, file: StaticString, line: UInt) {
163+
internal func recordFailure(description: String, file: StaticString, line: Int) {
164164
recordFailure(withDescription: "failed: " + description, inFile: String(describing: file), atLine: line, expected: true)
165165
}
166166
}

Sources/XCTest/Public/XCTestCase.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ open class XCTestCase: XCTest {
3737
/// A private setter for the name of this test case.
3838
private var _name: String
3939

40-
open override var testCaseCount: UInt {
40+
open override var testCaseCount: Int {
4141
return 1
4242
}
4343

@@ -99,7 +99,7 @@ open class XCTestCase: XCTest {
9999
/// - Parameter expected: `true` if the failure being reported was the
100100
/// result of a failed assertion, `false` if it was the result of an
101101
/// uncaught exception.
102-
open func recordFailure(withDescription description: String, inFile filePath: String, atLine lineNumber: UInt, expected: Bool) {
102+
open func recordFailure(withDescription description: String, inFile filePath: String, atLine lineNumber: Int, expected: Bool) {
103103
testRun?.recordFailure(
104104
withDescription: description,
105105
inFile: filePath,

Sources/XCTest/Public/XCTestCaseRun.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ open class XCTestCaseRun: XCTestRun {
2323
XCTestObservationCenter.shared().testCaseDidFinish(testCase)
2424
}
2525

26-
open override func recordFailure(withDescription description: String, inFile filePath: String?, atLine lineNumber: UInt, expected: Bool) {
26+
open override func recordFailure(withDescription description: String, inFile filePath: String?, atLine lineNumber: Int, expected: Bool) {
2727
super.recordFailure(
2828
withDescription: "\(test.name) : \(description)",
2929
inFile: filePath,

Sources/XCTest/Public/XCTestObservation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public protocol XCTestObservation: class {
3939
/// was reported, if available.
4040
/// - Parameter lineNumber: The line number in the source file where the
4141
/// failure was reported.
42-
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt)
42+
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: Int)
4343

4444
/// Called just after a test finishes executing.
4545
/// - Parameter testCase: The test case that finished. Its `name` property
@@ -66,7 +66,7 @@ public extension XCTestObservation {
6666
func testBundleWillStart(_ testBundle: Bundle) {}
6767
func testSuiteWillStart(_ testSuite: XCTestSuite) {}
6868
func testCaseWillStart(_ testCase: XCTestCase) {}
69-
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {}
69+
func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: Int) {}
7070
func testCaseDidFinish(_ testCase: XCTestCase) {}
7171
func testSuiteDidFinish(_ testSuite: XCTestSuite) {}
7272
func testBundleDidFinish(_ testBundle: Bundle) {}

Sources/XCTest/Public/XCTestObservationCenter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class XCTestObservationCenter {
4949
forEachObserver { $0.testCaseWillStart(testCase) }
5050
}
5151

52-
internal func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: UInt) {
52+
internal func testCase(_ testCase: XCTestCase, didFailWithDescription description: String, inFile filePath: String?, atLine lineNumber: Int) {
5353
forEachObserver { $0.testCase(testCase, didFailWithDescription: description, inFile: filePath, atLine: lineNumber) }
5454
}
5555

@@ -65,7 +65,7 @@ public class XCTestObservationCenter {
6565
forEachObserver { $0.testBundleDidFinish(testBundle) }
6666
}
6767

68-
internal func testCase(_ testCase: XCTestCase, didMeasurePerformanceResults results: String, file: StaticString, line: UInt) {
68+
internal func testCase(_ testCase: XCTestCase, didMeasurePerformanceResults results: String, file: StaticString, line: Int) {
6969
forEachInternalObserver { $0.testCase(testCase, didMeasurePerformanceResults: results, file: file, line: line) }
7070
}
7171

Sources/XCTest/Public/XCTestRun.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,22 @@ open class XCTestRun {
4242
}
4343

4444
/// The number of tests in the run.
45-
open var testCaseCount: UInt {
45+
open var testCaseCount: Int {
4646
return test.testCaseCount
4747
}
4848

4949
/// The number of test executions recorded during the run.
50-
open private(set) var executionCount: UInt = 0
50+
open private(set) var executionCount: Int = 0
5151

5252
/// The number of test failures recorded during the run.
53-
open private(set) var failureCount: UInt = 0
53+
open private(set) var failureCount: Int = 0
5454

5555
/// The number of uncaught exceptions recorded during the run.
56-
open private(set) var unexpectedExceptionCount: UInt = 0
56+
open private(set) var unexpectedExceptionCount: Int = 0
5757

5858
/// The total number of test failures and uncaught exceptions recorded
5959
/// during the run.
60-
open var totalFailureCount: UInt {
60+
open var totalFailureCount: Int {
6161
return failureCount + unexpectedExceptionCount
6262
}
6363

@@ -118,7 +118,7 @@ open class XCTestRun {
118118
/// - Parameter expected: `true` if the failure being reported was the
119119
/// result of a failed assertion, `false` if it was the result of an
120120
/// uncaught exception.
121-
func recordFailure(withDescription description: String, inFile filePath: String?, atLine lineNumber: UInt, expected: Bool) {
121+
func recordFailure(withDescription description: String, inFile filePath: String?, atLine lineNumber: Int, expected: Bool) {
122122
guard isStarted else {
123123
fatalError("Invalid attempt to record a failure for a test run " +
124124
"that has not yet been started: \(self)")

Sources/XCTest/Public/XCTestSuite.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ open class XCTestSuite: XCTest {
3030
private let _name: String
3131

3232
/// The number of test cases in this suite.
33-
open override var testCaseCount: UInt {
33+
open override var testCaseCount: Int {
3434
return tests.reduce(0) { $0 + $1.testCaseCount }
3535
}
3636

0 commit comments

Comments
 (0)