Files
swift-mirror/validation-test/Runtime/class_stubs_weak.m
Slava Pestov 5d66bb810a Run stable ABI tests on all Apple platforms
A number of tests exercise features only available in Apple OSes that
shipped with Swift 5.0 in the OS; this includes the following versions:

- macOS 10.14.4
- iOS 12.2
- tvOS 12.2
- watchOS 5.2

Previously these tests were restricted to running on macOS only, with
an explicit -target x86_64-apple-macosx10.14.4. To get better test
coverage, add a new %target-stable-abi-triple substitution which
expands to a triple with the correct OS version on all Apple platforms.

On non-Apple platforms, this is the same as %target-variant-triple,
but for now any test that uses this exercises Apple platform features
anyway.

One caveat is that since iOS 12.2 does not have a 32-bit slice, we
have to skip any tests that use -target %target-stable-abi-triple
on this platform. A new swift_stable_abi feature flag can be tested
with 'REQUIRES: swift_stable_abi'. To get maximum test coverage,
I split off a 'stable_abi' version of a few tests that build with both
an old and new deployment target. This allows the old deployment
target case to still be tested on 32-bit iOS.
2019-05-16 17:02:06 -04:00

53 lines
2.0 KiB
Objective-C

// Check that Objective-C is able to use a resilient class stub emitted
// by the Swift compiler.
// RUN: %empty-directory(%t)
// RUN: %target-build-swift -emit-library -emit-module -o %t/libfirst.dylib -emit-objc-header-path %t/first.h %S/Inputs/class-stubs-weak/first.swift -Xlinker -install_name -Xlinker @executable_path/libfirst.dylib -enable-library-evolution
// RUN: %target-build-swift -emit-library -o %t/libsecond.dylib -emit-objc-header-path %t/second.h -I %t %S/Inputs/class-stubs-weak/second.swift -Xlinker -install_name -Xlinker @executable_path/libsecond.dylib -lfirst -L %t -Xfrontend -enable-resilient-objc-class-stubs -DBEFORE
// RUN: cp %S/Inputs/class-stubs-weak/module.map %t/
// Note: This is the just-built Clang, not the system Clang.
// RUN: xcrun -sdk %sdk %clang %s -I %t -L %t -fmodules -fobjc-arc -o %t/main -lfirst -lsecond -Wl,-U,_objc_loadClassref -target %target-triple
// Now rebuild the library, omitting the weak-exported class
// RUN: %target-build-swift -emit-library -o %t/libsecond.dylib -I %t %S/Inputs/class-stubs-weak/second.swift -Xlinker -install_name -Xlinker @executable_path/libsecond.dylib -lfirst -L %t -Xfrontend -enable-resilient-objc-class-stubs
// RUN: %target-codesign %t/main %t/libfirst.dylib %t/libsecond.dylib
// RUN: %target-run %t/main %t/libfirst.dylib %t/libsecond.dylib
// REQUIRES: executable_test
// REQUIRES: objc_interop
#import <dlfcn.h>
#import <stdio.h>
#import "second.h"
@implementation DerivedClass (MyCategory)
- (int)instanceMethod {
return [super instanceMethod] + 1;
}
+ (int)classMethod {
return [super classMethod] + 1;
}
@end
int main(int argc, const char * const argv[]) {
// Only test the new behavior on a new enough libobjc.
if (!dlsym(RTLD_NEXT, "_objc_loadClassref")) {
fprintf(stderr, "skipping evolution tests; OS too old\n");
return EXIT_SUCCESS;
}
Class cls = [DerivedClass class];
if (cls) {
printf("Class is not null");
return EXIT_FAILURE;
}
printf("Class is null");
return EXIT_SUCCESS;
}