Skip to content

[stdlib] Migrate remaining stdlib tests from Swift 3 #18740

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 3 commits into from
Aug 16, 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
8 changes: 4 additions & 4 deletions test/stdlib/ArrayBridge.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// RUN: %gyb %s -o %t/ArrayBridge.swift
// RUN: %target-clang %S/Inputs/ArrayBridge/ArrayBridge.m -c -o %t/ArrayBridgeObjC.o -g
// RUN: %line-directive %t/ArrayBridge.swift -- %target-build-swift %t/ArrayBridge.swift -I %S/Inputs/ArrayBridge/ -Xlinker %t/ArrayBridgeObjC.o -o %t/ArrayBridge -swift-version 3 --
// RUN: %line-directive %t/ArrayBridge.swift -- %target-build-swift %t/ArrayBridge.swift -I %S/Inputs/ArrayBridge/ -Xlinker %t/ArrayBridgeObjC.o -o %t/ArrayBridge -swift-version 4.2 --

// RUN: %target-codesign %t/ArrayBridge
// RUN: %target-run %t/ArrayBridge
Expand Down Expand Up @@ -127,7 +127,7 @@ func == (lhs: BridgeableValue, rhs: BridgeableValue) -> Bool {

// A class used to test various Objective-C thunks.
class Thunks : NSObject {
func createSubclass(_ value: Int) -> AnyObject {
@objc func createSubclass(_ value: Int) -> AnyObject {
return Subclass(value)
}

Expand Down Expand Up @@ -296,8 +296,8 @@ tests.test("testExplicitlyBridged/${Any}") {

let bridgeableValuesAsNSArray = bridgeableValues as NSArray
expectEqual(2, bridgeableValuesAsNSArray.count)
expectEqual(42, (bridgeableValuesAsNSArray[0] as AnyObject).value)
expectEqual(17, (bridgeableValuesAsNSArray[1] as AnyObject).value)
expectEqual(42, (bridgeableValuesAsNSArray[0] as! Subclass).value)
expectEqual(17, (bridgeableValuesAsNSArray[1] as! Subclass).value)

// Make sure we can bridge back.
let roundTrippedValues = Swift._forceBridgeFromObjectiveC(
Expand Down
10 changes: 1 addition & 9 deletions test/stdlib/Intents.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-codesign %t/a.out3 && %target-run %t/a.out3
// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-codesign %t/a.out4 && %target-run %t/a.out4
// RUN: %target-build-swift %s -o %t/a.out42 -swift-version 4.2 && %target-codesign %t/a.out42 && %target-run %t/a.out42
// REQUIRES: executable_test
// REQUIRES: objc_interop

Expand All @@ -11,11 +11,7 @@ import StdlibUnittest

let IntentsTestSuite = TestSuite("Intents")

#if swift(>=4)
let swiftVersion = "4"
#else
let swiftVersion = "3"
#endif

if #available(OSX 10.12, iOS 10.0, watchOS 3.2, *) {

Expand Down Expand Up @@ -46,10 +42,6 @@ if #available(iOS 11.0, *) {
func f(profile: INSetProfileInCarIntent) {
var isDefaultProfile = profile.isDefaultProfile
expectType(Bool?.self, &isDefaultProfile)
#if !swift(>=4)
var defaultProfile = profile.defaultProfile
expectType(Int?.self, &defaultProfile)
#endif
}
}
}
Expand Down
50 changes: 16 additions & 34 deletions test/stdlib/UIKit.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -swift-version 3 %s -o %t/a.out3 && %target-codesign %t/a.out3 && %target-run %t/a.out3
// RUN: %target-build-swift -swift-version 4 %s -o %t/a.out4 && %target-codesign %t/a.out4 && %target-run %t/a.out4
// RUN: %target-build-swift -swift-version 4.2 %s -o %t/a.out4_2 && %target-codesign %t/a.out4_2 && %target-run %t/a.out4_2
// REQUIRES: executable_test
Expand All @@ -12,10 +11,8 @@ import StdlibUnittestFoundationExtras

#if swift(>=4.2)
let UIKitTests = TestSuite("UIKit_Swift4_2")
#elseif swift(>=4)
let UIKitTests = TestSuite("UIKit_Swift4")
#else
let UIKitTests = TestSuite("UIKit_Swift3")
let UIKitTests = TestSuite("UIKit_Swift4")
#endif

#if !os(watchOS) && !os(tvOS)
Expand Down Expand Up @@ -144,41 +141,26 @@ UIKitTests.test("UIFont.Weight") {

#if !os(watchOS)
UIKitTests.test("UILayoutPriority") {
#if swift(>=4) // Swift 4
let lowLayoutPriority: UILayoutPriority = .defaultLow
let highLayoutPriority: UILayoutPriority = .defaultHigh

expectTrue(lowLayoutPriority < highLayoutPriority)
let lowLayoutPriority: UILayoutPriority = .defaultLow
let highLayoutPriority: UILayoutPriority = .defaultHigh

expectTrue(lowLayoutPriority + 2.0 == UILayoutPriority(lowLayoutPriority.rawValue + 2.0))
expectTrue(2.0 + lowLayoutPriority == UILayoutPriority(lowLayoutPriority.rawValue + 2.0))
expectTrue(lowLayoutPriority - 2.0 == UILayoutPriority(lowLayoutPriority.rawValue - 2.0))
expectTrue(highLayoutPriority - lowLayoutPriority == highLayoutPriority.rawValue - lowLayoutPriority.rawValue)
expectTrue(lowLayoutPriority < highLayoutPriority)

expectTrue(lowLayoutPriority + (highLayoutPriority - lowLayoutPriority) == highLayoutPriority)
expectTrue(lowLayoutPriority + 2.0 == UILayoutPriority(lowLayoutPriority.rawValue + 2.0))
expectTrue(2.0 + lowLayoutPriority == UILayoutPriority(lowLayoutPriority.rawValue + 2.0))
expectTrue(lowLayoutPriority - 2.0 == UILayoutPriority(lowLayoutPriority.rawValue - 2.0))
expectTrue(highLayoutPriority - lowLayoutPriority == highLayoutPriority.rawValue - lowLayoutPriority.rawValue)

var mutablePriority = lowLayoutPriority
mutablePriority -= 1.0
mutablePriority += 2.0
expectTrue(mutablePriority == lowLayoutPriority + 1.0)
expectTrue(lowLayoutPriority + (highLayoutPriority - lowLayoutPriority) == highLayoutPriority)

let priorotyRange = lowLayoutPriority...highLayoutPriority
expectTrue(priorotyRange.contains(.defaultLow))
expectFalse(priorotyRange.contains(.required))
#else // Swift 3
let lowLayoutPriority: UILayoutPriority = UILayoutPriorityDefaultLow
let highLayoutPriority: UILayoutPriority = UILayoutPriorityDefaultHigh

expectTrue(lowLayoutPriority < highLayoutPriority)
var mutablePriority = lowLayoutPriority
mutablePriority -= 1.0
mutablePriority += 2.0
expectTrue(mutablePriority == lowLayoutPriority + 1.0)

expectTrue(2.0 + lowLayoutPriority == lowLayoutPriority + 2.0)
expectTrue(lowLayoutPriority + (highLayoutPriority - lowLayoutPriority) == highLayoutPriority)

var mutablePriority = lowLayoutPriority
mutablePriority -= 1.0
mutablePriority += 2.0
expectTrue(mutablePriority == lowLayoutPriority + 1.0)
#endif
let priorotyRange = lowLayoutPriority...highLayoutPriority
expectTrue(priorotyRange.contains(.defaultLow))
expectFalse(priorotyRange.contains(.required))
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion validation-test/stdlib/ArrayBridging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// RUN: %target-clang -fobjc-arc %S/Inputs/SlurpFastEnumeration/SlurpFastEnumeration.m -c -o %t/SlurpFastEnumeration.o
// RUN: echo '#sourceLocation(file: "%s", line: 1)' > "%t/main.swift" && cat "%s" >> "%t/main.swift" && chmod -w "%t/main.swift"
// RUN: %target-build-swift -Xfrontend -disable-access-control -I %S/Inputs/SlurpFastEnumeration/ %t/main.swift %S/Inputs/DictionaryKeyValueTypes.swift %S/Inputs/DictionaryKeyValueTypesObjC.swift -Xlinker %t/SlurpFastEnumeration.o -o %t.out -O -swift-version 3
// RUN: %target-build-swift -Xfrontend -disable-access-control -I %S/Inputs/SlurpFastEnumeration/ %t/main.swift %S/Inputs/DictionaryKeyValueTypes.swift %S/Inputs/DictionaryKeyValueTypesObjC.swift -Xlinker %t/SlurpFastEnumeration.o -o %t.out -O -swift-version 4
// RUN: %target-run %t.out
// REQUIRES: executable_test

Expand Down
50 changes: 21 additions & 29 deletions validation-test/stdlib/ArrayNew.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// RUN: %gyb %s -o %t/main.swift
// RUN: if [ %target-runtime == "objc" ]; then \
// RUN: %target-clang -fobjc-arc %S/Inputs/SlurpFastEnumeration/SlurpFastEnumeration.m -c -o %t/SlurpFastEnumeration.o; \
// RUN: %line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %S/Inputs/DictionaryKeyValueTypesObjC.swift %t/main.swift -I %S/Inputs/SlurpFastEnumeration/ -Xlinker %t/SlurpFastEnumeration.o -o %t/Array -Xfrontend -disable-access-control -swift-version 3; \
// RUN: %line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %S/Inputs/DictionaryKeyValueTypesObjC.swift %t/main.swift -I %S/Inputs/SlurpFastEnumeration/ -Xlinker %t/SlurpFastEnumeration.o -o %t/Array -Xfrontend -disable-access-control -swift-version 4.2; \
// RUN: else \
// RUN: %line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %t/main.swift -o %t/Array -Xfrontend -disable-access-control -swift-version 3; \
// RUN: %line-directive %t/main.swift -- %target-build-swift %S/Inputs/DictionaryKeyValueTypes.swift %t/main.swift -o %t/Array -Xfrontend -disable-access-control -swift-version 4.2; \
// RUN: fi
// RUN: %target-codesign %t/Array && %line-directive %t/main.swift -- %target-run %t/Array
// REQUIRES: executable_test
Expand Down Expand Up @@ -372,7 +372,7 @@ ArrayTestSuite.test("BridgedFromObjC.Verbatim.ArrayIsCopied") {
expectEqual(30, (nsa[1] as! TestObjCValueTy).value)

// Check that the Array is not affected.
expectEqual(20, result[1].value)
expectEqual(20, (result[1] as! TestObjCValueTy).value)
}

ArrayTestSuite.test("BridgedFromObjC.Nonverbatim.ArrayIsCopied") {
Expand All @@ -393,8 +393,8 @@ ArrayTestSuite.test("BridgedFromObjC.Nonverbatim.ArrayIsCopied") {

ArrayTestSuite.test("BridgedFromObjC.Verbatim.NSArrayIsRetained") {
let nsa = NSArray(array: getAsNSArray([ 10, 20, 30 ]))
var a: Array<AnyObject> = convertNSArrayToArray(nsa)
var bridgedBack: NSArray = convertArrayToNSArray(a)
let a: Array<AnyObject> = convertNSArrayToArray(nsa)
let bridgedBack: NSArray = convertArrayToNSArray(a)

expectEqual(
unsafeBitCast(nsa, to: Int.self),
Expand All @@ -407,8 +407,8 @@ ArrayTestSuite.test("BridgedFromObjC.Verbatim.NSArrayIsRetained") {

ArrayTestSuite.test("BridgedFromObjC.Nonverbatim.NSArrayIsCopied") {
let nsa = NSArray(array: getAsNSArray([ 10, 20, 30 ]))
var a: Array<TestBridgedValueTy> = convertNSArrayToArray(nsa)
var bridgedBack: NSArray = convertArrayToNSArray(a)
let a: Array<TestBridgedValueTy> = convertNSArrayToArray(nsa)
let bridgedBack: NSArray = convertArrayToNSArray(a)

expectNotEqual(
unsafeBitCast(nsa, to: Int.self),
Expand Down Expand Up @@ -542,11 +542,9 @@ ArrayTestSuite.test("BridgedToObjC/Verbatim/objectAtIndex") {
expectEqual(30, (v as! TestObjCValueTy).value)
let idValue2 = unsafeBitCast(v, to: UInt.self)

for i in 0..<3 {
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))
}
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))

expectAutoreleasedKeysAndValues(unopt: (0, 3))
}
Expand Down Expand Up @@ -602,11 +600,9 @@ ArrayTestSuite.test("BridgedToObjC/Verbatim/getObjects") {
expectEqual(30, (v as! TestObjCValueTy).value)
let idValue2 = unsafeBitCast(v, to: UInt.self)

for i in 0..<3 {
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))
}
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))

buffer.deallocate()
_fixLifetime(a)
Expand Down Expand Up @@ -815,11 +811,9 @@ ArrayTestSuite.test("BridgedToObjC/Custom/objectAtIndex") {
expectEqual(30, (v as! TestObjCValueTy).value)
let idValue2 = unsafeBitCast(v, to: UInt.self)

for i in 0..<3 {
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))
}
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))

expectEqual(3, TestBridgedValueTy.bridgeOperations)
expectAutoreleasedKeysAndValues(unopt: (0, 3))
Expand Down Expand Up @@ -876,11 +870,9 @@ ArrayTestSuite.test("BridgedToObjC/Custom/getObjects") {
expectEqual(30, (v as! TestObjCValueTy).value)
let idValue2 = unsafeBitCast(v, to: UInt.self)

for i in 0..<3 {
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))
}
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))

buffer.deallocate()
_fixLifetime(a)
Expand Down Expand Up @@ -1119,14 +1111,14 @@ ArrayTestSuite.test("BridgedToObjC.Nonverbatim.RoundtripThroughSwiftArray") {
TestBridgedValueTy.bridgeOperations = 0
let nsa: NSArray = getAsImmutableNSArray([ 10, 20, 30 ])
let a: Array<TestBridgedValueTy> = convertNSArrayToArray(nsa)
let bridgedBack = convertArrayToNSArray(a)
let _ = convertArrayToNSArray(a)
expectEqual(3, TestBridgedValueTy.bridgeOperations)
}
do {
TestBridgedValueTy.bridgeOperations = 0
let nsa: NSArray = getAsImmutableNSArray([ 10, 20, 30 ])
let a = nsa as! Array<TestBridgedValueTy>
let bridgedBack: NSArray = a as NSArray
let _: NSArray = a as NSArray
expectEqual(3, TestBridgedValueTy.bridgeOperations)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: %gyb %s -o %t/ArrayTraps.swift
// RUN: %line-directive %t/ArrayTraps.swift -- %target-build-swift %t/ArrayTraps.swift -o %t/a.out_Debug -Onone -swift-version 3
// RUN: %line-directive %t/ArrayTraps.swift -- %target-build-swift %t/ArrayTraps.swift -o %t/a.out_Release -O -swift-version 3
//
// RUN: %target-codesign %t/a.out_Debug
// RUN: %target-codesign %t/a.out_Release
// RUN: %line-directive %t/ArrayTraps.swift -- %target-run %t/a.out_Debug
// RUN: %line-directive %t/ArrayTraps.swift -- %target-run %t/a.out_Release
// RUN: %target-build-swift %s -o %t/a.out_Debug -Onone -swift-version 4.2 && %target-codesign %t/a.out_Debug && %target-run %t/a.out_Debug
// RUN: %target-build-swift %s -o %t/a.out_Release -O -swift-version 4.2 && %target-codesign %t/a.out_Release && %target-run %t/a.out_Release
// REQUIRES: executable_test
// REQUIRES: objc_interop

Expand All @@ -28,7 +22,7 @@ ArrayTraps.test("downcast1")
.code {
let ba: [Base] = [ Derived(), Base() ]
let da = ba as! [Derived]
let d0 = da[0]
_ = da[0]
expectCrashLater()
_ = da[1]
}
Expand All @@ -40,7 +34,7 @@ ArrayTraps.test("downcast2")
.code {
let a: [AnyObject] = ["String" as NSString, 1 as NSNumber]
let sa = a as! [NSString]
let s0 = sa[0]
_ = sa[0]
expectCrashLater()
_ = sa[1]
}
Expand All @@ -52,10 +46,10 @@ ArrayTraps.test("downcast3")
.code {
let ba: [Base] = [ Derived2(), Derived(), Base() ]
let d2a = ba as! [Derived2]
let d2a0 = d2a[0]
_ = d2a[0]
let d1a = d2a as [Derived]
let d1a0 = d1a[0]
let d1a1 = d1a[1]
_ = d1a[0]
_ = d1a[1]
expectCrashLater()
_ = d1a[2]
}
Expand All @@ -71,7 +65,7 @@ ArrayTraps.test("downcast4")
.code {
let ba: [ObjCProto] = [ ObjCDerived(), ObjCBase() ]
let da = ba as! [ObjCDerived]
let d0 = da[0]
_ = da[0]
expectCrashLater()
_ = da[1]
}
Expand All @@ -86,7 +80,7 @@ ArrayTraps.test("bounds_with_downcast")
let ba: [Base] = [ Derived(), Base() ]
let da = ba as! [Derived]
expectCrashLater()
let x = da[2]
_ = da[2]
}

var ArraySemanticOptzns = TestSuite("ArraySemanticOptzns" + testSuiteSuffix)
Expand Down Expand Up @@ -138,7 +132,7 @@ ArraySemanticOptzns.test("inout_rule_violated_isNativeBuffer")
{ _isFastAssertConfiguration() },
reason: "this trap is not guaranteed to happen in -Ounchecked"))
.crashOutputMatches(_isDebugAssertConfiguration() ?
"Fatal error: inout rules were violated: the array was overwritten" : "")
"Fatal access conflict detected." : "")
.code {
let v = ViolateInoutSafetySwitchToObjcBuffer()
expectCrashLater()
Expand Down Expand Up @@ -181,7 +175,7 @@ ArraySemanticOptzns.test("inout_rule_violated_needsElementTypeCheck")
{ _isFastAssertConfiguration() },
reason: "this trap is not guaranteed to happen in -Ounchecked"))
.crashOutputMatches(_isDebugAssertConfiguration() ?
"Fatal error: inout rules were violated: the array was overwritten" : "")
"Fatal access conflict detected." : "")
.code {
let v = ViolateInoutSafetyNeedElementTypeCheck()
expectCrashLater()
Expand Down
2 changes: 1 addition & 1 deletion validation-test/stdlib/CollectionCompatibility.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: rm -rf %t ; mkdir -p %t
// RUN: %target-build-swift %s -o %t/a.out3 -swift-version 3 && %target-codesign %t/a.out3 && %target-run %t/a.out3
// RUN: %target-build-swift %s -o %t/a.out4 -swift-version 4 && %target-codesign %t/a.out4 && %target-run %t/a.out4
// RUN: %target-build-swift %s -o %t/a.out42 -swift-version 4.2 && %target-codesign %t/a.out42 && %target-run %t/a.out42

// REQUIRES: executable_test

Expand Down
2 changes: 1 addition & 1 deletion validation-test/stdlib/DictionaryBridging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// RUN: %target-clang -fobjc-arc %S/Inputs/SlurpFastEnumeration/SlurpFastEnumeration.m -c -o %t/SlurpFastEnumeration.o
// RUN: echo '#sourceLocation(file: "%s", line: 1)' > "%t/main.swift" && cat "%s" >> "%t/main.swift" && chmod -w "%t/main.swift"
// RUN: %target-build-swift -Xfrontend -disable-access-control -I %S/Inputs/SlurpFastEnumeration/ %t/main.swift %S/Inputs/DictionaryKeyValueTypes.swift %S/Inputs/DictionaryKeyValueTypesObjC.swift -Xlinker %t/SlurpFastEnumeration.o -o %t.out -O -swift-version 3
// RUN: %target-build-swift -Xfrontend -disable-access-control -I %S/Inputs/SlurpFastEnumeration/ %t/main.swift %S/Inputs/DictionaryKeyValueTypes.swift %S/Inputs/DictionaryKeyValueTypesObjC.swift -Xlinker %t/SlurpFastEnumeration.o -o %t.out -O -swift-version 4.2
// RUN: %target-run %t.out
// REQUIRES: executable_test
// REQUIRES: stress_test
Expand Down
Loading