Skip to content

Commit f25e730

Browse files
committed
Add @_objcImpl test case with multiple modules
1 parent 623582d commit f25e730

File tree

4 files changed

+55
-6
lines changed

4 files changed

+55
-6
lines changed

test/Interpreter/Inputs/objc_implementation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
@interface ImplClass : NSObject
44

5+
+ (void)runTests;
56
- (nonnull NSString *)someMethod;
67

78
@end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
framework module objc_implementation {
2+
header "objc_implementation.h"
3+
}
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1-
// RUN: %target-run-simple-swift(-import-objc-header %S/Inputs/objc_implementation.h) %s | %FileCheck %s
1+
// RUN: %target-run-simple-swift(-import-objc-header %S/Inputs/objc_implementation.h -D TOP_LEVEL_CODE -swift-version 5) %s | %FileCheck %s
22
// REQUIRES: executable_test
33
// REQUIRES: objc_interop
44

55
import Foundation
66

77
@_objcImplementation extension ImplClass {
8+
@objc class func runTests() {
9+
print(ImplClass().someMethod())
10+
print(SwiftSubclass().someMethod())
11+
}
12+
813
@objc func someMethod() -> String { "ImplClass.someMethod()" }
914
}
1015

11-
print(ImplClass().someMethod())
12-
// CHECK: ImplClass.someMethod()
13-
1416
class SwiftSubclass: ImplClass {
1517
override func someMethod() -> String { "SwiftSubclass.someMethod()" }
1618
}
1719

18-
print(SwiftSubclass().someMethod())
20+
// `#if swift` to ignore the inactive branch's contents
21+
#if swift(>=5.0) && TOP_LEVEL_CODE
22+
ImplClass.runTests()
23+
// CHECK: ImplClass.someMethod()
1924
// CHECK: SwiftSubclass.someMethod()
20-
25+
#endif
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// Build objc_implementation.framework
3+
//
4+
// RUN: %empty-directory(%t-frameworks/objc_implementation.framework/Modules/objc_implementation.swiftmodule)
5+
// RUN: %empty-directory(%t-frameworks/objc_implementation.framework/Headers)
6+
// RUN: cp %S/Inputs/objc_implementation.modulemap %t-frameworks/objc_implementation.framework/Modules/module.modulemap
7+
// RUN: cp %S/Inputs/objc_implementation.h %t-frameworks/objc_implementation.framework/Headers
8+
// RUN: %target-build-swift-dylib(%t-frameworks/objc_implementation.framework/objc_implementation) -emit-module-path %t-frameworks/objc_implementation.framework/Modules/objc_implementation.swiftmodule/%module-target-triple.swiftmodule -module-name objc_implementation -F %t-frameworks -import-underlying-module -Xlinker -install_name -Xlinker %t-frameworks/objc_implementation.framework/objc_implementation %S/objc_implementation.swift
9+
10+
//
11+
// Execute this file
12+
//
13+
// RUN: %target-run-simple-swift(-F %t-frameworks) %s | %FileCheck %s
14+
15+
//
16+
// Execute again, without the swiftmodule this time
17+
//
18+
// RUN: mv %t-frameworks/objc_implementation.framework/Modules/objc_implementation.swiftmodule %t-frameworks/objc_implementation.framework/Modules/objc_implementation.swiftmodule.disabled
19+
// RUN: %target-run-simple-swift(-F %t-frameworks) %s | %FileCheck %s
20+
21+
// REQUIRES: executable_test
22+
// REQUIRES: objc_interop
23+
24+
import Foundation
25+
import objc_implementation
26+
27+
ImplClass.runTests()
28+
// CHECK: ImplClass.someMethod()
29+
// CHECK: SwiftSubclass.someMethod()
30+
31+
print(ImplClass().someMethod())
32+
// CHECK: ImplClass.someMethod()
33+
34+
class SwiftClientSubclass: ImplClass {
35+
override func someMethod() -> String { "SwiftClientSubclass.someMethod()" }
36+
}
37+
38+
print(SwiftClientSubclass().someMethod())
39+
// CHECK: SwiftClientSubclass.someMethod()
40+

0 commit comments

Comments
 (0)