Skip to content

Commit

Permalink
[test] Update stdlib tests to support compiling in Swift 5 mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lorentey committed Oct 16, 2020
1 parent 92c3c5f commit d7f5136
Show file tree
Hide file tree
Showing 26 changed files with 371 additions and 265 deletions.
7 changes: 5 additions & 2 deletions test/Constraints/existential_metatypes.swift
Expand Up @@ -86,6 +86,9 @@ func testP3(_ p: P3, something: Something) {
p.withP3(Something.takeP3(something))
}

func testIUOToAny(_ t: AnyObject.Type!) {
let _: Any = t
func testIUOToAny(_ t: AnyObject.Type!) { // expected-note {{implicitly unwrapped parameter 't' declared here}}
let _: Any = t // expected-warning {{coercion of implicitly unwrappable value of type 'AnyObject.Type?' to 'Any' does not unwrap optional}}
// expected-note@-1 {{force-unwrap the value to avoid this warning}}
// expected-note@-2 {{provide a default value to avoid this warning}}
// expected-note@-3 {{explicitly cast to 'Any' with 'as Any' to silence this warning}}
}
5 changes: 5 additions & 0 deletions test/Constraints/existential_metatypes4.swift
@@ -0,0 +1,5 @@
// RUN: %target-typecheck-verify-swift -swift-version 4

func testIUOToAny(_ t: AnyObject.Type!) {
let _: Any = t
}
4 changes: 2 additions & 2 deletions test/Migrator/stdlib_rename.swift
@@ -1,5 +1,5 @@
// REQUIRES: objc_interop
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/stdlib_rename.swift.result -emit-remap-file-path %t/stdlib_rename.swift.remap -o /dev/null
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/stdlib_rename.swift.result -emit-remap-file-path %t/stdlib_rename.swift.remap -swift-version 4 -o /dev/null
// RUN: diff -u %S/stdlib_rename.swift.expected %t/stdlib_rename.swift.result
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/stdlib_rename.swift.result -emit-remap-file-path %t/stdlib_rename.swift.remap -o /dev/null -swift-version 4.2
// RUN: diff -u %S/stdlib_rename.swift.expected %t/stdlib_rename.swift.result
Expand All @@ -10,4 +10,4 @@ func test1(_ a: [String], s: String) {
}
func test2(_ s: String, c: Character) {
_ = s.index(of: c)
}
}
4 changes: 2 additions & 2 deletions test/Migrator/stdlib_rename.swift.expected
@@ -1,5 +1,5 @@
// REQUIRES: objc_interop
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/stdlib_rename.swift.result -emit-remap-file-path %t/stdlib_rename.swift.remap -o /dev/null
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/stdlib_rename.swift.result -emit-remap-file-path %t/stdlib_rename.swift.remap -swift-version 4 -o /dev/null
// RUN: diff -u %S/stdlib_rename.swift.expected %t/stdlib_rename.swift.result
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -emit-migrated-file-path %t/stdlib_rename.swift.result -emit-remap-file-path %t/stdlib_rename.swift.remap -o /dev/null -swift-version 4.2
// RUN: diff -u %S/stdlib_rename.swift.expected %t/stdlib_rename.swift.result
Expand All @@ -10,4 +10,4 @@ func test1(_ a: [String], s: String) {
}
func test2(_ s: String, c: Character) {
_ = s.firstIndex(of: c)
}
}
4 changes: 2 additions & 2 deletions test/stdlib/Filter.swift
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
Expand All @@ -20,7 +20,7 @@ let FilterTests = TestSuite("Filter")
// Check that the generic parameter is called 'Base'.
protocol TestProtocol1 {}

extension LazyFilterIterator where Base : TestProtocol1 {
extension LazyFilterSequence.Iterator where Base : TestProtocol1 {
var _baseIsTestProtocol1: Bool {
fatalError("not implemented")
}
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib/Map.swift
Expand Up @@ -15,7 +15,7 @@
// Check that the generic parameters are called 'Base' and 'Element'.
protocol TestProtocol1 {}

extension LazyMapIterator where Base : TestProtocol1, Element : TestProtocol1 {
extension LazyMapSequence.Iterator where Base : TestProtocol1, Element : TestProtocol1 {
var _baseIsTestProtocol1: Bool {
fatalError("not implemented")
}
Expand Down
2 changes: 2 additions & 0 deletions test/stdlib/Mirror.swift
Expand Up @@ -969,6 +969,7 @@ mirrors.test("Invalid Path Type")
_ = m.descendant(X())
}

#if swift(<5) // CustomPlaygroundQuickLookable was obsoleted in Swift 5
mirrors.test("PlaygroundQuickLook") {
// Customization works.
struct CustomQuickie : CustomPlaygroundQuickLookable {
Expand Down Expand Up @@ -1036,6 +1037,7 @@ mirrors.test("_DefaultCustomPlaygroundQuickLookable") {
default: expectUnreachable("FancyChild custom quicklookable was expected")
}
}
#endif

mirrors.test("String.init") {
expectEqual("42", String(42))
Expand Down
48 changes: 48 additions & 0 deletions test/stdlib/ObsoleteTypenames.swift
@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -swift-version 4 %s -o %t/Filter4
// RUN: %target-codesign %t/Filter4
// RUN: %target-run %t/Filter4
// REQUIRES: executable_test

// Tests for typealiases obsoleted in Swift 5

import StdlibUnittest

let suite = TestSuite("Filter4")
defer { runAllTests() }

suite.test("obsolete names") {
expectEqualType(
LazyFilterIterator<[Int]>.self,
LazyFilterSequence<[Int]>.Iterator.self)
expectEqualType(
LazyMapBidirectionalCollection<[Int], Int>.self,
LazyMapCollection<[Int], Int>.self)
expectEqualType(
LazyMapRandomAccessCollection<[Int], Int>.self,
LazyMapCollection<[Int], Int>.self)
expectEqualType(
LazyMapIterator<[Int], Int>.self,
LazyMapSequence<[Int], Int>.Iterator.self)
expectEqualType(
UnsafeBufferPointerIterator<Int>.self,
UnsafeBufferPointer<Int>.Iterator.self)
expectEqualType(
IteratorOverOne<Int>.self,
CollectionOfOne<Int>.Iterator.self)
expectEqualType(
EmptyIterator<Int>.self,
EmptyCollection<Int>.Iterator.self)
}

164 changes: 0 additions & 164 deletions test/stdlib/Reflection_objc.swift
Expand Up @@ -77,94 +77,6 @@ print("We cannot reflect \(ComparisonResult.orderedAscending) yet")
print("NSURL:")
dump(NSURL(fileURLWithPath: "/Volumes", isDirectory: true))

// -- Check that quick look Cocoa objects get binned correctly to their
// associated enum tag.

// CHECK-NEXT: got the expected quick look text
switch PlaygroundQuickLook(reflecting: "woozle wuzzle" as NSString) {
case .text("woozle wuzzle"):
print("got the expected quick look text")
case let x:
print("NSString: got something else: \(x)")
}

// CHECK-NEXT: foobar
let somesubclassofnsstring = ("foo" + "bar") as NSString
switch PlaygroundQuickLook(reflecting: somesubclassofnsstring) {
case .text(let text): print(text)
case let x: print("not the expected quicklook: \(x)")
}

// CHECK-NEXT: got the expected quick look attributed string
let astr = NSAttributedString(string: "yizzle pizzle")
switch PlaygroundQuickLook(reflecting: astr) {
case .attributedString(let astr2 as NSAttributedString)
where astr == astr2:
print("got the expected quick look attributed string")
case let x:
print("NSAttributedString: got something else: \(x)")
}

// CHECK-NEXT: got the expected quick look int
switch PlaygroundQuickLook(reflecting: Int.max as NSNumber) {
case .int(+Int64(Int.max)):
print("got the expected quick look int")
case let x:
print("NSNumber(Int.max): got something else: \(x)")
}

// CHECK-NEXT: got the expected quick look uint
switch PlaygroundQuickLook(reflecting: NSNumber(value: UInt64.max)) {
case .uInt(UInt64.max):
print("got the expected quick look uint")
case let x:
print("NSNumber(Int64.max): got something else: \(x)")
}

// CHECK-NEXT: got the expected quick look double
switch PlaygroundQuickLook(reflecting: 22.5 as NSNumber) {
case .double(22.5):
print("got the expected quick look double")
case let x:
print("NSNumber(22.5): got something else: \(x)")
}

// CHECK-NEXT: got the expected quick look float
switch PlaygroundQuickLook(reflecting: Float32(1.25)) {
case .float(1.25):
print("got the expected quick look float")
case let x:
print("NSNumber(Float32(1.25)): got something else: \(x)")
}

// CHECK-NEXT: got the expected quick look image
// CHECK-NEXT: got the expected quick look color
// CHECK-NEXT: got the expected quick look bezier path

let image = OSImage(contentsOfFile:CommandLine.arguments[1])!
switch PlaygroundQuickLook(reflecting: image) {
case .image(let image2 as OSImage) where image === image2:
print("got the expected quick look image")
case let x:
print("OSImage: got something else: \(x)")
}

let color = OSColor.black
switch PlaygroundQuickLook(reflecting: color) {
case .color(let color2 as OSColor) where color === color2:
print("got the expected quick look color")
case let x:
print("OSColor: got something else: \(x)")
}

let path = OSBezierPath()
switch PlaygroundQuickLook(reflecting: path) {
case .bezierPath(let path2 as OSBezierPath) where path === path2:
print("got the expected quick look bezier path")
case let x:
print("OSBezierPath: got something else: \(x)")
}

// CHECK-LABEL: Reflecting NSArray:
// CHECK-NEXT: [ 1 2 3 4 5 ]
print("Reflecting NSArray:")
Expand Down Expand Up @@ -211,82 +123,6 @@ dump(CGSize(width: 30, height: 60))
// CHECK-NEXT: height: 150.0
dump(CGRect(x: 50, y: 60, width: 100, height: 150))

// rdar://problem/18513769 -- Make sure that QuickLookObject lookup correctly
// manages memory.

@objc class CanaryBase {
deinit {
print("\(type(of: self)) overboard")
}

required init() { }
}

var CanaryHandle = false

class IsDebugQLO : CanaryBase, CustomStringConvertible {
@objc var description: String {
return "I'm a QLO"
}
}

class HasDebugQLO : CanaryBase {
@objc var debugQuickLookObject: AnyObject {
return IsDebugQLO()
}
}

class HasNumberQLO : CanaryBase {
@objc var debugQuickLookObject: AnyObject {
let number = NSNumber(value: 97210)
return number
}
}

class HasAttributedQLO : CanaryBase {
@objc var debugQuickLookObject: AnyObject {
let str = NSAttributedString(string: "attributed string")
objc_setAssociatedObject(str, &CanaryHandle, CanaryBase(),
.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
return str
}
}

class HasStringQLO : CanaryBase {
@objc var debugQuickLookObject: AnyObject {
let str = NSString(string: "plain string")
objc_setAssociatedObject(str, &CanaryHandle, CanaryBase(),
.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
return str
}
}

func testQLO<T : CanaryBase>(_ type: T.Type) {
autoreleasepool {
_ = PlaygroundQuickLook(reflecting: type.init())
}
}

testQLO(IsDebugQLO.self)
// CHECK-NEXT: IsDebugQLO overboard

testQLO(HasDebugQLO.self)
// CHECK-NEXT: HasDebugQLO overboard
// CHECK-NEXT: IsDebugQLO overboard

testQLO(HasNumberQLO.self)
// CHECK-NEXT: HasNumberQLO overboard
// TODO: tagged numbers are immortal, so we can't reliably check for
// cleanup here

testQLO(HasAttributedQLO.self)
// CHECK-NEXT: HasAttributedQLO overboard
// CHECK-NEXT: CanaryBase overboard

testQLO(HasStringQLO.self)
// CHECK-NEXT: HasStringQLO overboard
// CHECK-NEXT: CanaryBase overboard

let x = float4(0)
print("float4 has \(Mirror(reflecting: x).children.count) children")
// CHECK-NEXT: float4 has 1 children
Expand Down

0 comments on commit d7f5136

Please sign in to comment.