Skip to content

Commit 2e5c2d7

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 2e5c2d7

19 files changed

+77
-77
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

0 commit comments

Comments
 (0)