Skip to content

Commit 9431ced

Browse files
committed
Reduce test compile times.
I noticed that the tests were taking quite a while to compile. Using the "-warn-long-expression-type-checking" flag, I measured the compile time of the test project. The total of types over 100ms was around 27 seconds before this change and around 25 seconds after (on my build configuration), so it shaves off a few seconds there. I also took the opportunity to reduce the number of attempted threads in the URL test from 640 to 10. There isn't much value add in going above the number of cores we're going to find on most machines, and that dramatically reduces the run time of that test.
1 parent 08afbe6 commit 9431ced

8 files changed

+35
-20
lines changed

Diff for: TestFoundation/TestDecimal.swift

+7-3
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,15 @@ class TestDecimal: XCTestCase {
180180
}
181181

182182
func test_ExplicitConstruction() {
183+
let reserved: UInt32 = (1<<18 as UInt32) + (1<<17 as UInt32) + 1
184+
let mantissa: (UInt16, UInt16, UInt16, UInt16, UInt16, UInt16, UInt16, UInt16) = (6, 7, 8, 9, 10, 11, 12, 13)
183185
var explicit = Decimal(
184186
_exponent: 0x17f,
185187
_length: 0xff,
186188
_isNegative: 3,
187189
_isCompact: 4,
188-
_reserved: 1<<18 + 1<<17 + 1,
189-
_mantissa: (6, 7, 8, 9, 10, 11, 12, 13)
190+
_reserved: reserved,
191+
_mantissa: mantissa
190192
)
191193
XCTAssertEqual(0x7f, explicit._exponent)
192194
XCTAssertEqual(0x7f, explicit.exponent)
@@ -195,7 +197,9 @@ class TestDecimal: XCTestCase {
195197
XCTAssertEqual(FloatingPointSign.minus, explicit.sign)
196198
XCTAssertTrue(explicit.isSignMinus)
197199
XCTAssertEqual(0, explicit._isCompact)
198-
XCTAssertEqual(UInt32(1<<17 + 1), explicit._reserved)
200+
let i = 1 << 17 + 1
201+
let expectedReserved: UInt32 = UInt32(i)
202+
XCTAssertEqual(expectedReserved, explicit._reserved)
199203
let (m0, m1, m2, m3, m4, m5, m6, m7) = explicit._mantissa
200204
XCTAssertEqual(6, m0)
201205
XCTAssertEqual(7, m1)

Diff for: TestFoundation/TestNSAttributedString.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ fileprivate extension TestNSAttributedString {
236236

237237
fileprivate func describe(attrs: [NSAttributedStringKey : Any]) -> String {
238238
if attrs.count > 0 {
239-
return "[" + attrs.map({ "\($0.rawValue):\($1)" }).sorted(by: { $0 < $1 }).joined(separator: ",") + "]"
239+
let mapped: [String] = attrs.map({ "\($0.rawValue):\($1)" })
240+
let sorted: [String] = mapped.sorted(by: { $0 < $1 })
241+
let joined: String = sorted.joined(separator: ",")
242+
return "[" + joined + "]"
240243
} else {
241244
return "[:]"
242245
}

Diff for: TestFoundation/TestNSKeyedArchiver.swift

+9-6
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,15 @@ class TestNSKeyedArchiver : XCTestCase {
221221
}
222222

223223
func test_archive_mutable_dictionary() {
224-
let mdictionary = NSMutableDictionary(dictionary: [
225-
"one": NSNumber(value: Int(1)),
226-
"two": NSNumber(value: Int(2)),
227-
"three": NSNumber(value: Int(3)),
228-
])
229-
224+
let one: NSNumber = NSNumber(value: Int(1))
225+
let two: NSNumber = NSNumber(value: Int(2))
226+
let three: NSNumber = NSNumber(value: Int(3))
227+
let dict: [String : Any] = [
228+
"one": one,
229+
"two": two,
230+
"three": three,
231+
]
232+
let mdictionary = NSMutableDictionary(dictionary: dict)
230233
test_archive(mdictionary)
231234
}
232235

Diff for: TestFoundation/TestNSNumber.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -1157,8 +1157,12 @@ class TestNSNumber : XCTestCase {
11571157
XCTAssertTrue(NSNumber(value: true) == NSNumber(value: Int8(1)))
11581158
XCTAssertTrue(NSNumber(value: true) != NSNumber(value: false))
11591159
XCTAssertTrue(NSNumber(value: true) != NSNumber(value: Int8(-1)))
1160-
XCTAssertTrue(NSNumber(value: true) != NSNumber(value: Float(1.01)))
1161-
XCTAssertTrue(NSNumber(value: true) != NSNumber(value: Double(1234.56)))
1160+
let f: Float = 1.01
1161+
let floatNum = NSNumber(value: f)
1162+
XCTAssertTrue(NSNumber(value: true) != floatNum)
1163+
let d: Double = 1234.56
1164+
let doubleNum = NSNumber(value: d)
1165+
XCTAssertTrue(NSNumber(value: true) != doubleNum)
11621166
XCTAssertTrue(NSNumber(value: true) != NSNumber(value: 2))
11631167
XCTAssertTrue(NSNumber(value: true) != NSNumber(value: Int.max))
11641168
XCTAssertTrue(NSNumber(value: false) == NSNumber(value: Bool(false)))

Diff for: TestFoundation/TestNumberFormatter.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ class TestNumberFormatter: XCTestCase {
172172
let noPlusString = numberFormatter.string(from: -0.420)
173173
XCTAssertNotNil(noPlusString)
174174
if let fmt = noPlusString {
175-
XCTAssertFalse(fmt.contains(sign), "Expected format of -0.420 (-4.2E-1) shouldn't have a plus sign which was set as \(sign)")
175+
let contains: Bool = fmt.contains(sign)
176+
XCTAssertFalse(contains, "Expected format of -0.420 (-4.2E-1) shouldn't have a plus sign which was set as \(sign)")
176177
}
177178
}
178179

Diff for: TestFoundation/TestURLSession.swift

+1-5
Original file line numberDiff line numberDiff line change
@@ -471,12 +471,8 @@ class TestURLSession : LoopbackServerTest {
471471
}
472472

473473
func test_concurrentRequests() {
474-
#if os(Android)
474+
// "10 tasks ought to be enough for anybody"
475475
let tasks = 10
476-
XCTFail("640 tasks causes other tests to fail on Android")
477-
#else
478-
let tasks = 640
479-
#endif
480476
let syncQ = dispatchQueueMake("test_dataTaskWithURL.syncQ")
481477
var dataTasks: [DataTask] = []
482478
let g = dispatchGroupMake()

Diff for: TestFoundation/TestXMLDocument.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,10 @@ class TestXMLDocument : XCTestCase {
355355
let otherDoc = XMLDocument(rootElement: XMLElement(name: "Bar"))
356356
otherDoc.rootElement()?.namespaces = [XMLNode.namespace(withName: "R", stringValue: "http://example.com/rnamespace") as! XMLNode, XMLNode.namespace(withName: "F", stringValue: "http://example.com/fakenamespace") as! XMLNode]
357357
XCTAssert(otherDoc.rootElement()?.namespaces?.count == 2)
358-
XCTAssert(otherDoc.rootElement()?.namespaces?.flatMap({ $0.name })[0] == "R" && otherDoc.rootElement()?.namespaces?.flatMap({ $0.name })[1] == "F")
358+
let namespaces: [XMLNode]? = otherDoc.rootElement()?.namespaces
359+
let names: [String]? = namespaces?.flatMap { $0.name }
360+
XCTAssertNotNil(names)
361+
XCTAssert(names![0] == "R" && names![1] == "F")
359362
otherDoc.rootElement()?.namespaces = nil
360363
XCTAssert((otherDoc.rootElement()?.namespaces?.count ?? 0) == 0)
361364
}

Diff for: TestFoundation/TestXMLParser.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ class TestXMLParser : XCTestCase {
8484
return xmlUnderTest
8585
}
8686
if let open = encoding.range(of: "(") {
87-
encoding = String(encoding[open.upperBound...])
87+
let range: Range<String.Index> = open.upperBound..<encoding.endIndex
88+
encoding = String(encoding[range])
8889
}
8990
if let close = encoding.range(of: ")") {
9091
encoding = String(encoding[..<close.lowerBound])

0 commit comments

Comments
 (0)