|
| 1 | +// |
| 2 | +// Build objc_implementation.framework |
| 3 | +// |
| 4 | +// RUN: %empty-directory(%t-frameworks) |
| 5 | +// RUN: %empty-directory(%t-frameworks/objc_implementation.framework/Modules/objc_implementation.swiftmodule) |
| 6 | +// RUN: %empty-directory(%t-frameworks/objc_implementation.framework/Headers) |
| 7 | +// RUN: cp %S/Inputs/objc_implementation.modulemap %t-frameworks/objc_implementation.framework/Modules/module.modulemap |
| 8 | +// RUN: cp %S/Inputs/objc_implementation.h %t-frameworks/objc_implementation.framework/Headers |
| 9 | +// 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 |
| 10 | + |
| 11 | +// |
| 12 | +// Execute this file |
| 13 | +// |
| 14 | +// RUN: %empty-directory(%t) |
| 15 | +// RUN: %target-clang %s -isysroot %sdk -F %t-frameworks -lobjc -fmodules -fobjc-arc -o %t/objc_implementation_objc_client |
| 16 | +// RUN: %target-codesign %t/objc_implementation_objc_client |
| 17 | +// RUN: %target-run %t/objc_implementation_objc_client 2>&1 | %FileCheck %s |
| 18 | + |
| 19 | +// REQUIRES: executable_test |
| 20 | +// REQUIRES: objc_interop |
| 21 | + |
| 22 | +#import <Foundation/Foundation.h> |
| 23 | +#import <objc_implementation/objc_implementation.h> |
| 24 | +#import <stdlib.h> |
| 25 | + |
| 26 | +@interface ObjCClientSubclass : ImplClass |
| 27 | + |
| 28 | +- (NSString *)someMethod; |
| 29 | + |
| 30 | +@end |
| 31 | + |
| 32 | +static void print(NSString *str) { |
| 33 | + NSData *strData = [str dataUsingEncoding:NSUTF8StringEncoding]; |
| 34 | + NSData *nlData = [@"\n" dataUsingEncoding:NSUTF8StringEncoding]; |
| 35 | + |
| 36 | + NSFileHandle *out = NSFileHandle.fileHandleWithStandardOutput; |
| 37 | + |
| 38 | + if (@available(macOS 10.15, iOS 13.0, watchOS 6.0, *)) { |
| 39 | + NSError *error; |
| 40 | + if (![out writeData:strData error:&error] |
| 41 | + || ![out writeData:nlData error:&error]) { |
| 42 | + NSLog(@"I/O error writing to stdout: %@", error); |
| 43 | + exit(EXIT_FAILURE); |
| 44 | + } |
| 45 | + } |
| 46 | + else { |
| 47 | + [out writeData:strData]; |
| 48 | + [out writeData:nlData]; |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +int main() { |
| 53 | + [ImplClass runTests]; |
| 54 | + // CHECK: ImplClass.someMethod() |
| 55 | + // CHECK: SwiftSubclass.someMethod() |
| 56 | + |
| 57 | + fflush(stdout); |
| 58 | + |
| 59 | + print([[[ImplClass alloc] init] someMethod]); |
| 60 | + // CHECK: ImplClass.someMethod() |
| 61 | + |
| 62 | + print([[[ObjCClientSubclass alloc] init] someMethod]); |
| 63 | + // CHECK: -[ObjCClientSubclass someMethod] |
| 64 | + |
| 65 | + return 0; |
| 66 | +} |
| 67 | + |
| 68 | +@implementation ObjCClientSubclass |
| 69 | + |
| 70 | +- (NSString *)someMethod { |
| 71 | + return @"-[ObjCClientSubclass someMethod]"; |
| 72 | +} |
| 73 | + |
| 74 | +@end |
0 commit comments