Skip to content

[stdlib] Migrate stdlib tests of Swift 3 #17427

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 4 commits into from
Jul 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions benchmark/single-source/ByteSwap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public let ByteSwap = BenchmarkInfo(
// a naive O(n) implementation of byteswap.
@inline(never)
func byteswap_n(_ a: UInt64) -> UInt64 {
#if swift(>=4)
return ((a & 0x00000000000000FF) &<< 56) |
((a & 0x000000000000FF00) &<< 40) |
((a & 0x0000000000FF0000) &<< 24) |
Expand All @@ -33,16 +32,6 @@ func byteswap_n(_ a: UInt64) -> UInt64 {
((a & 0x0000FF0000000000) &>> 24) |
((a & 0x00FF000000000000) &>> 40) |
((a & 0xFF00000000000000) &>> 56)
#else
return ((a & 0x00000000000000FF) << 56) |
((a & 0x000000000000FF00) << 40) |
((a & 0x0000000000FF0000) << 24) |
((a & 0x00000000FF000000) << 8) |
((a & 0x000000FF00000000) >> 8) |
((a & 0x0000FF0000000000) >> 24) |
((a & 0x00FF000000000000) >> 40) |
((a & 0xFF00000000000000) >> 56)
#endif
}

// a O(logn) implementation of byteswap.
Expand Down
4 changes: 2 additions & 2 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3010,8 +3010,8 @@ public func expectEqualMethodsForDomain<
}
}

public func expectEqualUnicodeScalars(
_ expected: [UInt32], _ actual: String,
public func expectEqualUnicodeScalars<S: StringProtocol>(
_ expected: [UInt32], _ actual: S,
_ message: @autoclosure () -> String = "",
stackTrace: SourceLocStack = SourceLocStack(),
showFrame: Bool = true,
Expand Down
16 changes: 3 additions & 13 deletions test/stdlib/Dispatch.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -o %t/a.out_swift3 -swift-version 3
// RUN: %target-build-swift %s -o %t/a.out_swift4 -swift-version 4
// RUN: %target-build-swift %s -o %t/a.out
//
// RUN: %target-run %t/a.out_swift3
// RUN: %target-run %t/a.out_swift4
// RUN: %target-run %t/a.out
// REQUIRES: executable_test

// REQUIRES: objc_interop
Expand Down Expand Up @@ -40,7 +38,7 @@ DispatchAPI.test("DispatchGroup creation") {
}

DispatchAPI.test("Dispatch sync return value") {
let value = 24;
let value = 24
let q = DispatchQueue(label: "Test")
let result = q.sync() { return 24 }
expectEqual(value, result)
Expand Down Expand Up @@ -516,14 +514,8 @@ DispatchAPI.test("DispatchData.bufferUnsafeRawBufferPointer") {

DispatchAPI.test("DispatchIO.initRelativePath") {
let q = DispatchQueue(label: "initRelativePath queue")
#if swift(>=4.0)
let chan = DispatchIO(type: .random, path: "_REL_PATH_", oflag: O_RDONLY, mode: 0, queue: q, cleanupHandler: { (error) in })
expectEqual(chan, nil)
#else
expectCrashLater()
let chan = DispatchIO(type: .random, path: "_REL_PATH_", oflag: O_RDONLY, mode: 0, queue: q, cleanupHandler: { (error) in })
chan.setInterval(interval: .seconds(1)) // Dereference of unexpected nil should crash
#endif
}

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

#if swift(>=4.0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the RUN: line for -swift-version 3 too?

DispatchAPI.test("DispatchTimeInterval.never.equals") {
expectTrue(DispatchTimeInterval.never == DispatchTimeInterval.never)
expectTrue(DispatchTimeInterval.seconds(10) != DispatchTimeInterval.never);
expectTrue(DispatchTimeInterval.never != DispatchTimeInterval.seconds(10));
expectTrue(DispatchTimeInterval.seconds(10) == DispatchTimeInterval.seconds(10));
}
#endif
9 changes: 3 additions & 6 deletions test/stdlib/Inputs/DictionaryKeyValueTypesObjC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,7 @@ func getBridgedNSDictionaryOfRefTypesBridgedVerbatim() -> NSDictionary {
d[TestObjCKeyTy(20)] = TestObjCValueTy(1020)
d[TestObjCKeyTy(30)] = TestObjCValueTy(1030)

let bridged =
unsafeBitCast(convertDictionaryToNSDictionary(d), to: NSDictionary.self)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lorentey just to check, can you spot any higher purpose to this bit cast that I'm missing? The function already returns an NSDictionary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is none as far as I can tell!

let bridged = convertDictionaryToNSDictionary(d)

assert(isNativeNSDictionary(bridged))

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

let bridged =
unsafeBitCast(convertDictionaryToNSDictionary(d), to: NSDictionary.self)
let bridged = convertDictionaryToNSDictionary(d)
assert(isNativeNSDictionary(bridged))

return bridged
Expand Down Expand Up @@ -874,8 +872,7 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
for i in 0..<3 {
var actualContents = [ExpectedDictionaryElement]()
let sink: (AnyObjectTuple2) -> Void = {
pair in
let (key, value) = pair
let (key, value) = $0
actualContents.append(ExpectedDictionaryElement(
key: convertKey(key),
value: convertValue(value),
Expand Down
32 changes: 0 additions & 32 deletions test/stdlib/IntegerCompatibility.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// RUN: %target-build-swift %s -swift-version 3 -typecheck
// RUN: %target-build-swift %s -swift-version 4 -typecheck


func byteswap_n(_ a: UInt64) -> UInt64 {
#if swift(>=4)
return ((a & 0x00000000000000FF) &<< 56) |
((a & 0x000000000000FF00) &<< 40) |
((a & 0x0000000000FF0000) &<< 24) |
Expand All @@ -12,22 +10,11 @@ func byteswap_n(_ a: UInt64) -> UInt64 {
((a & 0x0000FF0000000000) &>> 24) |
((a & 0x00FF000000000000) &>> 40) |
((a & 0xFF00000000000000) &>> 56)
#else
return ((a & 0x00000000000000FF) << 56) |
((a & 0x000000000000FF00) << 40) |
((a & 0x0000000000FF0000) << 24) |
((a & 0x00000000FF000000) << 8) |
((a & 0x000000FF00000000) >> 8) |
((a & 0x0000FF0000000000) >> 24) |
((a & 0x00FF000000000000) >> 40) |
((a & 0xFF00000000000000) >> 56)
#endif
}


// expression should not be too complex
func radar31845712(_ i: Int, _ buffer: [UInt8]) {
#if swift(>=4)
_ = UInt64(buffer[i])
| (UInt64(buffer[i + 1]) &<< 8)
| (UInt64(buffer[i + 2]) &<< 16)
Expand All @@ -36,16 +23,6 @@ func radar31845712(_ i: Int, _ buffer: [UInt8]) {
| (UInt64(buffer[i + 5]) &<< 40)
| (UInt64(buffer[i + 6]) &<< 48)
| (UInt64(buffer[i + 7]) &<< 56)
#else
_ = UInt64(buffer[i])
| (UInt64(buffer[i + 1]) << 8)
| (UInt64(buffer[i + 2]) << 16)
| (UInt64(buffer[i + 3]) << 24)
| (UInt64(buffer[i + 4]) << 32)
| (UInt64(buffer[i + 5]) << 40)
| (UInt64(buffer[i + 6]) << 48)
| (UInt64(buffer[i + 7]) << 56)
#endif
}

// expression should not be too complex
Expand All @@ -54,17 +31,10 @@ func radar32149641() {
var val: UInt32 = input
return withUnsafePointer(to: &val) { (ptr: UnsafePointer<UInt32>) -> UInt32 in
return ptr.withMemoryRebound(to: UInt8.self, capacity: 4) { data in
#if swift(>=4)
return (UInt32(data[3]) &<< 0) |
(UInt32(data[2]) &<< 8) |
(UInt32(data[1]) &<< 16) |
(UInt32(data[0]) &<< 24)
#else
return (UInt32(data[3]) << 0) |
(UInt32(data[2]) << 8) |
(UInt32(data[1]) << 16) |
(UInt32(data[0]) << 24)
#endif
}
}
}
Expand All @@ -74,11 +44,9 @@ func homogeneousLookingShiftAndAMask(_ i64: Int64) {
_ = (i64 >> 8) & 0xFF
}

#if swift(>=4)
func negativeShift(_ u8: UInt8) {
_ = (u8 << -1)
}
#endif

func sr5176(description: String = "unambiguous Int32.init(bitPattern:)") {
_ = Int32(bitPattern: 0) // should compile without ambiguity
Expand Down
1 change: 0 additions & 1 deletion test/stdlib/IntegerDiagnostics.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// RUN: %target-typecheck-verify-swift -swift-version 3
// RUN: %target-typecheck-verify-swift -swift-version 4

func signedBitPattern() {
Expand Down
17 changes: 0 additions & 17 deletions test/stdlib/LazyCollectionPlus.swift

This file was deleted.

7 changes: 3 additions & 4 deletions test/stdlib/LazySlice.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
// REQUIRES: executable_test

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

expectType(LazyFilterCollection<Slice<LazyCollection<[Int]>>>.self, &c)
}

runAllTests()
1 change: 0 additions & 1 deletion test/stdlib/MapFilterLayerFoldingCompatibilty.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
// RUN: %target-build-swift %s -o %t/a.out5 -swift-version 5 && %target-run %t/a.out5
// REQUIRES: executable_test
Expand Down
41 changes: 0 additions & 41 deletions test/stdlib/MixedTypeArithmeticsDiagnostics4.swift

This file was deleted.

5 changes: 0 additions & 5 deletions test/stdlib/RangeReplaceableFilterCompatibility.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4

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

tests.test("String.filter return type") {
var filtered = "Hello, World".filter { $0 < "A" }
#if swift(>=4)
expectType(String.self, &filtered)
#else
expectType([Character].self, &filtered)
#endif
}

tests.test("Array.filter return type") {
Expand Down
1 change: 0 additions & 1 deletion test/stdlib/ReverseCompatibility.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-run %t/a.out3
// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-run %t/a.out4
// RUN: %target-build-swift %s -o %t/a.out5 -swift-version 5 && %target-run %t/a.out5
// REQUIRES: executable_test
Expand Down
Loading