Skip to content

Commit 1eb4c01

Browse files
committed
Add @_objcImpl test case with multiple modules
1 parent 7e813fb commit 1eb4c01

File tree

4 files changed

+63
-6
lines changed

4 files changed

+63
-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: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// Build objc_implementation.framework
3+
//
4+
// RUN: %empty-directory(%t)
5+
// RUN: %empty-directory(%t/frameworks)
6+
// RUN: %empty-directory(%t/frameworks/objc_implementation.framework/Modules/objc_implementation.swiftmodule)
7+
// RUN: %empty-directory(%t/frameworks/objc_implementation.framework/Headers)
8+
// RUN: cp %S/Inputs/objc_implementation.modulemap %t/frameworks/objc_implementation.framework/Modules/module.modulemap
9+
// RUN: cp %S/Inputs/objc_implementation.h %t/frameworks/objc_implementation.framework/Headers
10+
// 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
11+
12+
//
13+
// Execute this file
14+
//
15+
// RUN: %empty-directory(%t/swiftmod)
16+
// RUN: %target-build-swift %s -module-cache-path %t/swiftmod/mcp -F %t/frameworks -o %t/swiftmod/a.out -module-name main
17+
// RUN: %target-codesign %t/swiftmod/a.out
18+
// RUN: %target-run %t/swiftmod/a.out | %FileCheck %s
19+
20+
//
21+
// Execute again, without the swiftmodule this time
22+
//
23+
// RUN: mv %t/frameworks/objc_implementation.framework/Modules/objc_implementation.swiftmodule %t/frameworks/objc_implementation.framework/Modules/objc_implementation.swiftmodule.disabled
24+
// RUN: %empty-directory(%t/clangmod)
25+
// RUN: %target-build-swift %s -module-cache-path %t/clangmod/mcp -F %t/frameworks -o %t/clangmod/a.out -module-name main
26+
// RUN: %target-codesign %t/clangmod/a.out
27+
// RUN: %target-run %t/clangmod/a.out | %FileCheck %s
28+
29+
// REQUIRES: executable_test
30+
// REQUIRES: objc_interop
31+
32+
import Foundation
33+
import objc_implementation
34+
35+
ImplClass.runTests()
36+
// CHECK: ImplClass.someMethod()
37+
// CHECK: SwiftSubclass.someMethod()
38+
39+
print(ImplClass().someMethod())
40+
// CHECK: ImplClass.someMethod()
41+
42+
class SwiftClientSubclass: ImplClass {
43+
override func someMethod() -> String { "SwiftClientSubclass.someMethod()" }
44+
}
45+
46+
print(SwiftClientSubclass().someMethod())
47+
// CHECK: SwiftClientSubclass.someMethod()
48+

0 commit comments

Comments
 (0)