Skip to content

Commit eb16025

Browse files
committed
Tests: Upstream some miscellaneous macCatalyst tests.
1 parent 54301e4 commit eb16025

File tree

4 files changed

+342
-0
lines changed

4 files changed

+342
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -target x86_64-apple-ios13.1-macabi -typecheck -verify -I %S/Inputs/custom-modules %s
2+
3+
// REQUIRES: maccatalyst_support
4+
5+
import Foundation
6+
import AvailabilityExtras
7+
8+
func test_unavailable_because_deprecated() {
9+
print(NSRealMemoryAvailable()) // expected-error {{APIs deprecated as of iOS 7 and earlier are unavailable in Swift}}
10+
}
11+
12+
func test_swift_unavailable_wins() {
13+
unavailableWithOS() // expected-error {{'unavailableWithOS()' is unavailable in Swift}}
14+
}
15+
16+
func test_maccatalyst_unavailable_wins() {
17+
availableOnIOSButUnavailableOnmacCatalyst() // expected-error {{'availableOnIOSButUnavailableOnmacCatalyst()' is unavailable}}
18+
}
19+
20+
func test_maccatalyst_deprecated_wins() {
21+
availableOnIOSButDeprecatedOnmacCatalyst() // expected-warning {{'availableOnIOSButDeprecatedOnmacCatalyst()' was deprecated in Mac Catalyst 9.0}}
22+
}
23+
24+
25+
func test_ios_unavailable_is_also_unavailable_on_maccatalyst() {
26+
unavailableOnIOS() // expected-error {{'unavailableOnIOS()' is unavailable}}
27+
}
28+
29+
func test_deprecation_on_ios_not_inherited_when_not_specified_on_maccatalyst() {
30+
deprecatedOniOSButNotOnmacCatalyst(); // no-warning
31+
}
32+
33+
func test_ios_app_extension() {
34+
availableOnIOSButUnavailableOniOSAppExtension() // no-error
35+
availableOnIOSAppExtensionButUnavailableOnmacCatalystAppExtension() // no-error
36+
37+
availableOnIOSButDeprecatedOniOSAppExtension() // no-warning
38+
availableOnIOSAppExtensionButDeprecatedOnmacCatalystAppExtension() // no-warning
39+
}
40+
41+
// Test platform inheritance for imported decls unavailable in iOS.
42+
// rdar://68597591
43+
44+
@available(iOS, unavailable)
45+
func unavailableFunctionUsingAnUnavailableType(_ p: UnavailableOniOS) { }
46+
47+
@available(iOS, unavailable)
48+
func unavailableOniOS(_ p: UnavailableOniOS) { } // ok
49+
50+
func functionUsingAnUnavailableType(_ p: UnavailableOniOS) { } // expected-error {{'UnavailableOniOS' is unavailable in Mac Catalyst}}
51+
52+
public extension UnavailableOniOS { // expected-error {{'UnavailableOniOS' is unavailable in Mac Catalyst}}
53+
func someMethod1(_ p: UnavailableOniOS) { } // expected-error {{'UnavailableOniOS' is unavailable in Mac Catalyst}}
54+
}
55+
56+
@available(iOS, unavailable)
57+
public extension UnavailableOniOS { // ok
58+
func someMethod2(_ p: UnavailableOniOS) { }
59+
}
60+
61+
public extension AvailableOnMacCatalystOnly { } // ok
62+
63+
public extension UnavailableOnMacCatalystOnly { } // expected-error {{UnavailableOnMacCatalystOnly' is unavailable in Mac Catalyst}}
64+
65+
@available(iOS, unavailable)
66+
@available(macCatalyst, introduced: 13.0)
67+
struct StructAvailableOnMacCatalystOnly {
68+
func nestedCheck(_ p: AvailableOnMacCatalystOnly) {}
69+
func invertedNestedCheck(_ p: UnavailableOnMacCatalystOnly) {} // expected-error {{UnavailableOnMacCatalystOnly' is unavailable in Mac Catalyst}}
70+
}
71+
72+
@available(iOS, introduced: 13.0)
73+
@available(macCatalyst, unavailable)
74+
struct StructUnavailableOnMacCatalystOnly {
75+
func nestedCheck(_ p: UnavailableOnMacCatalystOnly) {}
76+
func invertedNestedCheck(_ p: AvailableOnMacCatalystOnly) {} // Would error for an iOS target.
77+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -target x86_64-apple-ios13.1-macabi -application-extension -typecheck -verify -I %S/Inputs/custom-modules %s
2+
3+
// REQUIRES: maccatalyst_support
4+
5+
import Foundation
6+
import AvailabilityExtras
7+
8+
func test_unavailable_because_deprecated() {
9+
print(NSRealMemoryAvailable()) // expected-error {{APIs deprecated as of iOS 7 and earlier are unavailable in Swift}}
10+
}
11+
12+
func test_swift_unavailable_wins() {
13+
unavailableWithOS() // expected-error {{'unavailableWithOS()' is unavailable in Swift}}
14+
}
15+
16+
func test_maccatalyst_unavailable_wins() {
17+
availableOnIOSButUnavailableOnmacCatalyst() // expected-error {{'availableOnIOSButUnavailableOnmacCatalyst()' is unavailable in Mac Catalyst}}
18+
}
19+
20+
func test_maccatalyst_deprecated_wins() {
21+
availableOnIOSButDeprecatedOnmacCatalyst() // expected-warning {{'availableOnIOSButDeprecatedOnmacCatalyst()' was deprecated in Mac Catalyst 9.0}}
22+
}
23+
24+
func test_ios_unavailable_is_also_unavailable_on_maccatalyst() {
25+
unavailableOnIOS() // expected-error {{'unavailableOnIOS()' is unavailable in Mac Catalyst}}
26+
}
27+
28+
func test_deprecation_on_ios_not_inherited_when_not_specified_on_maccatalyst() {
29+
deprecatedOniOSButNotOnmacCatalyst(); // no-warning
30+
}
31+
32+
func test_ios_app_extension() {
33+
availableOnIOSButUnavailableOniOSAppExtension() // expected-error {{'availableOnIOSButUnavailableOniOSAppExtension()' is unavailable in application extensions for Mac Catalyst}}
34+
availableOnIOSAppExtensionButUnavailableOnmacCatalystAppExtension() // expected-error {{'availableOnIOSAppExtensionButUnavailableOnmacCatalystAppExtension()' is unavailable in application extensions for Mac Catalyst}}
35+
36+
availableOnIOSButDeprecatedOniOSAppExtension() // expected-warning {{'availableOnIOSButDeprecatedOniOSAppExtension()' was deprecated in application extensions for Mac Catalyst 13.1}}
37+
availableOnIOSAppExtensionButDeprecatedOnmacCatalystAppExtension() // expected-warning {{'availableOnIOSAppExtensionButDeprecatedOnmacCatalystAppExtension()' was deprecated in application extensions for Mac Catalyst 9.0}}
38+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// REQUIRES: OS=maccatalyst || OS=macosx
2+
// REQUIRES: maccatalyst_support
3+
4+
5+
// Zippered libraries
6+
7+
// RUN: %otool-classic -l %test-resource-dir/macosx/libswiftCore.dylib | %FileCheck %s --check-prefix=CHECK-ZIPPERED
8+
// RUN: %otool-classic -l %test-resource-dir/macosx/libswiftDarwin.dylib | %FileCheck %s --check-prefix=CHECK-ZIPPERED
9+
// RUN: %otool-classic -l %test-resource-dir/macosx/libswiftSwiftOnoneSupport.dylib | %FileCheck %s --check-prefix=CHECK-ZIPPERED
10+
// RUN: %otool-classic -l %test-resource-dir/macosx/libswiftCompatibility51.a | %FileCheck %s --check-prefix=CHECK-ZIPPERED
11+
12+
13+
// macCatalyst-only libraries
14+
// (None)
15+
16+
// Unzippered twins (separate iosMac-only and macOS-only libraries)
17+
// (None)
18+
19+
// For zippered dylibs we expect two load commands:
20+
// one for macos and one for maccatalyst.
21+
//
22+
// Note: For dylibs with deployment targets earlier than 10.14 we
23+
// should see an LC_VERSION_MIN_MACOSX load command followed by a
24+
// LC_BUILD_VERSION command. This enables the dylib to be back
25+
// deployed to versions of the OS don't support macCatalyst.
26+
//
27+
// For dylibs targetting 10.14 and later, we should see two
28+
// LC_BUILD_VERSION commands.
29+
//
30+
// CHECK-ZIPPERED: cmd {{LC_BUILD_VERSION|LC_VERSION_MIN_MACOSX}}
31+
// CHECK-ZIPPERED-NEXT: cmdsize
32+
// CHECK-ZIPPERED-NEXT: {{platform 1|version}}
33+
// CHECK-ZIPPERED-NEXT: {{minos|sdk}}
34+
35+
// CHECK-ZIPPERED: cmd LC_BUILD_VERSION
36+
// CHECK-ZIPPERED-NEXT: cmdsize
37+
// CHECK-ZIPPERED-NEXT: platform 6
38+
// CHECK-ZIPPERED-NEXT: minos
39+
40+
// For macCatalyst-only dylibs we expect a maccatalyst load command and no macos load command
41+
// CHECK-MACCATALYST-NOT: platform macos
42+
// CHECK-MACCATALYST: cmd LC_BUILD_VERSION
43+
// CHECK-MACCATALYST-NEXT: cmdsize
44+
// CHECK-MACCATALYST-NEXT: platform 6
45+
// CHECK-MACCATALYST-NEXT: minos
46+
// CHECK-MACCATALYST-NOT: platform macos
47+
48+
49+
// For Mac-only dylibs we expect a macos load command and no maccatalyst load command
50+
// Similar to the zippered case, when the deployment target is 10.14 and later
51+
// we should expect a *single* LC_BUILD_VERSION command and when it is earlier
52+
// we should expect only a LC_VERSION_MIN_MACOSX command.
53+
// CHECK-MAC-NOT: platform 6
54+
// CHECK-MAC: cmd LC_VERSION_MIN_MACOSX
55+
// CHECK-MAC-NEXT: cmdsize
56+
// CHECK-MAC-NEXT: version
57+
// CHECK-MAC-NOT: platform 6
58+
59+
// Check to make sure that when passing -target-variant the .o file is zippered.
60+
func foo() { }
61+
62+
// RUN: %swiftc_driver -target x86_64-apple-macosx10.15 -target-variant x86_64-apple-ios13.1-macabi -emit-object %s -o %t.o
63+
// RUN: %otool-classic -l %t.o | %FileCheck %s --check-prefix=CHECK-ZIPPERED
64+
65+
// With -target and -target variant reversed
66+
// RUN: %swiftc_driver -target x86_64-apple-ios13.1-macabi -target-variant x86_64-apple-macosx10.15 -emit-object %s -o %t.reversed.o
67+
// RUN: %otool-classic -l %t.reversed.o | %FileCheck %s --check-prefix=CHECK-ZIPPERED
68+
69+
// RUN: %swiftc_driver -target x86_64-apple-macosx10.15 -target-variant x86_64-apple-ios13.1-macabi -emit-library -module-name foo %s -o %t.dylib
70+
// RUN: %otool-classic -l %t.dylib | %FileCheck %s --check-prefix=CHECK-ZIPPERED
71+
72+
// RUN: %swiftc_driver -target x86_64-apple-ios13.1-macabi -target-variant x86_64-apple-macosx10.15 -emit-library -module-name foo %s -o %t.reversed.dylib
73+
// RUN: %otool-classic -l %t.reversed.dylib | %FileCheck %s --check-prefix=CHECK-ZIPPERED
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/// Tests the fallback behavior for runtime library import paths on macCatalyst. These
2+
/// should prefer the resource directory, then the SDK's System/iOSSupport
3+
/// directory, then the SDK's root. Contrariwise, test that iOSSupport is *not*
4+
/// used on any other platform.
5+
6+
// Test format: We try to type-check this file with different combinations of
7+
// mock resource directories and SDKs. If it loads a standard library,
8+
// typechecking will fail with a message that includes the word "success" (from
9+
// the name of the undefined function we try to call). If it tries to load a
10+
// standard library it shouldn't reach, loading will fail with a message that
11+
// includes the word "failure" (from the target triples we insert into the
12+
// bad .swiftmodule directories). If it can't even find a standard library to
13+
// attempt to load, the error message will contain neither "success" nor
14+
// "failure"; this should happen only in the last test case.
15+
16+
// REQUIRES: maccatalyst_support
17+
18+
// This symbol does not exist in the standard library.
19+
Swift.success()
20+
21+
// ***** SDKs AND RESOURCE DIRECTORIES *****
22+
23+
// bad-bad-sdk has bad stdlibs in both iOSSupport and the root.
24+
//
25+
// RUN: %empty-directory(%t/bad-bad-sdk)
26+
// RUN: mkdir -p %t/bad-bad-sdk/System/iOSSupport/usr/lib/swift/Swift.swiftmodule
27+
// RUN: touch %t/bad-bad-sdk/System/iOSSupport/usr/lib/swift/Swift.swiftmodule/failure-failure-failure.swiftmodule
28+
// RUN: mkdir -p %t/bad-bad-sdk/usr/lib/swift/Swift.swiftmodule
29+
// RUN: touch %t/bad-bad-sdk/usr/lib/swift/Swift.swiftmodule/failure-failure-failure.swiftmodule
30+
31+
// good-bad-sdk has a good stdlib in iOSSupport and a bad stdlib in the root.
32+
//
33+
// RUN: %empty-directory(%t/good-bad-sdk)
34+
// RUN: mkdir -p %t/good-bad-sdk/System/iOSSupport/usr/lib/swift
35+
// RUN: cp -r %test-resource-dir/maccatalyst/Swift.swiftmodule %t/good-bad-sdk/System/iOSSupport/usr/lib/swift/Swift.swiftmodule
36+
// RUN: mkdir -p %t/good-bad-sdk/usr/lib/swift/Swift.swiftmodule
37+
// RUN: touch %t/good-bad-sdk/usr/lib/swift/Swift.swiftmodule/failure-failure-failure.swiftmodule
38+
39+
// bad-good-sdk has a bad stdlib in iOSSupport and a good stdlib in the root.
40+
// Note that for the stdlib in this case to be "good", it needs to be universal.
41+
//
42+
// RUN: %empty-directory(%t/bad-good-sdk)
43+
// RUN: mkdir -p %t/bad-good-sdk/System/iOSSupport/usr/lib/swift/Swift.swiftmodule
44+
// RUN: touch %t/bad-good-sdk/System/iOSSupport/usr/lib/swift/Swift.swiftmodule/failure-failure-failure.swiftmodule
45+
// RUN: mkdir -p %t/bad-good-sdk/usr/lib/swift
46+
// RUN: cp -r %test-resource-dir/maccatalyst/Swift.swiftmodule %t/bad-good-sdk/usr/lib/swift/Swift.swiftmodule
47+
// RUN: cp -r %test-resource-dir/macosx/Swift.swiftmodule/* %t/bad-good-sdk/usr/lib/swift/Swift.swiftmodule
48+
49+
// empty-good-sdk has no stdlib in iOSSupport and a good stdlib in the root.
50+
// Note that for the stdlib in this case to be "good", it needs to be universal.
51+
//
52+
// RUN: %empty-directory(%t/empty-good-sdk)
53+
// RUN: mkdir -p %t/empty-good-sdk/System/iOSSupport/usr/lib/swift
54+
// RUN: mkdir -p %t/empty-good-sdk/usr/lib/swift
55+
// RUN: cp -r %test-resource-dir/maccatalyst/Swift.swiftmodule %t/empty-good-sdk/usr/lib/swift/Swift.swiftmodule
56+
// RUN: cp -r %test-resource-dir/macosx/Swift.swiftmodule/* %t/empty-good-sdk/usr/lib/swift/Swift.swiftmodule
57+
58+
// empty-empty-sdk has no stdlib in iOSSupport or the root.
59+
//
60+
// RUN: %empty-directory(%t/empty-empty-sdk)
61+
// RUN: mkdir -p %t/empty-empty-sdk/System/iOSSupport/usr/lib/swift
62+
// RUN: mkdir -p %t/empty-empty-sdk/usr/lib/swift
63+
64+
// We don't create a good-resourcedir; we just use the default one.
65+
66+
// empty-resdir has no stdlib in it.
67+
//
68+
// RUN: %empty-directory(%t/empty-resdir/usr/lib/swift)
69+
// FIXME: Until we have private imports, we need SwiftShims in the toolchain.
70+
// RUN: cp -r %test-resource-dir/shims %t/empty-resdir/usr/lib/swift/shims
71+
72+
73+
74+
// ***** MACCATALYST TESTS *****
75+
76+
// RESDIR: If resource-dir has a standard library, it will be preferred
77+
// over sdk/iOSSupport. (default resource dir + bad-bad-sdk)
78+
//
79+
// RUN: %empty-directory(%t.mcp)
80+
// RUN: not %target-swift-frontend(mock-sdk: -sdk %t/bad-bad-sdk) -target x86_64-apple-ios13.1-macabi -module-cache-path %t.mcp -typecheck %s 2>&1 | %FileCheck %s --check-prefix=RESDIR-MACCATALYST
81+
// RESDIR-MACCATALYST: success
82+
83+
// IOSSUP: If resource-dir has no standard library but sdk/iOSSupport does, it
84+
// will be preferred over sdk. (empty-resdir + good-bad-sdk)
85+
//
86+
// RUN: %empty-directory(%t.mcp)
87+
// RUN: not %target-swift-frontend(mock-sdk: -sdk %t/good-bad-sdk) -target x86_64-apple-ios13.1-macabi -resource-dir %t/empty-resdir/usr/lib/swift -module-cache-path %t.mcp -typecheck %s 2>&1 | %FileCheck %s --check-prefix=IOSSUP-MACCATALYST
88+
// IOSSUP-MACCATALYST: success
89+
90+
// IOSBAD: Confirms that we don't use sdk/iOSSupport on non-macCatalyst, even if
91+
// present. (empty-resdir + bad-good-sdk)
92+
//
93+
// RUN: %empty-directory(%t.mcp)
94+
// RUN: not %target-swift-frontend(mock-sdk: -sdk %t/bad-good-sdk) -target x86_64-apple-ios13.1-macabi -resource-dir %t/empty-resdir/usr/lib/swift -module-cache-path %t.mcp -typecheck %s 2>&1 | %FileCheck %s --check-prefix=IOSBAD-MACCATALYST
95+
// IOSBAD-MACCATALYST: failure
96+
97+
// SDKTOP: If resource-dir and sdk/iOSSupport don't have standard libraries but
98+
// sdk does, it will be used as a last resort. (empty-resdir + empty-good-sdk)
99+
//
100+
// RUN: %empty-directory(%t.mcp)
101+
// RUN: not %target-swift-frontend(mock-sdk: -sdk %t/empty-good-sdk) -target x86_64-apple-ios13.1-macabi -resource-dir %t/empty-resdir/usr/lib/swift -module-cache-path %t.mcp -typecheck %s 2>&1 | %FileCheck %s --check-prefix=SDKTOP-MACCATALYST
102+
// SDKTOP-MACCATALYST: success
103+
104+
// NILLIB: If no standard libraries are available, stdlib loading fails.
105+
// (empty-resdir + empty-empty-sdk) This one has a different error message from
106+
// the others because there are no failure-failure-failure triples to find.
107+
//
108+
// RUN: %empty-directory(%t.mcp)
109+
// RUN: not %target-swift-frontend(mock-sdk: -sdk %t/empty-empty-sdk) -target x86_64-apple-ios13.1-macabi -resource-dir %t/empty-resdir/usr/lib/swift -module-cache-path %t.mcp -typecheck %s 2>&1 | %FileCheck %s --check-prefix=NILLIB-MACCATALYST
110+
// NILLIB-MACCATALYST: unable to load standard library
111+
112+
113+
114+
// ***** MACOSX TESTS *****
115+
116+
// FIXME: Right now we're only building the ios-macabi swiftmodule when we
117+
// build for macCatalyst, so we need to accept "module 'Swfit' was created for
118+
// incompatible target" as successful.
119+
120+
// RESDIR: If resource-dir has a standard library, it will be preferred
121+
// over sdk/iOSSupport. (default resource dir + bad-bad-sdk)
122+
//
123+
// RUN: %empty-directory(%t.mcp)
124+
// RUN: not %target-swift-frontend(mock-sdk: -sdk %t/bad-bad-sdk) -target x86_64-apple-macosx10.15 -module-cache-path %t.mcp -typecheck %s 2>&1 | %FileCheck %s --check-prefix=RESDIR-MACOSX
125+
// RESDIR-MACOSX: {{success|module 'Swift' was created for incompatible target}}
126+
127+
// IOSSUP: If resource-dir has no standard library but sdk/iOSSupport does, it
128+
// will be preferred over sdk. (empty-resdir + good-bad-sdk)
129+
//
130+
// RUN: %empty-directory(%t.mcp)
131+
// RUN: not %target-swift-frontend(mock-sdk: -sdk %t/good-bad-sdk) -target x86_64-apple-macosx10.15 -resource-dir %t/empty-resdir/usr/lib/swift -module-cache-path %t.mcp -typecheck %s 2>&1 | %FileCheck %s --check-prefix=IOSSUP-MACOSX
132+
// IOSSUP-MACOSX: failure
133+
134+
// IOSBAD: Confirms that we don't use sdk/iOSSupport on non-macCatalyst, even if
135+
// present. (empty-resdir + bad-good-sdk)
136+
//
137+
// RUN: %empty-directory(%t.mcp)
138+
// RUN: not %target-swift-frontend(mock-sdk: -sdk %t/bad-good-sdk) -target x86_64-apple-macosx10.15 -resource-dir %t/empty-resdir/usr/lib/swift -module-cache-path %t.mcp -typecheck %s 2>&1 | %FileCheck %s --check-prefix=IOSBAD-MACOSX
139+
// IOSBAD-MACOSX: {{success|module 'Swift' was created for incompatible target}}
140+
141+
// SDKTOP: If resource-dir and sdk/iOSSupport don't have standard libraries but
142+
// sdk does, it will be used as a last resort. (empty-resdir + empty-good-sdk)
143+
//
144+
// RUN: %empty-directory(%t.mcp)
145+
// RUN: not %target-swift-frontend(mock-sdk: -sdk %t/empty-good-sdk) -target x86_64-apple-macosx10.15 -resource-dir %t/empty-resdir/usr/lib/swift -module-cache-path %t.mcp -typecheck %s 2>&1 | %FileCheck %s --check-prefix=SDKTOP-MACOSX
146+
// SDKTOP-MACOSX: {{success|module 'Swift' was created for incompatible target}}
147+
148+
// NILLIB: If no standard libraries are available, stdlib loading fails.
149+
// (empty-resdir + empty-empty-sdk) This one has a different error message from
150+
// the others because there are no failure-failure-failure triples to find.
151+
//
152+
// RUN: %empty-directory(%t.mcp)
153+
// RUN: not %target-swift-frontend(mock-sdk: -sdk %t/empty-empty-sdk) -target x86_64-apple-macosx10.15 -resource-dir %t/empty-resdir/usr/lib/swift -module-cache-path %t.mcp -typecheck %s 2>&1 | %FileCheck %s --check-prefix=NILLIB-MACOSX
154+
// NILLIB-MACOSX: unable to load standard library

0 commit comments

Comments
 (0)