Skip to content

Commit 685f31b

Browse files
[stdlib] Migrate stdlib tests of Swift 3 (#17427)
* First sweep of Swift 3 stdlib test upgrades * Review feedback * Remove a handful more #if >=4.0 * Fix up Dictionary tests
1 parent e34c409 commit 685f31b

17 files changed

+295
-556
lines changed

benchmark/single-source/ByteSwap.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public let ByteSwap = BenchmarkInfo(
2424
// a naive O(n) implementation of byteswap.
2525
@inline(never)
2626
func byteswap_n(_ a: UInt64) -> UInt64 {
27-
#if swift(>=4)
2827
return ((a & 0x00000000000000FF) &<< 56) |
2928
((a & 0x000000000000FF00) &<< 40) |
3029
((a & 0x0000000000FF0000) &<< 24) |
@@ -33,16 +32,6 @@ func byteswap_n(_ a: UInt64) -> UInt64 {
3332
((a & 0x0000FF0000000000) &>> 24) |
3433
((a & 0x00FF000000000000) &>> 40) |
3534
((a & 0xFF00000000000000) &>> 56)
36-
#else
37-
return ((a & 0x00000000000000FF) << 56) |
38-
((a & 0x000000000000FF00) << 40) |
39-
((a & 0x0000000000FF0000) << 24) |
40-
((a & 0x00000000FF000000) << 8) |
41-
((a & 0x000000FF00000000) >> 8) |
42-
((a & 0x0000FF0000000000) >> 24) |
43-
((a & 0x00FF000000000000) >> 40) |
44-
((a & 0xFF00000000000000) >> 56)
45-
#endif
4635
}
4736

4837
// a O(logn) implementation of byteswap.

stdlib/private/StdlibUnittest/StdlibUnittest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,8 +3010,8 @@ public func expectEqualMethodsForDomain<
30103010
}
30113011
}
30123012

3013-
public func expectEqualUnicodeScalars(
3014-
_ expected: [UInt32], _ actual: String,
3013+
public func expectEqualUnicodeScalars<S: StringProtocol>(
3014+
_ expected: [UInt32], _ actual: S,
30153015
_ message: @autoclosure () -> String = "",
30163016
stackTrace: SourceLocStack = SourceLocStack(),
30173017
showFrame: Bool = true,

test/stdlib/Dispatch.swift

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift %s -o %t/a.out_swift3 -swift-version 3
3-
// RUN: %target-build-swift %s -o %t/a.out_swift4 -swift-version 4
2+
// RUN: %target-build-swift %s -o %t/a.out
43
//
5-
// RUN: %target-run %t/a.out_swift3
6-
// RUN: %target-run %t/a.out_swift4
4+
// RUN: %target-run %t/a.out
75
// REQUIRES: executable_test
86

97
// REQUIRES: objc_interop
@@ -40,7 +38,7 @@ DispatchAPI.test("DispatchGroup creation") {
4038
}
4139

4240
DispatchAPI.test("Dispatch sync return value") {
43-
let value = 24;
41+
let value = 24
4442
let q = DispatchQueue(label: "Test")
4543
let result = q.sync() { return 24 }
4644
expectEqual(value, result)
@@ -516,14 +514,8 @@ DispatchAPI.test("DispatchData.bufferUnsafeRawBufferPointer") {
516514

517515
DispatchAPI.test("DispatchIO.initRelativePath") {
518516
let q = DispatchQueue(label: "initRelativePath queue")
519-
#if swift(>=4.0)
520517
let chan = DispatchIO(type: .random, path: "_REL_PATH_", oflag: O_RDONLY, mode: 0, queue: q, cleanupHandler: { (error) in })
521518
expectEqual(chan, nil)
522-
#else
523-
expectCrashLater()
524-
let chan = DispatchIO(type: .random, path: "_REL_PATH_", oflag: O_RDONLY, mode: 0, queue: q, cleanupHandler: { (error) in })
525-
chan.setInterval(interval: .seconds(1)) // Dereference of unexpected nil should crash
526-
#endif
527519
}
528520

529521
if #available(OSX 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *) {
@@ -595,11 +587,9 @@ DispatchAPI.test("DispatchTimeInterval") {
595587
expectTrue(t == t) // This would crash.
596588
}
597589

598-
#if swift(>=4.0)
599590
DispatchAPI.test("DispatchTimeInterval.never.equals") {
600591
expectTrue(DispatchTimeInterval.never == DispatchTimeInterval.never)
601592
expectTrue(DispatchTimeInterval.seconds(10) != DispatchTimeInterval.never);
602593
expectTrue(DispatchTimeInterval.never != DispatchTimeInterval.seconds(10));
603594
expectTrue(DispatchTimeInterval.seconds(10) == DispatchTimeInterval.seconds(10));
604595
}
605-
#endif

test/stdlib/Inputs/DictionaryKeyValueTypesObjC.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@ func getBridgedNSDictionaryOfRefTypesBridgedVerbatim() -> NSDictionary {
475475
d[TestObjCKeyTy(20)] = TestObjCValueTy(1020)
476476
d[TestObjCKeyTy(30)] = TestObjCValueTy(1030)
477477

478-
let bridged =
479-
unsafeBitCast(convertDictionaryToNSDictionary(d), to: NSDictionary.self)
478+
let bridged = convertDictionaryToNSDictionary(d)
480479

481480
assert(isNativeNSDictionary(bridged))
482481

@@ -486,8 +485,7 @@ func getBridgedNSDictionaryOfRefTypesBridgedVerbatim() -> NSDictionary {
486485
func getBridgedEmptyNSDictionary() -> NSDictionary {
487486
let d = Dictionary<TestObjCKeyTy, TestObjCValueTy>()
488487

489-
let bridged =
490-
unsafeBitCast(convertDictionaryToNSDictionary(d), to: NSDictionary.self)
488+
let bridged = convertDictionaryToNSDictionary(d)
491489
assert(isNativeNSDictionary(bridged))
492490

493491
return bridged
@@ -874,8 +872,7 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
874872
for i in 0..<3 {
875873
var actualContents = [ExpectedDictionaryElement]()
876874
let sink: (AnyObjectTuple2) -> Void = {
877-
pair in
878-
let (key, value) = pair
875+
let (key, value) = $0
879876
actualContents.append(ExpectedDictionaryElement(
880877
key: convertKey(key),
881878
value: convertValue(value),

test/stdlib/IntegerCompatibility.swift

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
// RUN: %target-build-swift %s -swift-version 3 -typecheck
21
// RUN: %target-build-swift %s -swift-version 4 -typecheck
32

43

54
func byteswap_n(_ a: UInt64) -> UInt64 {
6-
#if swift(>=4)
75
return ((a & 0x00000000000000FF) &<< 56) |
86
((a & 0x000000000000FF00) &<< 40) |
97
((a & 0x0000000000FF0000) &<< 24) |
@@ -12,22 +10,11 @@ func byteswap_n(_ a: UInt64) -> UInt64 {
1210
((a & 0x0000FF0000000000) &>> 24) |
1311
((a & 0x00FF000000000000) &>> 40) |
1412
((a & 0xFF00000000000000) &>> 56)
15-
#else
16-
return ((a & 0x00000000000000FF) << 56) |
17-
((a & 0x000000000000FF00) << 40) |
18-
((a & 0x0000000000FF0000) << 24) |
19-
((a & 0x00000000FF000000) << 8) |
20-
((a & 0x000000FF00000000) >> 8) |
21-
((a & 0x0000FF0000000000) >> 24) |
22-
((a & 0x00FF000000000000) >> 40) |
23-
((a & 0xFF00000000000000) >> 56)
24-
#endif
2513
}
2614

2715

2816
// expression should not be too complex
2917
func radar31845712(_ i: Int, _ buffer: [UInt8]) {
30-
#if swift(>=4)
3118
_ = UInt64(buffer[i])
3219
| (UInt64(buffer[i + 1]) &<< 8)
3320
| (UInt64(buffer[i + 2]) &<< 16)
@@ -36,16 +23,6 @@ func radar31845712(_ i: Int, _ buffer: [UInt8]) {
3623
| (UInt64(buffer[i + 5]) &<< 40)
3724
| (UInt64(buffer[i + 6]) &<< 48)
3825
| (UInt64(buffer[i + 7]) &<< 56)
39-
#else
40-
_ = UInt64(buffer[i])
41-
| (UInt64(buffer[i + 1]) << 8)
42-
| (UInt64(buffer[i + 2]) << 16)
43-
| (UInt64(buffer[i + 3]) << 24)
44-
| (UInt64(buffer[i + 4]) << 32)
45-
| (UInt64(buffer[i + 5]) << 40)
46-
| (UInt64(buffer[i + 6]) << 48)
47-
| (UInt64(buffer[i + 7]) << 56)
48-
#endif
4926
}
5027

5128
// expression should not be too complex
@@ -54,17 +31,10 @@ func radar32149641() {
5431
var val: UInt32 = input
5532
return withUnsafePointer(to: &val) { (ptr: UnsafePointer<UInt32>) -> UInt32 in
5633
return ptr.withMemoryRebound(to: UInt8.self, capacity: 4) { data in
57-
#if swift(>=4)
5834
return (UInt32(data[3]) &<< 0) |
5935
(UInt32(data[2]) &<< 8) |
6036
(UInt32(data[1]) &<< 16) |
6137
(UInt32(data[0]) &<< 24)
62-
#else
63-
return (UInt32(data[3]) << 0) |
64-
(UInt32(data[2]) << 8) |
65-
(UInt32(data[1]) << 16) |
66-
(UInt32(data[0]) << 24)
67-
#endif
6838
}
6939
}
7040
}
@@ -74,11 +44,9 @@ func homogeneousLookingShiftAndAMask(_ i64: Int64) {
7444
_ = (i64 >> 8) & 0xFF
7545
}
7646

77-
#if swift(>=4)
7847
func negativeShift(_ u8: UInt8) {
7948
_ = (u8 << -1)
8049
}
81-
#endif
8250

8351
func sr5176(description: String = "unambiguous Int32.init(bitPattern:)") {
8452
_ = Int32(bitPattern: 0) // should compile without ambiguity

test/stdlib/IntegerDiagnostics.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// RUN: %target-typecheck-verify-swift -swift-version 3
21
// RUN: %target-typecheck-verify-swift -swift-version 4
32

43
func signedBitPattern() {

test/stdlib/LazyCollectionPlus.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/stdlib/LazySlice.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
2+
// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
33
// REQUIRES: executable_test
44

55
import StdlibUnittest
@@ -10,9 +10,8 @@ tests.test("CommuteLazyness") {
1010
let a = [1,2,3].lazy
1111
let b = a[...]
1212
var c = b.filter { $0 == 0 }
13-
// NOTE, this test will fail once lazy collectionness becomes a conditiona
14-
// conformance, and will need updating to be a LazyBidirectional thingy
15-
expectType(LazyFilterBidirectionalCollection<Slice<LazyRandomAccessCollection<[Int]>>>.self, &c)
13+
14+
expectType(LazyFilterCollection<Slice<LazyCollection<[Int]>>>.self, &c)
1615
}
1716

1817
runAllTests()

test/stdlib/MapFilterLayerFoldingCompatibilty.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
32
// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
43
// RUN: %target-build-swift %s -o %t/a.out5 -swift-version 5 && %target-run %t/a.out5
54
// REQUIRES: executable_test

test/stdlib/MixedTypeArithmeticsDiagnostics4.swift

Lines changed: 0 additions & 41 deletions
This file was deleted.

test/stdlib/RangeReplaceableFilterCompatibility.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
32
// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
43

54
// REQUIRES: executable_test
@@ -10,11 +9,7 @@ var tests = TestSuite("RangeReplaceableFilterCompatibility")
109

1110
tests.test("String.filter return type") {
1211
var filtered = "Hello, World".filter { $0 < "A" }
13-
#if swift(>=4)
1412
expectType(String.self, &filtered)
15-
#else
16-
expectType([Character].self, &filtered)
17-
#endif
1813
}
1914

2015
tests.test("Array.filter return type") {

test/stdlib/ReverseCompatibility.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
32
// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
43
// RUN: %target-build-swift %s -o %t/a.out5 -swift-version 5 && %target-run %t/a.out5
54
// REQUIRES: executable_test

0 commit comments

Comments
 (0)